From b0ba159996357d4ab3ed6364e7695e5f798066b7 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Fri, 12 Nov 2021 10:33:41 +0900 Subject: [PATCH] #101 pinch-to-zoom looks for neighbouring thumbnails when focal point not on thumbnail --- lib/widgets/common/scaling.dart | 34 ++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/widgets/common/scaling.dart b/lib/widgets/common/scaling.dart index 88156ebda..ea1e624ca 100644 --- a/lib/widgets/common/scaling.dart +++ b/lib/widgets/common/scaling.dart @@ -55,14 +55,16 @@ class _GridScaleGestureDetectorState extends State(); + final scrollableContext = widget.scrollableKey.currentContext!; final scrollableBox = scrollableContext.findRenderObject() as RenderBox; - final result = BoxHitTestResult(); - scrollableBox.hitTest(result, position: details.localFocalPoint); - - // find `RenderObject`s at the gesture focal point - U? firstOf(BoxHitTestResult result) => result.path.firstWhereOrNull((el) => el.target is U)?.target as U?; - final renderMetaData = firstOf(result); + final renderMetaData = _getClosestRenderMetadata( + box: scrollableBox, + localFocalPoint: details.localFocalPoint, + spacing: tileExtentController.spacing, + ); // abort if we cannot find an image to show on overlay if (renderMetaData == null) return; _metadata = renderMetaData.metaData; @@ -72,7 +74,6 @@ class _GridScaleGestureDetectorState extends State(); _extentMin = tileExtentController.effectiveExtentMin; _extentMax = tileExtentController.effectiveExtentMax; @@ -138,6 +139,25 @@ class _GridScaleGestureDetectorState extends State 0 && position.dy > 0) { + final result = BoxHitTestResult(); + box.hitTest(result, position: position); + + // find `RenderObject`s at the gesture focal point + U? firstOf(BoxHitTestResult result) => result.path.firstWhereOrNull((el) => el.target is U)?.target as U?; + final renderMetaData = firstOf(result); + if (renderMetaData != null) return renderMetaData; + position = position.translate(-spacing, -spacing); + } + return null; + } } class ScaleOverlay extends StatefulWidget {