Skip to content

Commit 043b73a

Browse files
committed
* Fix issue that unsmooth zooming when using ExtendedImageGesturePageView (#631)
* Add [ExtendedImageGesturePageView.shouldAccpetHorizontalOrVerticalDrag] to custum whether should accpet horizontal or vertical drag at that time.
1 parent be9e83a commit 043b73a

File tree

7 files changed

+65
-16
lines changed

7 files changed

+65
-16
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 8.0.3
2+
3+
* Fix issue that unsmooth zooming when using ExtendedImageGesturePageView (#631)
4+
* Add [ExtendedImageGesturePageView.shouldAccpetHorizontalOrVerticalDrag] to custum whether should accpet horizontal or vertical drag at that time.
5+
16
## 8.0.2
27

38
* [EditorCropLayerPainter.paintMask] not use BlendMode.clear now, due to '--web-renderer html' is not support.

example/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ build/
7070
!**/ios/**/default.pbxuser
7171
!**/ios/**/default.perspectivev3
7272
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
73+
assets.preview.dart

example/lib/pages/simple/photo_view_demo.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:extended_image/extended_image.dart';
22
import 'package:ff_annotation_route_core/ff_annotation_route_core.dart';
3+
import 'package:flutter/gestures.dart';
34
import 'package:flutter/material.dart';
45

56
@FFRoute(
@@ -57,6 +58,27 @@ class _SimplePhotoViewDemoState extends State<SimplePhotoViewDemo> {
5758
},
5859
);
5960
},
61+
// just demo, it the same as default.
62+
// if you need to custom it, you can define it base on your case.
63+
shouldAccpetHorizontalOrVerticalDrag:
64+
(Map<int, VelocityTracker> velocityTrackers) {
65+
if (velocityTrackers.keys.length == 1) {
66+
return true;
67+
}
68+
69+
// if pointers are not the only, check whether they are in the negative
70+
// maybe this is a Horizontal/Vertical zoom
71+
Offset offset = const Offset(1, 1);
72+
for (final VelocityTracker tracker in velocityTrackers.values) {
73+
if (tracker is ExtendedVelocityTracker) {
74+
final Offset delta = tracker.getSamplesDelta();
75+
offset = Offset(offset.dx * (delta.dx == 0 ? 1 : delta.dx),
76+
offset.dy * (delta.dy == 0 ? 1 : delta.dy));
77+
}
78+
}
79+
80+
return !(offset.dx < 0 || offset.dy < 0);
81+
},
6082
),
6183
);
6284
}

lib/extended_image.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export 'src/gesture/page_view/gesture_page_view.dart';
1212
export 'src/gesture/slide_page.dart';
1313
export 'src/gesture/slide_page_handler.dart';
1414
export 'src/gesture/utils.dart';
15+
export 'src/gesture_detector/official.dart';
1516
export 'src/image/painting.dart';
1617
export 'src/image/raw_image.dart';
1718
export 'src/image/render_image.dart';

