Skip to content

Commit 74e5a87

Browse files
authored
fix-double-order (#326)
1 parent 4816982 commit 74e5a87

File tree

3 files changed

+47
-49
lines changed

3 files changed

+47
-49
lines changed

example/lib/screens/examples/gallery/gallery_example.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,14 @@ class _GalleryPhotoViewWrapperState extends State<GalleryPhotoViewWrapper> {
176176
childSize: const Size(300, 300),
177177
initialScale: PhotoViewComputedScale.contained,
178178
minScale: PhotoViewComputedScale.contained * (0.5 + index / 10),
179-
maxScale: PhotoViewComputedScale.covered * 1.1,
179+
maxScale: PhotoViewComputedScale.covered * 4.1,
180180
heroAttributes: PhotoViewHeroAttributes(tag: item.id),
181181
)
182182
: PhotoViewGalleryPageOptions(
183183
imageProvider: AssetImage(item.resource),
184184
initialScale: PhotoViewComputedScale.contained,
185185
minScale: PhotoViewComputedScale.contained * (0.5 + index / 10),
186-
maxScale: PhotoViewComputedScale.covered * 1.1,
186+
maxScale: PhotoViewComputedScale.covered * 4.1,
187187
heroAttributes: PhotoViewHeroAttributes(tag: item.id),
188188
);
189189
}

lib/src/core/photo_view_gesture_detector.dart

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ class PhotoViewGestureDetector extends StatelessWidget {
5252
);
5353
}
5454

55+
gestures[DoubleTapGestureRecognizer] =
56+
GestureRecognizerFactoryWithHandlers<DoubleTapGestureRecognizer>(
57+
() => DoubleTapGestureRecognizer(debugOwner: this),
58+
(DoubleTapGestureRecognizer instance) {
59+
instance..onDoubleTap = onDoubleTap;
60+
},
61+
);
62+
5563
gestures[PhotoViewGestureRecognizer] =
5664
GestureRecognizerFactoryWithHandlers<PhotoViewGestureRecognizer>(
5765
() => PhotoViewGestureRecognizer(
@@ -64,16 +72,8 @@ class PhotoViewGestureDetector extends StatelessWidget {
6472
},
6573
);
6674

67-
gestures[DoubleTapGestureRecognizer] =
68-
GestureRecognizerFactoryWithHandlers<DoubleTapGestureRecognizer>(
69-
() => DoubleTapGestureRecognizer(debugOwner: this),
70-
(DoubleTapGestureRecognizer instance) {
71-
instance..onDoubleTap = onDoubleTap;
72-
},
73-
);
74-
7575
return RawGestureDetector(
76-
behavior: behavior ?? HitTestBehavior.translucent,
76+
behavior: behavior,
7777
child: child,
7878
gestures: gestures,
7979
);
@@ -150,9 +150,7 @@ class PhotoViewGestureRecognizer extends ScaleGestureRecognizer {
150150
return;
151151
}
152152
final move = _initialFocalPoint - _currentFocalPoint;
153-
final bool shouldMove = validateAxis == Axis.vertical
154-
? hitDetector.shouldMoveY(move)
155-
: hitDetector.shouldMoveX(move);
153+
final bool shouldMove = hitDetector.shouldMove(move, validateAxis);
156154
if (shouldMove || _pointerLocations.keys.length > 1) {
157155
acceptGesture(event.pointer);
158156
}

lib/src/core/photo_view_hit_corners.dart

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
import 'package:flutter/foundation.dart';
12
import 'package:flutter/widgets.dart';
23

34
import 'package:photo_view/src/controller/photo_view_controller_delegate.dart'
45
show PhotoViewControllerDelegate;
56

67
mixin HitCornersDetector on PhotoViewControllerDelegate {
7-
HitAxis hitAxis() => HitAxis(hitCornersX(), hitCornersY());
8-
9-
HitCorners hitCornersX() {
8+
HitCorners _hitCornersX() {
109
final double childWidth = scaleBoundaries.childSize.width * scale;
1110
final double screenWidth = scaleBoundaries.outerSize.width;
1211
if (screenWidth >= childWidth) {
@@ -17,7 +16,7 @@ mixin HitCornersDetector on PhotoViewControllerDelegate {
1716
return HitCorners(x <= cornersX.min, x >= cornersX.max);
1817
}
1918

20-
HitCorners hitCornersY() {
19+
HitCorners _hitCornersY() {
2120
final double childHeight = scaleBoundaries.childSize.height * scale;
2221
final double screenHeight = scaleBoundaries.outerSize.height;
2322
if (screenHeight >= childHeight) {
@@ -28,45 +27,46 @@ mixin HitCornersDetector on PhotoViewControllerDelegate {
2827
return HitCorners(y <= cornersY.min, y >= cornersY.max);
2928
}
3029

31-
bool shouldMoveX(Offset move) {
32-
final hitCornersX = this.hitCornersX();
33-
34-
if (hitCornersX.hasHitAny && move != Offset.zero) {
35-
if (hitCornersX.hasHitBoth) {
36-
return false;
37-
}
38-
if (hitCornersX.hasHitMax) {
39-
return move.dx < 0;
40-
}
41-
return move.dx > 0;
30+
bool _shouldMoveAxis(
31+
HitCorners hitCorners, double mainAxisMove, double crossAxisMove) {
32+
if (mainAxisMove == 0) {
33+
return false;
4234
}
43-
return true;
44-
}
45-
46-
bool shouldMoveY(Offset move) {
47-
final hitCornersY = this.hitCornersY();
48-
if (hitCornersY.hasHitAny && move != Offset.zero) {
49-
if (hitCornersY.hasHitBoth) {
50-
return false;
51-
}
52-
if (hitCornersY.hasHitMax) {
53-
return move.dy < 0;
54-
}
55-
return move.dy > 0;
35+
if (!hitCorners.hasHitAny) {
36+
return true;
37+
}
38+
final axisBlocked = hitCorners.hasHitBoth ||
39+
(hitCorners.hasHitMax ? mainAxisMove > 0 : mainAxisMove < 0);
40+
if (axisBlocked) {
41+
return false;
5642
}
5743
return true;
5844
}
59-
}
6045

61-
class HitAxis {
62-
HitAxis(this.hasHitX, this.hasHitY);
46+
bool _shouldMoveX(Offset move) {
47+
final hitCornersX = _hitCornersX();
48+
final mainAxisMove = move.dx;
49+
final crossAxisMove = move.dy;
50+
51+
return _shouldMoveAxis(hitCornersX, mainAxisMove, crossAxisMove);
52+
}
6353

64-
final HitCorners hasHitX;
65-
final HitCorners hasHitY;
54+
bool _shouldMoveY(Offset move) {
55+
final hitCornersY = _hitCornersY();
56+
final mainAxisMove = move.dy;
57+
final crossAxisMove = move.dx;
6658

67-
bool get hasHitAny => hasHitX.hasHitAny || hasHitY.hasHitAny;
59+
return _shouldMoveAxis(hitCornersY, mainAxisMove, crossAxisMove);
60+
}
6861

69-
bool get hasHitBoth => hasHitX.hasHitBoth && hasHitY.hasHitBoth;
62+
bool shouldMove(Offset move, Axis mainAxis) {
63+
assert(mainAxis != null);
64+
assert(move != null);
65+
if (mainAxis == Axis.vertical) {
66+
return _shouldMoveY(move);
67+
}
68+
return _shouldMoveX(move);
69+
}
7070
}
7171

7272
class HitCorners {

0 commit comments

Comments
 (0)