Fix bottom-nav interaction on Bookmarks screen #149
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes two related issues on the Saved (My Bookmarks) screen:
The bottom navigation items (Home/Search/Settings) were not receiving taps because the fragment content overlapped the BottomNavigationView.
The Home button behaviour was inconsistent: after visiting Saved and then switching to Search or Settings, tapping Home could return the user back to Saved instead of always taking them to Home.
What was causing the bug
Touch interception: fragment_saved's RecyclerView was constrained to the parent bottom edge and could overlap the BottomNavigationView; even when the nav was visible on top, the RecyclerView continued to intercept touch events so taps on the bottom nav did nothing in some states.
Navigation/back-stack semantics: SavedFragment is not a bottom-nav destination. After navigating from mainFragment → savedFragment, the BottomNavigationView still showed the Home item as selected. The Navigation component (via setupWithNavController) will ignore reselection by default. Because of the back stack state, tapping Home did not always navigate to the true mainFragment—it sometimes left savedFragment on top, producing the incorrect behaviour.
Solution
Prevent touch interception by leaving space at the bottom of the content: add bottom padding to the RecyclerView in fragment_saved.xml and use a dimen resource for the nav height. clipToPadding="false" allows the RecyclerView to scroll under that padding while keeping the bottom touch area free.
Make bottom-nav selection explicit: intercept bottom nav item selections and either pop back to the matching destination if it exists in the back stack or navigate to it otherwise. Also keep a reselection handler for consistent behavior on tapping an already-selected tab. This ensures Home always navigates to mainFragment.
Files changed
fragment_saved.xml
Added: android:paddingBottom="@dimen/bottom_nav_height" on bookmarks_recycler_view (keeps bottom nav clickable)
dimens.xml
Added: 72dp (adjustable)
MainActivity.kt
Added a custom setOnItemSelectedListener to the BottomNavigationView that:
tries navController.popBackStack(, false) and navigates if pop failed
guarantees selecting Home always ends up on mainFragment
Added a setOnItemReselectedListener to handle reselection (pop back to root of that tab)
Bottom padding in fragment_saved.xml:
bookmarks RecyclerView:
android:paddingBottom="@dimen/bottom_nav_height"
android:clipToPadding="false" (already present)
MainActivity navigation changes:
binding.bottomNavigationView.setOnItemSelectedListener { ... } — ensures deterministic navigation behavior
binding.bottomNavigationView.setOnItemReselectedListener { ... } — preserves reselection semantics (pop to root)
Testing / Verification
From the Home (main) screen:
Tap MY Bookmarks — confirm the My Bookmarks screen opens.
Tap Home — should return to Home (mainFragment).
From Home, open Saved again, then:
Tap Search — confirm it goes to Search.
Tap Settings — confirm it goes to Settings.
Tap Home — must always go to Home (mainFragment) (this was the incorrect behavior before).
On Saved screen, verify bottom nav buttons are responsive (touches register immediately).
Verify RecyclerView scroll still works and content isn't covered visually (padding is only space — RecyclerView can scroll under the padding).