From 77a99f30afcc89715ef5510d78e20c3a12b56e18 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Thu, 9 Dec 2021 04:18:48 +0800 Subject: [PATCH] Swipe down to dismiss viewer --- lib/widget/viewer.dart | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/widget/viewer.dart b/lib/widget/viewer.dart index 23f16766..00d7df10 100644 --- a/lib/widget/viewer.dart +++ b/lib/widget/viewer.dart @@ -326,7 +326,12 @@ class _ViewerState extends State if (!_canOpenDetailPane()) { return false; } + if (notification is ScrollStartNotification) { + _scrollStartPosition = + _pageStates[index]?.scrollController.position.pixels; + } if (notification is ScrollEndNotification) { + _scrollStartPosition = null; final scrollPos = _pageStates[index]!.scrollController.position; if (scrollPos.pixels == 0) { setState(() { @@ -360,6 +365,19 @@ class _ViewerState extends State }); } } + + if (notification is OverscrollNotification) { + if (_scrollStartPosition == 0) { + // start at top + _overscrollSum += notification.overscroll; + if (_overscrollSum < -176) { + // and scroll downwards + Navigator.of(context).pop(); + } + } + } else { + _overscrollSum = 0; + } return false; } @@ -578,6 +596,9 @@ class _ViewerState extends State bool _isViewerLoaded = false; final _pageStates = {}; + double? _scrollStartPosition; + var _overscrollSum = 0.0; + static final _log = Logger("widget.viewer._ViewerState"); static const _viewportFraction = 1.05;