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!!,
|
actionMode!!,
|
||||||
R.menu.library_selection
|
R.menu.library_selection
|
||||||
) { onActionItemClicked(it!!) }
|
) { 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())
|
selectionRelay.call(LibrarySelectionEvent.Cleared())
|
||||||
|
|
||||||
binding.actionToolbar.hide()
|
binding.actionToolbar.hide()
|
||||||
(activity as? MainActivity)?.showBottomNav(visible = true, collapse = true)
|
(activity as? MainActivity)?.showBottomNav(visible = true, expand = true)
|
||||||
|
|
||||||
actionMode = null
|
actionMode = null
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ import com.bluelinelabs.conductor.Controller
|
|||||||
import com.bluelinelabs.conductor.ControllerChangeHandler
|
import com.bluelinelabs.conductor.ControllerChangeHandler
|
||||||
import com.bluelinelabs.conductor.Router
|
import com.bluelinelabs.conductor.Router
|
||||||
import com.google.android.material.appbar.AppBarLayout
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior
|
|
||||||
import com.google.android.material.navigation.NavigationBarView
|
import com.google.android.material.navigation.NavigationBarView
|
||||||
import dev.chrisbanes.insetter.applyInsetter
|
import dev.chrisbanes.insetter.applyInsetter
|
||||||
import eu.kanade.tachiyomi.R
|
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.dpToPx
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import eu.kanade.tachiyomi.util.view.setNavigationBarTransparentCompat
|
import eu.kanade.tachiyomi.util.view.setNavigationBarTransparentCompat
|
||||||
|
import eu.kanade.tachiyomi.widget.HideBottomNavigationOnScrollBehavior
|
||||||
import exh.EXHMigrations
|
import exh.EXHMigrations
|
||||||
import exh.eh.EHentaiUpdateWorker
|
import exh.eh.EHentaiUpdateWorker
|
||||||
import exh.source.BlacklistedSources
|
import exh.source.BlacklistedSources
|
||||||
@ -168,15 +168,6 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
|||||||
if (binding.bottomNav != null) {
|
if (binding.bottomNav != null) {
|
||||||
bottomNavAnimator = ViewHeightAnimator(binding.bottomNav!!)
|
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
|
// Set behavior of bottom nav
|
||||||
preferences.hideBottomBarOnScroll()
|
preferences.hideBottomBarOnScroll()
|
||||||
.asImmediateFlow { setBottomNavBehaviorOnScroll() }
|
.asImmediateFlow { setBottomNavBehaviorOnScroll() }
|
||||||
@ -555,11 +546,11 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
|||||||
binding.appbar.setExpanded(true)
|
binding.appbar.setExpanded(true)
|
||||||
|
|
||||||
if ((from == null || from is RootController) && to !is RootController) {
|
if ((from == null || from is RootController) && to !is RootController) {
|
||||||
showNav(visible = false, collapse = true)
|
showNav(visible = false, expand = true)
|
||||||
}
|
}
|
||||||
if (to is RootController) {
|
if (to is RootController) {
|
||||||
// Always show bottom nav again when returning to a 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) {
|
if (from is TabbedController) {
|
||||||
@ -595,32 +586,23 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showNav(visible: Boolean, collapse: Boolean = false) {
|
private fun showNav(visible: Boolean, expand: Boolean = false) {
|
||||||
showBottomNav(visible, collapse)
|
showBottomNav(visible, expand)
|
||||||
showSideNav(visible)
|
showSideNav(visible)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also used from some controllers to swap bottom nav with action toolbar
|
// Also used from some controllers to swap bottom nav with action toolbar
|
||||||
fun showBottomNav(visible: Boolean, collapse: Boolean = false) {
|
fun showBottomNav(visible: Boolean, expand: Boolean = false) {
|
||||||
binding.bottomNav?.let {
|
if (visible) {
|
||||||
val layoutParams = it.layoutParams as CoordinatorLayout.LayoutParams
|
binding.bottomNav?.translationY = 0F
|
||||||
val bottomViewNavigationBehavior =
|
if (expand) {
|
||||||
layoutParams.behavior as? HideBottomViewOnScrollBehavior
|
bottomNavAnimator?.expand()
|
||||||
if (visible) {
|
// SY -->
|
||||||
if (collapse) {
|
binding.bottomNav?.menu?.let { updateNavMenu(it) }
|
||||||
bottomNavAnimator?.expand()
|
// SY <--
|
||||||
// SY -->
|
|
||||||
updateNavMenu(it.menu)
|
|
||||||
// SY <--
|
|
||||||
}
|
|
||||||
bottomViewNavigationBehavior?.slideUp(it)
|
|
||||||
} else {
|
|
||||||
if (collapse) {
|
|
||||||
bottomNavAnimator?.collapse()
|
|
||||||
}
|
|
||||||
|
|
||||||
bottomViewNavigationBehavior?.slideDown(it)
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
bottomNavAnimator?.collapse()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -663,10 +645,11 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
|||||||
|
|
||||||
binding.bottomNav?.updateLayoutParams<CoordinatorLayout.LayoutParams> {
|
binding.bottomNav?.updateLayoutParams<CoordinatorLayout.LayoutParams> {
|
||||||
behavior = when {
|
behavior = when {
|
||||||
preferences.hideBottomBarOnScroll().get() -> HideBottomViewOnScrollBehavior<View>()
|
preferences.hideBottomBarOnScroll().get() -> HideBottomNavigationOnScrollBehavior()
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
binding.bottomNav?.translationY = 0F
|
||||||
}
|
}
|
||||||
|
|
||||||
private val nav: NavigationBarView
|
private val nav: NavigationBarView
|
||||||
|
@ -183,7 +183,7 @@ class UpdatesController :
|
|||||||
actionMode!!,
|
actionMode!!,
|
||||||
R.menu.updates_chapter_selection
|
R.menu.updates_chapter_selection
|
||||||
) { onActionItemClicked(it!!) }
|
) { onActionItemClicked(it!!) }
|
||||||
(activity as? MainActivity)?.showBottomNav(visible = false, collapse = true)
|
(activity as? MainActivity)?.showBottomNav(visible = false, expand = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleSelection(position)
|
toggleSelection(position)
|
||||||
@ -389,7 +389,7 @@ class UpdatesController :
|
|||||||
adapter?.clearSelection()
|
adapter?.clearSelection()
|
||||||
|
|
||||||
binding.actionToolbar.hide()
|
binding.actionToolbar.hide()
|
||||||
(activity as? MainActivity)?.showBottomNav(visible = true, collapse = true)
|
(activity as? MainActivity)?.showBottomNav(visible = true, expand = true)
|
||||||
|
|
||||||
actionMode = null
|
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