Swipe down to dismiss viewer

This commit is contained in:
Ming Ming 2021-12-09 04:18:48 +08:00
parent d4334f3a2b
commit 77a99f30af

View file

@ -326,7 +326,12 @@ class _ViewerState extends State<Viewer>
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<Viewer>
});
}
}
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<Viewer>
bool _isViewerLoaded = false;
final _pageStates = <int, _PageState>{};
double? _scrollStartPosition;
var _overscrollSum = 0.0;
static final _log = Logger("widget.viewer._ViewerState");
static const _viewportFraction = 1.05;