Improve the long press to zoom feature.

Close #287
This commit is contained in:
2025-03-27 13:04:19 +08:00
parent d812332613
commit d440ed6424
3 changed files with 24 additions and 6 deletions

View File

@@ -455,6 +455,7 @@ class _ContinuousModeState extends State<_ContinuousMode>
bool jumpToPrevChapter = false; bool jumpToPrevChapter = false;
bool isZoomedIn = false; bool isZoomedIn = false;
bool isLongPressing = false;
@override @override
void initState() { void initState() {
@@ -668,8 +669,23 @@ class _ContinuousModeState extends State<_ContinuousMode>
if (photoViewController.scale == 1 || fingers != 1) { if (photoViewController.scale == 1 || fingers != 1) {
return; 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( photoViewController.updateMultiple(
position: photoViewController.position + Offset(value.dx, value.dy), position: photoViewController.position + offset,
); );
}, },
onPointerSignal: onPointerSignal, onPointerSignal: onPointerSignal,
@@ -807,12 +823,12 @@ class _ContinuousModeState extends State<_ContinuousMode>
return; return;
} }
double target = photoViewController.getInitialScale!.call()! * 1.75; double target = photoViewController.getInitialScale!.call()! * 1.75;
var size = MediaQuery.of(context).size;
photoViewController.animateScale?.call( photoViewController.animateScale?.call(
target, target,
Offset(size.width / 2 - location.dx, size.height / 2 - location.dy), Offset(0, 0),
); );
onScaleUpdate(target); onScaleUpdate(target);
isLongPressing = true;
} }
@override @override
@@ -822,6 +838,8 @@ class _ContinuousModeState extends State<_ContinuousMode>
} }
double target = photoViewController.getInitialScale!.call()!; double target = photoViewController.getInitialScale!.call()!;
photoViewController.animateScale?.call(target); photoViewController.animateScale?.call(target);
onScaleUpdate(target);
isLongPressing = false;
} }
@override @override

View File

@@ -725,8 +725,8 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
path: "." path: "."
ref: d71faf3c75e059d013b0ce9ddaf5ecc1680e2eb6 ref: a1255d1b5945aad4b7323303ec2ecdf0c90ffc4c
resolved-ref: d71faf3c75e059d013b0ce9ddaf5ecc1680e2eb6 resolved-ref: a1255d1b5945aad4b7323303ec2ecdf0c90ffc4c
url: "https://github.com/wgh136/photo_view" url: "https://github.com/wgh136/photo_view"
source: git source: git
version: "0.14.0" version: "0.14.0"

View File

@@ -29,7 +29,7 @@ dependencies:
photo_view: photo_view:
git: git:
url: https://github.com/wgh136/photo_view url: https://github.com/wgh136/photo_view
ref: d71faf3c75e059d013b0ce9ddaf5ecc1680e2eb6 ref: a1255d1b5945aad4b7323303ec2ecdf0c90ffc4c
mime: ^2.0.0 mime: ^2.0.0
share_plus: ^10.1.4 share_plus: ^10.1.4
scrollable_positioned_list: scrollable_positioned_list: