Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Hide header and nav bar on library scroll, enlarge bookmark delete button

Nathan Poulsona04bd4529287
diff --git a/lib/screens/app_shell.dart b/lib/screens/app_shell.dart
index f3bbb1e1..101a593c 100644
--- a/lib/screens/app_shell.dart
+++ b/lib/screens/app_shell.dart
@@ -62,6 +62,14 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver, Ticker
DateTime? _lastBackPress;
String? _lastCoverItemId; // tracks which item's cover we derived the scheme from
+ // ── Scroll-to-hide bottom nav (driven by Library screen) ──
+ late final AnimationController _navBarAnimController = AnimationController(
+ vsync: this,
+ duration: const Duration(milliseconds: 250),
+ value: 1.0,
+ );
+ VoidCallback? _navBarListener;
+
// Lazily build tabs so startup on Absorbing does not initialize Home/Library
// work until the user actually visits those tabs.
final List<Widget?> _pages = List<Widget?>.filled(5, null, growable: false);
@@ -86,6 +94,7 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver, Ticker
return;
}
_ensurePageBuilt(index);
+ _syncNavBarListener(index);
if (snappyTransitionsNotifier.value) {
setState(() => _currentIndex = index);
} else {
@@ -99,6 +108,38 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver, Ticker
}
}
+ /// Subscribe to library screen's barsVisibleNotifier when on Library tab,
+ /// and ensure the nav bar is visible on all other tabs.
+ void _syncNavBarListener(int index) {
+ if (index == 1) {
+ // Entering Library tab - listen to its visibility notifier
+ final notifier = _libraryKey.currentState?.barsVisibleNotifier;
+ if (notifier != null && _navBarListener == null) {
+ _navBarListener = () {
+ if (notifier.value) {
+ _navBarAnimController.forward();
+ } else {
+ _navBarAnimController.reverse();
+ }
+ };
+ notifier.addListener(_navBarListener!);
+ // Sync to current state
+ _navBarListener!();
+ }
+ } else {
+ // Leaving Library tab - detach and show nav bar
+ _detachNavBarListener();
+ _navBarAnimController.forward();
+ }
+ }
+
+ void _detachNavBarListener() {
+ if (_navBarListener != null) {
+ _libraryKey.currentState?.barsVisibleNotifier.removeListener(_navBarListener!);
+ _navBarListener = null;
+ }
+ }
+
void _ensurePageBuilt(int index) {
if (_pages[index] != null) return;
switch (index) {
@@ -190,6 +231,8 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver, Ticker
@override
void dispose() {
_fadeController.dispose();
+ _detachNavBarListener();
+ _navBarAnimController.dispose();
_player.removeListener(_onPlayerChanged);
_cast.removeListener(_onCastChanged);
try { context.read<LibraryProvider>().removeListener(_onLibraryChanged); } catch (_) {}
@@ -431,32 +474,41 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver, Ticker
),
),
),
- bottomNavigationBar: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- NavigationBar(
- selectedIndex: _currentIndex,
- onDestinationSelected: (i) {
- // If tapping Library while already on Library, clear search
- if (i == 1 && _currentIndex == 1 &&
- _libraryKey.currentState?.isSearchActive == true) {
- _libraryKey.currentState?.clearSearch();
- return;
- }
- _navigateTo(i);
- // Refresh data on switching to Library, Home, Absorbing, or Stats
- if (i == 0 || i == 1 || i == 2 || i == 3) {
- _refreshDataForTab(i);
- }
- },
- destinations: _buildDestinations(context),
- ),
- ],
- ),
+ bottomNavigationBar: _buildBottomNav(context),
),
);
}
+ Widget _buildBottomNav(BuildContext context) {
+ // Lazily attach listener when on Library tab (handles start-on-library case)
+ if (_currentIndex == 1 && _navBarListener == null) {
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (mounted) _syncNavBarListener(1);
+ });
+ }
+ return SizeTransition(
+ sizeFactor: _navBarAnimController,
+ axisAlignment: 1.0,
+ child: NavigationBar(
+ selectedIndex: _currentIndex,
+ onDestinationSelected: (i) {
+ // If tapping Library while already on Library, clear search
+ if (i == 1 && _currentIndex == 1 &&
+ _libraryKey.currentState?.isSearchActive == true) {
+ _libraryKey.currentState?.clearSearch();
+ return;
+ }
+ _navigateTo(i);
+ // Refresh data on switching to Library, Home, Absorbing, or Stats
+ if (i == 0 || i == 1 || i == 2 || i == 3) {
+ _refreshDataForTab(i);
+ }
+ },
+ destinations: _buildDestinations(context),
+ ),
+ );
+ }
+
List<NavigationDestination> _buildDestinations(BuildContext context) {
final l = AppLocalizations.of(context)!;
final lib = context.watch<LibraryProvider>();
diff --git a/lib/screens/library_screen.dart b/lib/screens/library_screen.dart
index 6d9fc8d6..64db0482 100644
--- a/lib/screens/library_screen.dart
+++ b/lib/screens/library_screen.dart
@@ -52,6 +52,7 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
_searchController.clear();
_onSearchChanged('');
_focusNode.unfocus();
+ _showBars();
}
List<dynamic> _searchBookResults = [];
List<dynamic> _searchSeriesResults = [];
@@ -110,6 +111,52 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
bool _rectangleCovers = false;
double get _coverAspectRatio => _rectangleCovers ? 2 / 3 : 1.0;
+ // ── Scroll-to-hide bars ──
+ /// Notifies AppShell whether the bottom nav bar should be visible.
+ final ValueNotifier<bool> barsVisibleNotifier = ValueNotifier(true);
+ late final AnimationController _headerAnimController = AnimationController(
+ vsync: this,
+ duration: const Duration(milliseconds: 250),
+ value: 1.0,
+ );
+ double _lastScrollOffset = 0;
+
+ void _onScrollDirection(ScrollController controller) {
+ if (_isInSearchMode) return;
+ if (!controller.hasClients) return;
+ final offset = controller.offset;
+ final delta = offset - _lastScrollOffset;
+ _lastScrollOffset = offset;
+
+ // At the top, always show
+ if (offset <= 0) {
+ _showBars();
+ return;
+ }
+ // Ignore tiny deltas (noise from overscroll bounce etc.)
+ if (delta.abs() < 1.0) return;
+
+ if (delta > 0) {
+ _hideBars();
+ } else if (delta < 0) {
+ _showBars();
+ }
+ }
+
+ void _showBars() {
+ if (!barsVisibleNotifier.value) {
+ barsVisibleNotifier.value = true;
+ _headerAnimController.forward();
+ }
+ }
+
+ void _hideBars() {
+ if (barsVisibleNotifier.value) {
+ barsVisibleNotifier.value = false;
+ _headerAnimController.reverse();
+ }
+ }
+
/// Called externally (e.g. from AppShell) to focus the search field.
void requestSearchFocus() {
_focusNode.requestFocus();
@@ -122,6 +169,7 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
super.initState();
_scrollController.addListener(_onScroll);
_seriesScrollController.addListener(_onSeriesScroll);
+ _authorsScrollController.addListener(_onAuthorsScroll);
// Load initial page once the library is ready
WidgetsBinding.instance.addPostFrameCallback((_) {
_initTabController();
@@ -142,6 +190,9 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
final newTab = _tabController!.index;
if (newTab == _currentTab) return;
setState(() => _currentTab = newTab);
+ // Reset scroll tracking and show bars when switching sub-tabs
+ _lastScrollOffset = 0;
+ _showBars();
PlayerSettings.setLibraryTab(newTab);
// Lazy load data for the tab
if (newTab == 1 && _seriesItems.isEmpty && !_isLoadingSeriesPage) {
@@ -192,6 +243,8 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
if (_scrollController.hasClients) _scrollController.jumpTo(0);
if (_seriesScrollController.hasClients) _seriesScrollController.jumpTo(0);
if (_authorsScrollController.hasClients) _authorsScrollController.jumpTo(0);
+ _lastScrollOffset = 0;
+ _showBars();
// Restore sort/filter for the new library type, then load
_restoreSortFilter().then((_) {
if (mounted) _loadPage();
@@ -364,6 +417,8 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
_scrollController.dispose();
_seriesScrollController.dispose();
_authorsScrollController.dispose();
+ _headerAnimController.dispose();
+ barsVisibleNotifier.dispose();
_tabController?.removeListener(_onTabChanged);
_tabController?.dispose();
PlayerSettings.settingsChanged.removeListener(_onSettingsChanged);
@@ -375,8 +430,9 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
super.dispose();
}
- // ── Scroll-based pagination ──
+ // ── Scroll-based pagination + direction tracking ──
void _onScroll() {
+ _onScrollDirection(_scrollController);
if (_isInSearchMode) return;
if (_scrollController.position.pixels >=
_scrollController.position.maxScrollExtent - 400) {
@@ -385,12 +441,17 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
}
void _onSeriesScroll() {
+ _onScrollDirection(_seriesScrollController);
if (_seriesScrollController.position.pixels >=
_seriesScrollController.position.maxScrollExtent - 400) {
_loadSeriesPage();
}
}
+ void _onAuthorsScroll() {
+ _onScrollDirection(_authorsScrollController);
+ }
+
// ══════════════════════════════════════════════════════════════
// LIBRARY TAB - Load a page of items
// ══════════════════════════════════════════════════════════════
@@ -835,6 +896,8 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
// ── Search ──
void _onSearchChanged(String query) {
_debounce?.cancel();
+ // Always show bars when entering/exiting search
+ _showBars();
if (query.trim().isEmpty) {
setState(() {
_searchBookResults = [];
@@ -1130,96 +1193,105 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
SafeArea(
child: Column(
children: [
- AbsorbPageHeader(
- title: 'Library',
- trailing: GestureDetector(
- onTap: () {
- final newVal = !lib.isManualOffline;
- lib.setManualOffline(newVal);
- if (newVal) {
- final dl = DownloadService();
- final player = AudioPlayerService();
- final itemId = player.currentItemId;
- final epId = player.currentEpisodeId;
- final dlKey = epId != null && itemId != null
- ? '$itemId-$epId'
- : itemId;
- if (dlKey == null || !dl.isDownloaded(dlKey)) {
- player.stop();
- }
- }
- },
- child: Icon(
- lib.isOffline ? Icons.cloud_off_rounded : Icons.cloud_done_rounded,
- size: 20, color: lib.isOffline ? Colors.orange : Colors.green,
- ),
- ),
- actions: hasMultipleLibraries ? [
- GestureDetector(
- onTap: () => _showLibraryPicker(context, cs, tt, allLibraries, lib),
- child: Container(
- padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
- decoration: BoxDecoration(
- color: cs.onSurface.withValues(alpha: 0.06),
- borderRadius: BorderRadius.circular(20),
- border: Border.all(color: cs.onSurface.withValues(alpha: 0.08)),
+ SizeTransition(
+ sizeFactor: _headerAnimController,
+ axisAlignment: -1.0,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ AbsorbPageHeader(
+ title: 'Library',
+ trailing: GestureDetector(
+ onTap: () {
+ final newVal = !lib.isManualOffline;
+ lib.setManualOffline(newVal);
+ if (newVal) {
+ final dl = DownloadService();
+ final player = AudioPlayerService();
+ final itemId = player.currentItemId;
+ final epId = player.currentEpisodeId;
+ final dlKey = epId != null && itemId != null
+ ? '$itemId-$epId'
+ : itemId;
+ if (dlKey == null || !dl.isDownloaded(dlKey)) {
+ player.stop();
+ }
+ }
+ },
+ child: Icon(
+ lib.isOffline ? Icons.cloud_off_rounded : Icons.cloud_done_rounded,
+ size: 20, color: lib.isOffline ? Colors.orange : Colors.green,
+ ),
),
- child: SizedBox(
- height: 20,
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Icon(lib.isPodcastLibrary ? Icons.podcasts_rounded : Icons.auto_stories_rounded, size: 18, color: cs.onSurfaceVariant),
- const SizedBox(width: 6),
- ConstrainedBox(
- constraints: const BoxConstraints(maxWidth: 140),
- child: Text(libraryName, style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: cs.onSurfaceVariant),
- overflow: TextOverflow.ellipsis, maxLines: 1),
+ actions: hasMultipleLibraries ? [
+ GestureDetector(
+ onTap: () => _showLibraryPicker(context, cs, tt, allLibraries, lib),
+ child: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
+ decoration: BoxDecoration(
+ color: cs.onSurface.withValues(alpha: 0.06),
+ borderRadius: BorderRadius.circular(20),
+ border: Border.all(color: cs.onSurface.withValues(alpha: 0.08)),
),
- const SizedBox(width: 4),
- Icon(Icons.unfold_more_rounded, size: 18, color: cs.onSurfaceVariant),
- ],
+ child: SizedBox(
+ height: 20,
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(lib.isPodcastLibrary ? Icons.podcasts_rounded : Icons.auto_stories_rounded, size: 18, color: cs.onSurfaceVariant),
+ const SizedBox(width: 6),
+ ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 140),
+ child: Text(libraryName, style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: cs.onSurfaceVariant),
+ overflow: TextOverflow.ellipsis, maxLines: 1),
+ ),
+ const SizedBox(width: 4),
+ Icon(Icons.unfold_more_rounded, size: 18, color: cs.onSurfaceVariant),
+ ],
+ ),
+ ),
+ ),
),
- ),
+ ] : null,
),
- ),
- ] : null,
- ),
- Padding(
- padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
- child: SearchBar(
- controller: _searchController,
- focusNode: _focusNode,
- hintText: lib.isPodcastLibrary
- ? 'Search shows and episodes...'
- : 'Search books, series, and authors...',
- leading: const Padding(
- padding: EdgeInsets.only(left: 8),
- child: Icon(Icons.search_rounded),
- ),
- trailing: [
- if (_searchController.text.isNotEmpty)
- IconButton(
- icon: const Icon(Icons.clear_rounded),
- onPressed: () {
- _searchController.clear();
- _onSearchChanged('');
- _focusNode.unfocus();
- },
+ Padding(
+ padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
+ child: SearchBar(
+ controller: _searchController,
+ focusNode: _focusNode,
+ hintText: lib.isPodcastLibrary
+ ? 'Search shows and episodes...'
+ : 'Search books, series, and authors...',
+ leading: const Padding(
+ padding: EdgeInsets.only(left: 8),
+ child: Icon(Icons.search_rounded),
+ ),
+ trailing: [
+ if (_searchController.text.isNotEmpty)
+ IconButton(
+ icon: const Icon(Icons.clear_rounded),
+ onPressed: () {
+ _searchController.clear();
+ _onSearchChanged('');
+ _focusNode.unfocus();
+ },
+ ),
+ ],
+ onChanged: _onSearchChanged,
+ padding: const WidgetStatePropertyAll(EdgeInsets.symmetric(horizontal: 8)),
+ side: WidgetStatePropertyAll(
+ BorderSide(color: cs.onSurface.withValues(alpha: 0.08)),
+ ),
),
+ ),
+
+ // Item count + filter badge row
+ if (!_isInSearchMode)
+ _buildInfoRow(cs, tt),
],
- onChanged: _onSearchChanged,
- padding: const WidgetStatePropertyAll(EdgeInsets.symmetric(horizontal: 8)),
- side: WidgetStatePropertyAll(
- BorderSide(color: cs.onSurface.withValues(alpha: 0.08)),
- ),
),
),
- // Item count + filter badge row
- if (!_isInSearchMode)
- _buildInfoRow(cs, tt),
-
Expanded(
child: Stack(
children: [
@@ -1233,23 +1305,47 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
Positioned(
left: 0, right: 0,
bottom: 12,
- child: _buildFloatingTabBar(cs),
+ child: ValueListenableBuilder<bool>(
+ valueListenable: barsVisibleNotifier,
+ builder: (_, visible, child) => AnimatedSlide(
+ duration: const Duration(milliseconds: 250),
+ offset: visible ? Offset.zero : const Offset(0, 3),
+ child: AnimatedOpacity(
+ duration: const Duration(milliseconds: 200),
+ opacity: visible ? 1.0 : 0.0,
+ child: child,
+ ),
+ ),
+ child: _buildFloatingTabBar(cs),
+ ),
),
// Floating sort button for podcast libraries
if (!hasTabs && !_isInSearchMode)
Positioned(
left: 0, right: 0,
bottom: 12,
- child: Center(child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- _buildFloatingSortButton(cs, tt),
- if (context.read<AuthProvider>().isRoot) ...[
- const SizedBox(width: 8),
- _buildFloatingManageButton(cs),
+ child: ValueListenableBuilder<bool>(
+ valueListenable: barsVisibleNotifier,
+ builder: (_, visible, child) => AnimatedSlide(
+ duration: const Duration(milliseconds: 250),
+ offset: visible ? Offset.zero : const Offset(0, 3),
+ child: AnimatedOpacity(
+ duration: const Duration(milliseconds: 200),
+ opacity: visible ? 1.0 : 0.0,
+ child: child,
+ ),
+ ),
+ child: Center(child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ _buildFloatingSortButton(cs, tt),
+ if (context.read<AuthProvider>().isRoot) ...[
+ const SizedBox(width: 8),
+ _buildFloatingManageButton(cs),
+ ],
],
- ],
- )),
+ )),
+ ),
),
],
),
diff --git a/lib/widgets/card_buttons.dart b/lib/widgets/card_buttons.dart
index 5af1ac87..85508e35 100644
--- a/lib/widgets/card_buttons.dart
+++ b/lib/widgets/card_buttons.dart
@@ -644,7 +644,7 @@ class _SimpleBookmarkSheetState extends State<SimpleBookmarkSheet> {
},
onLongPress: () => _editBookmark(bm),
child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
Padding(
padding: const EdgeInsets.only(top: 2),
@@ -686,8 +686,8 @@ class _SimpleBookmarkSheetState extends State<SimpleBookmarkSheet> {
_load();
},
child: Padding(
- padding: const EdgeInsets.all(4),
- child: Icon(Icons.close_rounded, size: 16, color: cs.onSurface.withValues(alpha: 0.24)),
+ padding: const EdgeInsets.all(10),
+ child: Icon(Icons.delete_outline_rounded, size: 22, color: cs.onSurface.withValues(alpha: 0.35)),
),
),
]),