1+ import 'package:flutter/foundation.dart' ;
12import 'package:flutter/widgets.dart' ;
23
34import 'package:photo_view/src/controller/photo_view_controller_delegate.dart'
45 show PhotoViewControllerDelegate;
56
67mixin 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
7272class HitCorners {
0 commit comments