From fda9e6195a995e00c067e129bca394d00f66d060 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Sat, 15 Jul 2023 18:54:53 -0400 Subject: [PATCH] Make transition animation directional (#675) --- lib/pages/home.dart | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/pages/home.dart b/lib/pages/home.dart index 1e74fcc..c64ed03 100644 --- a/lib/pages/home.dart +++ b/lib/pages/home.dart @@ -26,6 +26,7 @@ class NavigationPageItem { class _HomePageState extends State { List selectedIndexHistory = []; + bool isReversing = false; int prevAppCount = -1; bool prevIsLoading = true; @@ -42,7 +43,16 @@ class _HomePageState extends State { Widget build(BuildContext context) { AppsProvider appsProvider = context.watch(); + setIsReversing(int targetIndex) { + bool reversing = selectedIndexHistory.isNotEmpty && + selectedIndexHistory.last > targetIndex; + setState(() { + isReversing = reversing; + }); + } + switchToPage(int index) async { + setIsReversing(index); if (index == 0) { while ((pages[0].widget.key as GlobalKey).currentState != null) { @@ -79,6 +89,7 @@ class _HomePageState extends State { child: Scaffold( backgroundColor: Theme.of(context).colorScheme.surface, body: PageTransitionSwitcher( + reverse: isReversing, transitionBuilder: ( Widget child, Animation animation, @@ -104,13 +115,16 @@ class _HomePageState extends State { .toList(), onDestinationSelected: (int index) async { HapticFeedback.selectionClick(); - await switchToPage(index); + switchToPage(index); }, selectedIndex: selectedIndexHistory.isEmpty ? 0 : selectedIndexHistory.last, ), ), onWillPop: () async { + setIsReversing(selectedIndexHistory.length >= 2 + ? selectedIndexHistory.reversed.toList()[1] + : 0); if (selectedIndexHistory.isNotEmpty) { setState(() { selectedIndexHistory.removeLast();