diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e77c77b..1ac58d90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 8.0.3 + +* Fix issue that unsmooth zooming when using ExtendedImageGesturePageView (#631) +* Add [ExtendedImageGesturePageView.shouldAccpetHorizontalOrVerticalDrag] to custum whether should accpet horizontal or vertical drag at that time. + ## 8.0.2 * [EditorCropLayerPainter.paintMask] not use BlendMode.clear now, due to '--web-renderer html' is not support. diff --git a/example/.gitignore b/example/.gitignore index 83ebb9e9..1d107637 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -70,3 +70,4 @@ build/ !**/ios/**/default.pbxuser !**/ios/**/default.perspectivev3 !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages +assets.preview.dart \ No newline at end of file diff --git a/example/lib/pages/simple/photo_view_demo.dart b/example/lib/pages/simple/photo_view_demo.dart index f85a0844..230aeaf9 100644 --- a/example/lib/pages/simple/photo_view_demo.dart +++ b/example/lib/pages/simple/photo_view_demo.dart @@ -1,5 +1,6 @@ import 'package:extended_image/extended_image.dart'; import 'package:ff_annotation_route_core/ff_annotation_route_core.dart'; +import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; @FFRoute( @@ -57,6 +58,27 @@ class _SimplePhotoViewDemoState extends State { }, ); }, + // just demo, it the same as default. + // if you need to custom it, you can define it base on your case. + shouldAccpetHorizontalOrVerticalDrag: + (Map velocityTrackers) { + if (velocityTrackers.keys.length == 1) { + return true; + } + + // if pointers are not the only, check whether they are in the negative + // maybe this is a Horizontal/Vertical zoom + Offset offset = const Offset(1, 1); + for (final VelocityTracker tracker in velocityTrackers.values) { + if (tracker is ExtendedVelocityTracker) { + final Offset delta = tracker.getSamplesDelta(); + offset = Offset(offset.dx * (delta.dx == 0 ? 1 : delta.dx), + offset.dy * (delta.dy == 0 ? 1 : delta.dy)); + } + } + + return !(offset.dx < 0 || offset.dy < 0); + }, ), ); } diff --git a/lib/extended_image.dart b/lib/extended_image.dart index bf4846e3..95dddd74 100644 --- a/lib/extended_image.dart +++ b/lib/extended_image.dart @@ -12,6 +12,7 @@ export 'src/gesture/page_view/gesture_page_view.dart'; export 'src/gesture/slide_page.dart'; export 'src/gesture/slide_page_handler.dart'; export 'src/gesture/utils.dart'; +export 'src/gesture_detector/official.dart'; export 'src/image/painting.dart'; export 'src/image/raw_image.dart'; export 'src/image/render_image.dart'; diff --git a/lib/src/gesture/page_view/gesture_page_view.dart b/lib/src/gesture/page_view/gesture_page_view.dart index 654a4de3..eb943865 100644 --- a/lib/src/gesture/page_view/gesture_page_view.dart +++ b/lib/src/gesture/page_view/gesture_page_view.dart @@ -48,6 +48,7 @@ class ExtendedImageGesturePageView extends StatefulWidget { List children = const [], CanScrollPage? canScrollPage, this.preloadPagesCount = 0, + this.shouldAccpetHorizontalOrVerticalDrag, }) : controller = controller ?? _defaultPageController, childrenDelegate = SliverChildListDelegate(children), physics = physics != null @@ -80,6 +81,7 @@ class ExtendedImageGesturePageView extends StatefulWidget { int? itemCount, CanScrollPage? canScrollPage, this.preloadPagesCount = 0, + this.shouldAccpetHorizontalOrVerticalDrag, }) : controller = controller ?? _defaultPageController, childrenDelegate = SliverChildBuilderDelegate(itemBuilder, childCount: itemCount), @@ -102,6 +104,7 @@ class ExtendedImageGesturePageView extends StatefulWidget { CanScrollPage? canScrollPage, required this.childrenDelegate, this.preloadPagesCount = 0, + this.shouldAccpetHorizontalOrVerticalDrag, }) : controller = controller ?? _defaultPageController, physics = _defaultScrollPhysics, canScrollPage = canScrollPage ?? _defaultCanScrollPage, @@ -161,6 +164,11 @@ class ExtendedImageGesturePageView extends StatefulWidget { /// The count of pre-built pages final int preloadPagesCount; + /// Whether should accpet horizontal or vertical drag at that time + /// You can custom it by your base + final ShouldAccpetHorizontalOrVerticalDrag? + shouldAccpetHorizontalOrVerticalDrag; + @override ExtendedImageGesturePageViewState createState() => ExtendedImageGesturePageViewState(); @@ -230,6 +238,8 @@ class ExtendedImageGesturePageViewState () => ExtendedVerticalDragGestureRecognizer( canHorizontalOrVerticalDrag: canHorizontalOrVerticalDrag, debugOwner: this, + shouldAccpetHorizontalOrVerticalDrag: + widget.shouldAccpetHorizontalOrVerticalDrag, ), (ExtendedVerticalDragGestureRecognizer instance) { instance @@ -254,6 +264,8 @@ class ExtendedImageGesturePageViewState () => ExtendedHorizontalDragGestureRecognizer( canHorizontalOrVerticalDrag: canHorizontalOrVerticalDrag, debugOwner: this, + shouldAccpetHorizontalOrVerticalDrag: + widget.shouldAccpetHorizontalOrVerticalDrag, ), (ExtendedHorizontalDragGestureRecognizer instance) { instance diff --git a/lib/src/gesture_detector/drag_gesture_recognizer.dart b/lib/src/gesture_detector/drag_gesture_recognizer.dart index a7ba8796..e626b6e9 100644 --- a/lib/src/gesture_detector/drag_gesture_recognizer.dart +++ b/lib/src/gesture_detector/drag_gesture_recognizer.dart @@ -2,6 +2,10 @@ part of 'official.dart'; typedef CanHorizontalOrVerticalDrag = bool Function(); +typedef ShouldAccpetHorizontalOrVerticalDrag = bool Function( + Map velocityTrackers, +); + mixin DragGestureRecognizerMixin on _DragGestureRecognizer { bool get canDrag => canHorizontalOrVerticalDrag == null || canHorizontalOrVerticalDrag!(); @@ -10,6 +14,10 @@ mixin DragGestureRecognizerMixin on _DragGestureRecognizer { if (!canDrag) { return false; } + if (shouldAccpetHorizontalOrVerticalDrag != null) { + return shouldAccpetHorizontalOrVerticalDrag!(_velocityTrackers); + } + if (_velocityTrackers.keys.length == 1) { return true; } @@ -29,6 +37,8 @@ mixin DragGestureRecognizerMixin on _DragGestureRecognizer { } CanHorizontalOrVerticalDrag? get canHorizontalOrVerticalDrag; + ShouldAccpetHorizontalOrVerticalDrag? + get shouldAccpetHorizontalOrVerticalDrag; @override void handleEvent(PointerEvent event) { @@ -101,25 +111,14 @@ mixin DragGestureRecognizerMixin on _DragGestureRecognizer { _giveUpPointer(event.pointer); } } -} -abstract class ExtendedDragGestureRecognizer extends _DragGestureRecognizer - with DragGestureRecognizerMixin { - ExtendedDragGestureRecognizer({ - super.debugOwner, - super.dragStartBehavior = DragStartBehavior.start, - super.velocityTrackerBuilder = _defaultBuilder, - super.supportedDevices, - super.allowedButtonsFilter, - this.canHorizontalOrVerticalDrag, - }); - - static ExtendedVelocityTracker _defaultBuilder(PointerEvent event) => - ExtendedVelocityTracker.withKind(event.kind); @override - final CanHorizontalOrVerticalDrag? canHorizontalOrVerticalDrag; + GestureVelocityTrackerBuilder get velocityTrackerBuilder => _defaultBuilder; } +ExtendedVelocityTracker _defaultBuilder(PointerEvent event) => + ExtendedVelocityTracker.withKind(event.kind); + class ExtendedHorizontalDragGestureRecognizer extends _HorizontalDragGestureRecognizer with DragGestureRecognizerMixin { ExtendedHorizontalDragGestureRecognizer({ @@ -127,10 +126,15 @@ class ExtendedHorizontalDragGestureRecognizer super.supportedDevices, super.allowedButtonsFilter, this.canHorizontalOrVerticalDrag, + this.shouldAccpetHorizontalOrVerticalDrag, }); @override final CanHorizontalOrVerticalDrag? canHorizontalOrVerticalDrag; + + @override + final ShouldAccpetHorizontalOrVerticalDrag? + shouldAccpetHorizontalOrVerticalDrag; } class ExtendedVerticalDragGestureRecognizer @@ -140,8 +144,12 @@ class ExtendedVerticalDragGestureRecognizer super.supportedDevices, super.allowedButtonsFilter, this.canHorizontalOrVerticalDrag, + this.shouldAccpetHorizontalOrVerticalDrag, }); @override final CanHorizontalOrVerticalDrag? canHorizontalOrVerticalDrag; + @override + final ShouldAccpetHorizontalOrVerticalDrag? + shouldAccpetHorizontalOrVerticalDrag; } diff --git a/pubspec.yaml b/pubspec.yaml index 88003784..0f9c93df 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: extended_image description: Official extension image, support placeholder(loading)/ failed state, cache network, zoom/pan, photo view, slide out page, editor(crop,rotate,flip), painting etc. -version: 8.0.2 +version: 8.0.3 homepage: https://github.com/fluttercandies/extended_image environment: