From 76da2ca3901c031c3b71dc6470e52a42dcb2556e Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Fri, 7 Apr 2023 08:55:37 -0400 Subject: [PATCH] Clicking on home button when on that screen scrolls it to the top --- CHANGELOG.md | 1 + beta-program.md | 1 + lib/controls/app_bottom_nav_bar.dart | 11 ++++++++++- lib/controls/timeline/timeline_panel.dart | 11 +++++++++-- lib/screens/home.dart | 9 ++++++--- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02497a2..b431ad8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * The "copy text" action now copies the plain text not HTML version. So things like hashtags show up as "#hashtag" not the HTML code around it with the link reference etc. + * Clicking on the "Home" button if you already are on that screen scrolls to the top. * Fixes * New Features diff --git a/beta-program.md b/beta-program.md index 6d6a19d..10d23a0 100644 --- a/beta-program.md +++ b/beta-program.md @@ -120,6 +120,7 @@ wanted to lay out some expectations before getting into the small details * Nitter replacement of Twitter links * User configurable Server blocking * Server-side searching tied into profiles, posts, hashtags +* Smarter hashtag and user account storage/searching * Being able to ignore/unignore users * Deleting images and entire galleries * Events diff --git a/lib/controls/app_bottom_nav_bar.dart b/lib/controls/app_bottom_nav_bar.dart index c98265f..7f215db 100644 --- a/lib/controls/app_bottom_nav_bar.dart +++ b/lib/controls/app_bottom_nav_bar.dart @@ -17,8 +17,13 @@ enum NavBarButtons { class AppBottomNavBar extends StatelessWidget { static final _logger = Logger('$AppBottomNavBar'); final NavBarButtons currentButton; + final Function()? onHomeButtonReclick; - const AppBottomNavBar({super.key, required this.currentButton}); + const AppBottomNavBar({ + super.key, + required this.currentButton, + this.onHomeButtonReclick, + }); @override Widget build(BuildContext context) { @@ -36,6 +41,10 @@ class AppBottomNavBar extends StatelessWidget { onTap: (index) { final newButton = _indexToButton(index); if (newButton == currentButton) { + if (newButton == NavBarButtons.timelines && + onHomeButtonReclick != null) { + onHomeButtonReclick!(); + } return; } diff --git a/lib/controls/timeline/timeline_panel.dart b/lib/controls/timeline/timeline_panel.dart index 00914a5..d8fe46e 100644 --- a/lib/controls/timeline/timeline_panel.dart +++ b/lib/controls/timeline/timeline_panel.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:logging/logging.dart'; import 'package:provider/provider.dart'; +import 'package:scrollable_positioned_list/scrollable_positioned_list.dart'; import '../../models/TimelineIdentifiers.dart'; import '../../services/timeline_manager.dart'; @@ -10,8 +11,9 @@ import 'post_control.dart'; class TimelinePanel extends StatelessWidget { static final _logger = Logger('$TimelinePanel'); final TimelineIdentifiers timeline; + final controller = ItemScrollController(); - const TimelinePanel({super.key, required this.timeline}); + TimelinePanel({super.key, required this.timeline}); Future update(TimelineManager manager) async { await manager.updateTimeline( @@ -25,6 +27,10 @@ class TimelinePanel extends StatelessWidget { ); } + void scrollToTop() { + controller.jumpTo(index: 0); + } + @override Widget build(BuildContext context) { _logger.finer('Build'); @@ -50,7 +56,8 @@ class TimelinePanel extends StatelessWidget { ], ), ) - : ListView.builder( + : ScrollablePositionedList.builder( + itemScrollController: controller, physics: const AlwaysScrollableScrollPhysics(), itemBuilder: (context, index) { if (index == 0) { diff --git a/lib/screens/home.dart b/lib/screens/home.dart index cd97db0..aae2406 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -78,6 +78,8 @@ class _HomeScreenState extends State { currentGroup = null; } + final timeline = TimelinePanel(timeline: currentTimeline); + return Scaffold( appBar: AppBar( leading: accountService.loggedIn @@ -150,13 +152,14 @@ class _HomeScreenState extends State { child: Column( children: [ StandardLinearProgressIndicator(nss.timelineLoadingStatus), - Expanded(child: TimelinePanel(timeline: currentTimeline)), + Expanded(child: timeline), ], ), ), - drawer: StandardAppDrawer(), - bottomNavigationBar: const AppBottomNavBar( + drawer: const StandardAppDrawer(), + bottomNavigationBar: AppBottomNavBar( currentButton: NavBarButtons.timelines, + onHomeButtonReclick: () => timeline.scrollToTop(), ), floatingActionButton: FloatingActionButton.small( onPressed: () {