mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-01 05:10:15 +02:00
Make transition animation directional (#675)
This commit is contained in:
@@ -26,6 +26,7 @@ class NavigationPageItem {
|
|||||||
|
|
||||||
class _HomePageState extends State<HomePage> {
|
class _HomePageState extends State<HomePage> {
|
||||||
List<int> selectedIndexHistory = [];
|
List<int> selectedIndexHistory = [];
|
||||||
|
bool isReversing = false;
|
||||||
int prevAppCount = -1;
|
int prevAppCount = -1;
|
||||||
bool prevIsLoading = true;
|
bool prevIsLoading = true;
|
||||||
|
|
||||||
@@ -42,7 +43,16 @@ class _HomePageState extends State<HomePage> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
AppsProvider appsProvider = context.watch<AppsProvider>();
|
AppsProvider appsProvider = context.watch<AppsProvider>();
|
||||||
|
|
||||||
|
setIsReversing(int targetIndex) {
|
||||||
|
bool reversing = selectedIndexHistory.isNotEmpty &&
|
||||||
|
selectedIndexHistory.last > targetIndex;
|
||||||
|
setState(() {
|
||||||
|
isReversing = reversing;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
switchToPage(int index) async {
|
switchToPage(int index) async {
|
||||||
|
setIsReversing(index);
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
while ((pages[0].widget.key as GlobalKey<AppsPageState>).currentState !=
|
while ((pages[0].widget.key as GlobalKey<AppsPageState>).currentState !=
|
||||||
null) {
|
null) {
|
||||||
@@ -79,6 +89,7 @@ class _HomePageState extends State<HomePage> {
|
|||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||||
body: PageTransitionSwitcher(
|
body: PageTransitionSwitcher(
|
||||||
|
reverse: isReversing,
|
||||||
transitionBuilder: (
|
transitionBuilder: (
|
||||||
Widget child,
|
Widget child,
|
||||||
Animation<double> animation,
|
Animation<double> animation,
|
||||||
@@ -104,13 +115,16 @@ class _HomePageState extends State<HomePage> {
|
|||||||
.toList(),
|
.toList(),
|
||||||
onDestinationSelected: (int index) async {
|
onDestinationSelected: (int index) async {
|
||||||
HapticFeedback.selectionClick();
|
HapticFeedback.selectionClick();
|
||||||
await switchToPage(index);
|
switchToPage(index);
|
||||||
},
|
},
|
||||||
selectedIndex:
|
selectedIndex:
|
||||||
selectedIndexHistory.isEmpty ? 0 : selectedIndexHistory.last,
|
selectedIndexHistory.isEmpty ? 0 : selectedIndexHistory.last,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onWillPop: () async {
|
onWillPop: () async {
|
||||||
|
setIsReversing(selectedIndexHistory.length >= 2
|
||||||
|
? selectedIndexHistory.reversed.toList()[1]
|
||||||
|
: 0);
|
||||||
if (selectedIndexHistory.isNotEmpty) {
|
if (selectedIndexHistory.isNotEmpty) {
|
||||||
setState(() {
|
setState(() {
|
||||||
selectedIndexHistory.removeLast();
|
selectedIndexHistory.removeLast();
|
||||||
|
Reference in New Issue
Block a user