Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with gallery in Android for flutter version 1.20 and up #304 #349

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.2"
version: "2.5.0-nullsafety.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0-nullsafety.1"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "1.1.0-nullsafety.3"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
version: "1.2.0-nullsafety.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
version: "1.1.0-nullsafety.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.13"
version: "1.15.0-nullsafety.3"
convert:
dependency: transitive
description:
Expand All @@ -56,7 +56,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0-nullsafety.1"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -80,21 +80,21 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.8"
version: "0.12.10-nullsafety.1"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
version: "1.3.0-nullsafety.3"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0-nullsafety.1"
path_drawing:
dependency: transitive
description:
Expand Down Expand Up @@ -134,56 +134,56 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0-nullsafety.2"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.5"
version: "1.10.0-nullsafety.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0-nullsafety.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "1.1.0-nullsafety.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0-nullsafety.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.17"
version: "0.2.19-nullsafety.2"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0-nullsafety.3"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
version: "2.1.0-nullsafety.3"
xml:
dependency: transitive
description:
Expand All @@ -192,5 +192,5 @@ packages:
source: hosted
version: "4.2.0"
sdks:
dart: ">=2.9.0-14.0.dev <3.0.0"
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.18.0-6.0.pre <2.0.0"
23 changes: 13 additions & 10 deletions lib/src/core/photo_view_gesture_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ class PhotoViewGestureDetector extends StatelessWidget {
);
}

gestures[DoubleTapGestureRecognizer] =
GestureRecognizerFactoryWithHandlers<DoubleTapGestureRecognizer>(
() => DoubleTapGestureRecognizer(debugOwner: this),
(DoubleTapGestureRecognizer instance) {
instance..onDoubleTap = onDoubleTap;
},
);

gestures[PhotoViewGestureRecognizer] =
GestureRecognizerFactoryWithHandlers<PhotoViewGestureRecognizer>(
() => PhotoViewGestureRecognizer(
Expand All @@ -72,8 +64,16 @@ class PhotoViewGestureDetector extends StatelessWidget {
},
);

gestures[DoubleTapGestureRecognizer] =
GestureRecognizerFactoryWithHandlers<DoubleTapGestureRecognizer>(
() => DoubleTapGestureRecognizer(debugOwner: this),
(DoubleTapGestureRecognizer instance) {
instance..onDoubleTap = onDoubleTap;
},
);

return RawGestureDetector(
behavior: behavior,
behavior: behavior ?? HitTestBehavior.translucent,
child: child,
gestures: gestures,
);
Expand Down Expand Up @@ -150,7 +150,10 @@ class PhotoViewGestureRecognizer extends ScaleGestureRecognizer {
return;
}
final move = _initialFocalPoint - _currentFocalPoint;
final bool shouldMove = hitDetector.shouldMove(move, validateAxis);
if (move == Offset.zero) return;
final bool shouldMove = validateAxis == Axis.vertical
? hitDetector.shouldMoveY(move)
: hitDetector.shouldMoveX(move);
if (shouldMove || _pointerLocations.keys.length > 1) {
acceptGesture(event.pointer);
}
Expand Down
70 changes: 35 additions & 35 deletions lib/src/core/photo_view_hit_corners.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

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

mixin HitCornersDetector on PhotoViewControllerDelegate {
HitCorners _hitCornersX() {
HitAxis hitAxis() => HitAxis(hitCornersX(), hitCornersY());

HitCorners hitCornersX() {
final double childWidth = scaleBoundaries.childSize.width * scale;
final double screenWidth = scaleBoundaries.outerSize.width;
if (screenWidth >= childWidth) {
Expand All @@ -16,7 +17,7 @@ mixin HitCornersDetector on PhotoViewControllerDelegate {
return HitCorners(x <= cornersX.min, x >= cornersX.max);
}

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

bool _shouldMoveAxis(
HitCorners hitCorners, double mainAxisMove, double crossAxisMove) {
if (mainAxisMove == 0) {
return false;
}
if (!hitCorners.hasHitAny) {
return true;
}
final axisBlocked = hitCorners.hasHitBoth ||
(hitCorners.hasHitMax ? mainAxisMove > 0 : mainAxisMove < 0);
if (axisBlocked) {
return false;
bool shouldMoveX(Offset move) {
final hitCornersX = this.hitCornersX();

if (hitCornersX.hasHitAny && move != Offset.zero) {
if (hitCornersX.hasHitBoth) {
return false;
}
if (hitCornersX.hasHitMax) {
return move.dx < 0;
}
return move.dx > 0;
}
return true;
Comment on lines +32 to 43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why bring this code back? This is the root of the problem on double taps. If the offset is zero in two axis it will return true anyway.

}

bool _shouldMoveX(Offset move) {
final hitCornersX = _hitCornersX();
final mainAxisMove = move.dx;
final crossAxisMove = move.dy;

return _shouldMoveAxis(hitCornersX, mainAxisMove, crossAxisMove);
bool shouldMoveY(Offset move) {
final hitCornersY = this.hitCornersY();
if (hitCornersY.hasHitAny && move != Offset.zero) {
if (hitCornersY.hasHitBoth) {
return false;
}
if (hitCornersY.hasHitMax) {
return move.dy < 0;
}
return move.dy > 0;
}
return true;
}
}

bool _shouldMoveY(Offset move) {
final hitCornersY = _hitCornersY();
final mainAxisMove = move.dy;
final crossAxisMove = move.dx;
class HitAxis {
HitAxis(this.hasHitX, this.hasHitY);

return _shouldMoveAxis(hitCornersY, mainAxisMove, crossAxisMove);
}
final HitCorners hasHitX;
final HitCorners hasHitY;

bool shouldMove(Offset move, Axis mainAxis) {
assert(mainAxis != null);
assert(move != null);
if (mainAxis == Axis.vertical) {
return _shouldMoveY(move);
}
return _shouldMoveX(move);
}
bool get hasHitAny => hasHitX.hasHitAny || hasHitY.hasHitAny;

bool get hasHitBoth => hasHitX.hasHitBoth && hasHitY.hasHitBoth;
}

class HitCorners {
Expand Down
Loading