fullscreen: improved vertical scroll performance
This commit is contained in:
parent
1b6759384e
commit
43ef91cc7b
1 changed files with 53 additions and 37 deletions
|
@ -58,7 +58,8 @@ class FullscreenBody extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProviderStateMixin {
|
class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProviderStateMixin {
|
||||||
int _currentHorizontalPage, _currentVerticalPage = imagePage;
|
int _currentHorizontalPage;
|
||||||
|
final ValueNotifier<int> _currentVerticalPage = ValueNotifier(imagePage);
|
||||||
PageController _horizontalPager, _verticalPager;
|
PageController _horizontalPager, _verticalPager;
|
||||||
final ValueNotifier<bool> _overlayVisible = ValueNotifier(true);
|
final ValueNotifier<bool> _overlayVisible = ValueNotifier(true);
|
||||||
AnimationController _overlayAnimationController;
|
AnimationController _overlayAnimationController;
|
||||||
|
@ -82,7 +83,7 @@ class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProvide
|
||||||
final index = entries.indexWhere((entry) => entry.uri == widget.initialUri);
|
final index = entries.indexWhere((entry) => entry.uri == widget.initialUri);
|
||||||
_currentHorizontalPage = max(0, index);
|
_currentHorizontalPage = max(0, index);
|
||||||
_horizontalPager = PageController(initialPage: _currentHorizontalPage);
|
_horizontalPager = PageController(initialPage: _currentHorizontalPage);
|
||||||
_verticalPager = PageController(initialPage: _currentVerticalPage);
|
_verticalPager = PageController(initialPage: _currentVerticalPage.value);
|
||||||
_overlayAnimationController = AnimationController(
|
_overlayAnimationController = AnimationController(
|
||||||
duration: const Duration(milliseconds: 400),
|
duration: const Duration(milliseconds: 400),
|
||||||
vsync: this,
|
vsync: this,
|
||||||
|
@ -121,11 +122,9 @@ class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProvide
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final entry = _currentHorizontalPage != null && _currentHorizontalPage < entries.length ? entries[_currentHorizontalPage] : null;
|
final entry = _currentHorizontalPage != null && _currentHorizontalPage < entries.length ? entries[_currentHorizontalPage] : null;
|
||||||
final showOverlay = entry != null && _currentVerticalPage == imagePage;
|
|
||||||
final videoController = showOverlay && entry.isVideo ? _videoControllers.firstWhere((kv) => kv.item1 == entry.path, orElse: () => null)?.item2 : null;
|
|
||||||
return WillPopScope(
|
return WillPopScope(
|
||||||
onWillPop: () {
|
onWillPop: () {
|
||||||
if (_currentVerticalPage == infoPage) {
|
if (_currentVerticalPage.value == infoPage) {
|
||||||
_goToVerticalPage(imagePage);
|
_goToVerticalPage(imagePage);
|
||||||
return Future.value(false);
|
return Future.value(false);
|
||||||
}
|
}
|
||||||
|
@ -145,15 +144,29 @@ class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProvide
|
||||||
onImageTap: () => _overlayVisible.value = !_overlayVisible.value,
|
onImageTap: () => _overlayVisible.value = !_overlayVisible.value,
|
||||||
onImagePageRequested: () => _goToVerticalPage(imagePage),
|
onImagePageRequested: () => _goToVerticalPage(imagePage),
|
||||||
),
|
),
|
||||||
if (showOverlay) FullscreenTopOverlay(
|
ValueListenableBuilder<int>(
|
||||||
|
valueListenable: _currentVerticalPage,
|
||||||
|
builder: (context, page, child) {
|
||||||
|
final showOverlay = entry != null && page == imagePage;
|
||||||
|
return showOverlay
|
||||||
|
? FullscreenTopOverlay(
|
||||||
entries: entries,
|
entries: entries,
|
||||||
index: _currentHorizontalPage,
|
index: _currentHorizontalPage,
|
||||||
scale: _topOverlayScale,
|
scale: _topOverlayScale,
|
||||||
viewInsets: _frozenViewInsets,
|
viewInsets: _frozenViewInsets,
|
||||||
viewPadding: _frozenViewPadding,
|
viewPadding: _frozenViewPadding,
|
||||||
onActionSelected: (action) => _actionDelegate.onActionSelected(context, entry, action),
|
onActionSelected: (action) => _actionDelegate.onActionSelected(context, entry, action),
|
||||||
|
)
|
||||||
|
: const SizedBox.shrink();
|
||||||
|
},
|
||||||
),
|
),
|
||||||
if (showOverlay) Positioned(
|
ValueListenableBuilder<int>(
|
||||||
|
valueListenable: _currentVerticalPage,
|
||||||
|
builder: (context, page, child) {
|
||||||
|
final showOverlay = entry != null && page == imagePage;
|
||||||
|
final videoController = showOverlay && entry.isVideo ? _videoControllers.firstWhere((kv) => kv.item1 == entry.path, orElse: () => null)?.item2 : null;
|
||||||
|
return showOverlay
|
||||||
|
? Positioned(
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
|
@ -176,6 +189,9 @@ class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProvide
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
)
|
||||||
|
: const SizedBox.shrink();
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -191,8 +207,8 @@ class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProvide
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onVerticalPageChanged(int page) {
|
void _onVerticalPageChanged(int page) {
|
||||||
setState(() => _currentVerticalPage = page);
|
_currentVerticalPage.value = page;
|
||||||
if (_currentVerticalPage == transitionPage) {
|
if (page == transitionPage) {
|
||||||
_onLeave();
|
_onLeave();
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue