From d440ed6424eff183ec4d8124920922245c018407 Mon Sep 17 00:00:00 2001 From: nyne Date: Thu, 27 Mar 2025 13:04:19 +0800 Subject: [PATCH] Improve the long press to zoom feature. Close #287 --- lib/pages/reader/images.dart | 24 +++++++++++++++++++++--- pubspec.lock | 4 ++-- pubspec.yaml | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/pages/reader/images.dart b/lib/pages/reader/images.dart index 3ea42b0..7cc608e 100644 --- a/lib/pages/reader/images.dart +++ b/lib/pages/reader/images.dart @@ -455,6 +455,7 @@ class _ContinuousModeState extends State<_ContinuousMode> bool jumpToPrevChapter = false; bool isZoomedIn = false; + bool isLongPressing = false; @override void initState() { @@ -668,8 +669,23 @@ class _ContinuousModeState extends State<_ContinuousMode> if (photoViewController.scale == 1 || fingers != 1) { return; } + Offset offset; + var sp = scrollController.position; + if (sp.pixels < sp.minScrollExtent + || sp.pixels > sp.maxScrollExtent) { + offset = Offset(value.dx, value.dy); + } else { + if (reader.mode == ReaderMode.continuousTopToBottom) { + offset = Offset(value.dx, 0); + } else { + offset = Offset(0, value.dy); + } + } + if (isLongPressing) { + offset += value; + } photoViewController.updateMultiple( - position: photoViewController.position + Offset(value.dx, value.dy), + position: photoViewController.position + offset, ); }, onPointerSignal: onPointerSignal, @@ -807,12 +823,12 @@ class _ContinuousModeState extends State<_ContinuousMode> return; } double target = photoViewController.getInitialScale!.call()! * 1.75; - var size = MediaQuery.of(context).size; photoViewController.animateScale?.call( target, - Offset(size.width / 2 - location.dx, size.height / 2 - location.dy), + Offset(0, 0), ); onScaleUpdate(target); + isLongPressing = true; } @override @@ -822,6 +838,8 @@ class _ContinuousModeState extends State<_ContinuousMode> } double target = photoViewController.getInitialScale!.call()!; photoViewController.animateScale?.call(target); + onScaleUpdate(target); + isLongPressing = false; } @override diff --git a/pubspec.lock b/pubspec.lock index 620d6c1..effdaa0 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -725,8 +725,8 @@ packages: dependency: "direct main" description: path: "." - ref: d71faf3c75e059d013b0ce9ddaf5ecc1680e2eb6 - resolved-ref: d71faf3c75e059d013b0ce9ddaf5ecc1680e2eb6 + ref: a1255d1b5945aad4b7323303ec2ecdf0c90ffc4c + resolved-ref: a1255d1b5945aad4b7323303ec2ecdf0c90ffc4c url: "https://github.com/wgh136/photo_view" source: git version: "0.14.0" diff --git a/pubspec.yaml b/pubspec.yaml index ae37b56..42e84aa 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,7 +29,7 @@ dependencies: photo_view: git: url: https://github.com/wgh136/photo_view - ref: d71faf3c75e059d013b0ce9ddaf5ecc1680e2eb6 + ref: a1255d1b5945aad4b7323303ec2ecdf0c90ffc4c mime: ^2.0.0 share_plus: ^10.1.4 scrollable_positioned_list: