Change BottomNavigationView behavior (#5603)
Similar to app bar's scroll behavior (cherry picked from commit ff2a4e69526a2edfa5f3bd7570c09204e5ebb9f9) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
This commit is contained in:
parent
2b4adc0c7d
commit
d5423caf91
@ -429,7 +429,7 @@ class LibraryController(
|
||||
actionMode!!,
|
||||
R.menu.library_selection
|
||||
) { onActionItemClicked(it!!) }
|
||||
(activity as? MainActivity)?.showBottomNav(visible = false, collapse = true)
|
||||
(activity as? MainActivity)?.showBottomNav(visible = false, expand = true)
|
||||
}
|
||||
}
|
||||
|
||||
@ -577,7 +577,7 @@ class LibraryController(
|
||||
selectionRelay.call(LibrarySelectionEvent.Cleared())
|
||||
|
||||
binding.actionToolbar.hide()
|
||||
(activity as? MainActivity)?.showBottomNav(visible = true, collapse = true)
|
||||
(activity as? MainActivity)?.showBottomNav(visible = true, expand = true)
|
||||
|
||||
actionMode = null
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ import com.bluelinelabs.conductor.Controller
|
||||
import com.bluelinelabs.conductor.ControllerChangeHandler
|
||||
import com.bluelinelabs.conductor.Router
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior
|
||||
import com.google.android.material.navigation.NavigationBarView
|
||||
import dev.chrisbanes.insetter.applyInsetter
|
||||
import eu.kanade.tachiyomi.R
|
||||
@ -61,6 +60,7 @@ import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import eu.kanade.tachiyomi.util.view.setNavigationBarTransparentCompat
|
||||
import eu.kanade.tachiyomi.widget.HideBottomNavigationOnScrollBehavior
|
||||
import exh.EXHMigrations
|
||||
import exh.eh.EHentaiUpdateWorker
|
||||
import exh.source.BlacklistedSources
|
||||
@ -168,15 +168,6 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
||||
if (binding.bottomNav != null) {
|
||||
bottomNavAnimator = ViewHeightAnimator(binding.bottomNav!!)
|
||||
|
||||
// If bottom nav is hidden, make it visible again when the app bar is expanded
|
||||
binding.appbar.addOnOffsetChangedListener(
|
||||
AppBarLayout.OnOffsetChangedListener { _, verticalOffset ->
|
||||
if (verticalOffset == 0) {
|
||||
showNav(visible = true)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// Set behavior of bottom nav
|
||||
preferences.hideBottomBarOnScroll()
|
||||
.asImmediateFlow { setBottomNavBehaviorOnScroll() }
|
||||
@ -555,11 +546,11 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
||||
binding.appbar.setExpanded(true)
|
||||
|
||||
if ((from == null || from is RootController) && to !is RootController) {
|
||||
showNav(visible = false, collapse = true)
|
||||
showNav(visible = false, expand = true)
|
||||
}
|
||||
if (to is RootController) {
|
||||
// Always show bottom nav again when returning to a RootController
|
||||
showNav(visible = true, collapse = from !is RootController)
|
||||
showNav(visible = true, expand = from !is RootController)
|
||||
}
|
||||
|
||||
if (from is TabbedController) {
|
||||
@ -595,33 +586,24 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun showNav(visible: Boolean, collapse: Boolean = false) {
|
||||
showBottomNav(visible, collapse)
|
||||
private fun showNav(visible: Boolean, expand: Boolean = false) {
|
||||
showBottomNav(visible, expand)
|
||||
showSideNav(visible)
|
||||
}
|
||||
|
||||
// Also used from some controllers to swap bottom nav with action toolbar
|
||||
fun showBottomNav(visible: Boolean, collapse: Boolean = false) {
|
||||
binding.bottomNav?.let {
|
||||
val layoutParams = it.layoutParams as CoordinatorLayout.LayoutParams
|
||||
val bottomViewNavigationBehavior =
|
||||
layoutParams.behavior as? HideBottomViewOnScrollBehavior
|
||||
fun showBottomNav(visible: Boolean, expand: Boolean = false) {
|
||||
if (visible) {
|
||||
if (collapse) {
|
||||
binding.bottomNav?.translationY = 0F
|
||||
if (expand) {
|
||||
bottomNavAnimator?.expand()
|
||||
// SY -->
|
||||
updateNavMenu(it.menu)
|
||||
binding.bottomNav?.menu?.let { updateNavMenu(it) }
|
||||
// SY <--
|
||||
}
|
||||
bottomViewNavigationBehavior?.slideUp(it)
|
||||
} else {
|
||||
if (collapse) {
|
||||
bottomNavAnimator?.collapse()
|
||||
}
|
||||
|
||||
bottomViewNavigationBehavior?.slideDown(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showSideNav(visible: Boolean) {
|
||||
@ -663,10 +645,11 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
||||
|
||||
binding.bottomNav?.updateLayoutParams<CoordinatorLayout.LayoutParams> {
|
||||
behavior = when {
|
||||
preferences.hideBottomBarOnScroll().get() -> HideBottomViewOnScrollBehavior<View>()
|
||||
preferences.hideBottomBarOnScroll().get() -> HideBottomNavigationOnScrollBehavior()
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
binding.bottomNav?.translationY = 0F
|
||||
}
|
||||
|
||||
private val nav: NavigationBarView
|
||||
|
@ -183,7 +183,7 @@ class UpdatesController :
|
||||
actionMode!!,
|
||||
R.menu.updates_chapter_selection
|
||||
) { onActionItemClicked(it!!) }
|
||||
(activity as? MainActivity)?.showBottomNav(visible = false, collapse = true)
|
||||
(activity as? MainActivity)?.showBottomNav(visible = false, expand = true)
|
||||
}
|
||||
|
||||
toggleSelection(position)
|
||||
@ -389,7 +389,7 @@ class UpdatesController :
|
||||
adapter?.clearSelection()
|
||||
|
||||
binding.actionToolbar.hide()
|
||||
(activity as? MainActivity)?.showBottomNav(visible = true, collapse = true)
|
||||
(activity as? MainActivity)?.showBottomNav(visible = true, expand = true)
|
||||
|
||||
actionMode = null
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.view.ViewCompat
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
|
||||
/**
|
||||
* Hide behavior similar to app bar for [BottomNavigationView]
|
||||
*/
|
||||
class HideBottomNavigationOnScrollBehavior @JvmOverloads constructor(
|
||||
context: Context? = null,
|
||||
attrs: AttributeSet? = null
|
||||
) : CoordinatorLayout.Behavior<BottomNavigationView>(context, attrs) {
|
||||
|
||||
override fun onStartNestedScroll(
|
||||
coordinatorLayout: CoordinatorLayout,
|
||||
child: BottomNavigationView,
|
||||
directTargetChild: View,
|
||||
target: View,
|
||||
axes: Int,
|
||||
type: Int
|
||||
): Boolean {
|
||||
return axes == ViewCompat.SCROLL_AXIS_VERTICAL
|
||||
}
|
||||
|
||||
override fun onNestedPreScroll(
|
||||
coordinatorLayout: CoordinatorLayout,
|
||||
child: BottomNavigationView,
|
||||
target: View,
|
||||
dx: Int,
|
||||
dy: Int,
|
||||
consumed: IntArray,
|
||||
type: Int
|
||||
) {
|
||||
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type)
|
||||
child.translationY = (child.translationY + dy).coerceIn(0F, child.height.toFloat())
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user