Skip to content

Commit

Permalink
[Presentation] Lets just tap once to scroll to top
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Jan 24, 2024
1 parent fd16411 commit e2b0a1c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/presentation/desktop_tablet_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class _NavigationRailState extends State<_NavigationRail> with ScrollToTopOnDoub
return;
}

scrollToTopOnTabDoubleTap(widget.tabController.index, realIndex, widget.scrollControllers);
scrollToTopOnTabTap(widget.tabController.index, realIndex, widget.scrollControllers);
context.read<MainTabBloc>().add(MainTabEvent.goToTab(index: realIndex));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/mobile_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class _MobileScaffoldState extends State<MobileScaffold> with SingleTickerProvid
}

void _gotoTab(int newIndex) {
scrollToTopOnTabDoubleTap(widget.tabController.index, newIndex, widget.scrollControllers);
scrollToTopOnTabTap(widget.tabController.index, newIndex, widget.scrollControllers);
context.read<MainTabBloc>().add(MainTabEvent.goToTab(index: newIndex));
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import 'package:flutter/material.dart';

mixin ScrollToTopOnDoubleTabTapMixin<T extends StatefulWidget> on State<T> {
DateTime? _tabPressedAt;

void scrollToTopOnTabDoubleTap(int currentIndex, int newIndex, List<ScrollController> scrollControllers) {
final DateTime now = DateTime.now();
void scrollToTopOnTabTap(int currentIndex, int newIndex, List<ScrollController> scrollControllers) {
final bool sameTab = currentIndex == newIndex;
final bool diffExists = _tabPressedAt != null && now.difference(_tabPressedAt!).inMilliseconds < 200;
if (sameTab && diffExists) {
if (sameTab) {
scrollControllers.elementAtOrNull(newIndex)?.animateTo(0, duration: const Duration(milliseconds: 500), curve: Curves.linear);
}
_tabPressedAt = now;
}
}

0 comments on commit e2b0a1c

Please sign in to comment.