lib/src/gesture/page_view/gesture_page_view.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class ExtendedImageGesturePageView extends StatefulWidget {
4848
List<Widget> children = const <Widget>[],
4949
CanScrollPage? canScrollPage,
5050
this.preloadPagesCount = 0,
51+
this.shouldAccpetHorizontalOrVerticalDrag,
5152
}) : controller = controller ?? _defaultPageController,
5253
childrenDelegate = SliverChildListDelegate(children),
5354
physics = physics != null
@@ -80,6 +81,7 @@ class ExtendedImageGesturePageView extends StatefulWidget {
8081
int? itemCount,
8182
CanScrollPage? canScrollPage,
8283
this.preloadPagesCount = 0,
84+
this.shouldAccpetHorizontalOrVerticalDrag,
8385
}) : controller = controller ?? _defaultPageController,
8486
childrenDelegate =
8587
SliverChildBuilderDelegate(itemBuilder, childCount: itemCount),
@@ -102,6 +104,7 @@ class ExtendedImageGesturePageView extends StatefulWidget {
102104
CanScrollPage? canScrollPage,
103105
required this.childrenDelegate,
104106
this.preloadPagesCount = 0,
107+
this.shouldAccpetHorizontalOrVerticalDrag,
105108
}) : controller = controller ?? _defaultPageController,
106109
physics = _defaultScrollPhysics,
107110
canScrollPage = canScrollPage ?? _defaultCanScrollPage,
@@ -161,6 +164,11 @@ class ExtendedImageGesturePageView extends StatefulWidget {
161164
/// The count of pre-built pages
162165
final int preloadPagesCount;
163166

167+
/// Whether should accpet horizontal or vertical drag at that time
168+
/// You can custom it by your base
169+
final ShouldAccpetHorizontalOrVerticalDrag?
170+
shouldAccpetHorizontalOrVerticalDrag;
171+
164172
@override
165173
ExtendedImageGesturePageViewState createState() =>
166174
ExtendedImageGesturePageViewState();
@@ -230,6 +238,8 @@ class ExtendedImageGesturePageViewState
230238
() => ExtendedVerticalDragGestureRecognizer(
231239
canHorizontalOrVerticalDrag: canHorizontalOrVerticalDrag,
232240
debugOwner: this,
241+
shouldAccpetHorizontalOrVerticalDrag:
242+
widget.shouldAccpetHorizontalOrVerticalDrag,
233243
),
234244
(ExtendedVerticalDragGestureRecognizer instance) {
235245
instance
@@ -254,6 +264,8 @@ class ExtendedImageGesturePageViewState
254264
() => ExtendedHorizontalDragGestureRecognizer(
255265
canHorizontalOrVerticalDrag: canHorizontalOrVerticalDrag,
256266
debugOwner: this,
267+
shouldAccpetHorizontalOrVerticalDrag:
268+
widget.shouldAccpetHorizontalOrVerticalDrag,
257269
),
258270
(ExtendedHorizontalDragGestureRecognizer instance) {
259271
instance

lib/src/gesture_detector/drag_gesture_recognizer.dart

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ part of 'official.dart';
22

33
typedef CanHorizontalOrVerticalDrag = bool Function();
44

5+
typedef ShouldAccpetHorizontalOrVerticalDrag = bool Function(
6+
Map<int, VelocityTracker> velocityTrackers,
7+
);
8+
59
mixin DragGestureRecognizerMixin on _DragGestureRecognizer {
610
bool get canDrag =>
711
canHorizontalOrVerticalDrag == null || canHorizontalOrVerticalDrag!();
@@ -10,6 +14,10 @@ mixin DragGestureRecognizerMixin on _DragGestureRecognizer {
1014
if (!canDrag) {
1115
return false;
1216
}
17+
if (shouldAccpetHorizontalOrVerticalDrag != null) {
18+
return shouldAccpetHorizontalOrVerticalDrag!(_velocityTrackers);
19+
}
20+
1321
if (_velocityTrackers.keys.length == 1) {
1422
return true;
1523
}
@@ -29,6 +37,8 @@ mixin DragGestureRecognizerMixin on _DragGestureRecognizer {
2937
}
3038

3139
CanHorizontalOrVerticalDrag? get canHorizontalOrVerticalDrag;
40+
ShouldAccpetHorizontalOrVerticalDrag?
41+
get shouldAccpetHorizontalOrVerticalDrag;
3242

3343
@override
3444
void handleEvent(PointerEvent event) {
@@ -101,36 +111,30 @@ mixin DragGestureRecognizerMixin on _DragGestureRecognizer {
101111
_giveUpPointer(event.pointer);
102112
}
103113
}
104-
}
105114

106-
abstract class ExtendedDragGestureRecognizer extends _DragGestureRecognizer
107-
with DragGestureRecognizerMixin {
108-
ExtendedDragGestureRecognizer({
109-
super.debugOwner,
110-
super.dragStartBehavior = DragStartBehavior.start,
111-
super.velocityTrackerBuilder = _defaultBuilder,
112-
super.supportedDevices,
113-
super.allowedButtonsFilter,
114-
this.canHorizontalOrVerticalDrag,
115-
});
116-
117-
static ExtendedVelocityTracker _defaultBuilder(PointerEvent event) =>
118-
ExtendedVelocityTracker.withKind(event.kind);
119115
@override
120-
final CanHorizontalOrVerticalDrag? canHorizontalOrVerticalDrag;
116+
GestureVelocityTrackerBuilder get velocityTrackerBuilder => _defaultBuilder;
121117
}
122118

119+
ExtendedVelocityTracker _defaultBuilder(PointerEvent event) =>
120+
ExtendedVelocityTracker.withKind(event.kind);
121+
123122
class ExtendedHorizontalDragGestureRecognizer
124123
extends _HorizontalDragGestureRecognizer with DragGestureRecognizerMixin {
125124
ExtendedHorizontalDragGestureRecognizer({
126125
super.debugOwner,
127126
super.supportedDevices,
128127
super.allowedButtonsFilter,
129128
this.canHorizontalOrVerticalDrag,
129+
this.shouldAccpetHorizontalOrVerticalDrag,
130130
});
131131

132132
@override
133133
final CanHorizontalOrVerticalDrag? canHorizontalOrVerticalDrag;
134+
135+
@override
136+
final ShouldAccpetHorizontalOrVerticalDrag?
137+
shouldAccpetHorizontalOrVerticalDrag;
134138
}
135139

136140
class ExtendedVerticalDragGestureRecognizer
@@ -140,8 +144,12 @@ class ExtendedVerticalDragGestureRecognizer
140144
super.supportedDevices,
141145
super.allowedButtonsFilter,
142146
this.canHorizontalOrVerticalDrag,
147+
this.shouldAccpetHorizontalOrVerticalDrag,
143148
});
144149

145150
@override
146151
final CanHorizontalOrVerticalDrag? canHorizontalOrVerticalDrag;
152+
@override
153+
final ShouldAccpetHorizontalOrVerticalDrag?
154+
shouldAccpetHorizontalOrVerticalDrag;
147155
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: extended_image
22
description: Official extension image, support placeholder(loading)/ failed state, cache network, zoom/pan, photo view, slide out page, editor(crop,rotate,flip), painting etc.
3-
version: 8.0.2
3+
version: 8.0.3
44
homepage: https://github.com/fluttercandies/extended_image
55

66
environment:

0 commit comments

Comments
 (0)