fix: preserve platform bottom navigation implementation (#6956)

This commit is contained in:
Thomas W. 2025-01-16 17:16:19 +01:00 committed by GitHub
parent 5bafa1209a
commit f519168422
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 8 deletions

View File

@ -26,6 +26,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.onNavDestinationSelected
import androidx.navigation.ui.setupWithNavController
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.BuildConfig
@ -163,7 +164,6 @@ class MainActivity : BaseActivity() {
binding.bottomNav.setOnItemSelectedListener {
navigateToBottomSelectedItem(it)
false
}
if (binding.bottomNav.menu.children.none { it.itemId == startFragmentId }) deselectBottomBarItems()
@ -551,21 +551,17 @@ class MainActivity : BaseActivity() {
}
}
private fun navigateToBottomSelectedItem(item: MenuItem) {
private fun navigateToBottomSelectedItem(item: MenuItem): Boolean {
if (item.itemId == R.id.subscriptionsFragment) {
binding.bottomNav.removeBadge(R.id.subscriptionsFragment)
}
// navigate to the selected fragment, if the fragment already
// exists in backstack then pop up to that entry
if (!navController.popBackStack(item.itemId, false)) {
navController.navigate(item.itemId)
}
// Remove focus from search view when navigating to bottom view.
// Call only after navigate to destination, so it can be used in
// onMenuItemActionCollapse for backstack management
removeSearchFocus()
return item.onNavDestinationSelected(navController)
}
override fun onUserLeaveHint() {

View File

@ -41,6 +41,7 @@
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@+id/bottomNav"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"