mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 17:41:50 +01:00
Bottom nav now snaps to bottom or top after scroll
This commit is contained in:
parent
b7eebcef53
commit
d9d6d4ed29
@ -235,7 +235,6 @@ class LibraryController(
|
||||
showCategoryText(currentCategory.name)
|
||||
}
|
||||
}
|
||||
updateFilterSheetY()
|
||||
val savedCurrentCategory = getHeader(true)?.category ?: return
|
||||
if (savedCurrentCategory.order != lastUsedCategory) {
|
||||
lastUsedCategory = savedCurrentCategory.order
|
||||
@ -252,7 +251,6 @@ class LibraryController(
|
||||
}
|
||||
RecyclerView.SCROLL_STATE_IDLE -> {
|
||||
updateHopperPosition()
|
||||
updateFilterSheetY()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -262,7 +260,6 @@ class LibraryController(
|
||||
val bottomBar = activity?.bottom_nav
|
||||
filter_bottom_sheet ?: return
|
||||
if (bottomBar != null) {
|
||||
updateHopperY()
|
||||
if (filter_bottom_sheet.sheetBehavior.isHidden()) {
|
||||
val pad = bottomBar.translationY - bottomBar.height
|
||||
filter_bottom_sheet.translationY = pad
|
||||
@ -283,6 +280,7 @@ class LibraryController(
|
||||
view?.rootWindowInsets?.getBottomGestureInsets() ?: 0
|
||||
)
|
||||
filter_bottom_sheet.sheetBehavior?.peekHeight = 60.dpToPx + padding
|
||||
updateHopperY()
|
||||
fast_scroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = -pad.toInt()
|
||||
}
|
||||
@ -387,9 +385,6 @@ class LibraryController(
|
||||
|
||||
adapter = LibraryCategoryAdapter(this)
|
||||
setRecyclerLayout()
|
||||
recycler.post {
|
||||
updateFilterSheetY()
|
||||
}
|
||||
|
||||
recycler.manager.spanSizeLookup = (
|
||||
object : GridLayoutManager.SpanSizeLookup() {
|
||||
@ -442,6 +437,9 @@ class LibraryController(
|
||||
},
|
||||
onLeavingController = {
|
||||
header_title?.gone()
|
||||
},
|
||||
onBottomNavUpdate = {
|
||||
updateFilterSheetY()
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -134,6 +134,9 @@ class RecentsController(bundle: Bundle? = null) :
|
||||
afterInsets = {
|
||||
headerHeight = it.systemWindowInsetTop + appBarHeight
|
||||
recycler.updatePaddingRelative(bottom = activity!!.bottom_nav.height)
|
||||
},
|
||||
onBottomNavUpdate = {
|
||||
setBottomPadding()
|
||||
}
|
||||
)
|
||||
|
||||
@ -144,17 +147,6 @@ class RecentsController(bundle: Bundle? = null) :
|
||||
adapter.addScrollableHeader(presenter.generalHeader)
|
||||
}
|
||||
}
|
||||
recycler?.post {
|
||||
setBottomPadding()
|
||||
}
|
||||
recycler.addOnScrollListener(
|
||||
object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
setBottomPadding()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
dl_bottom_sheet.onCreate(this)
|
||||
|
||||
|
@ -13,7 +13,6 @@ import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bluelinelabs.conductor.ControllerChangeHandler
|
||||
import com.bluelinelabs.conductor.ControllerChangeType
|
||||
import com.bluelinelabs.conductor.RouterTransaction
|
||||
@ -153,21 +152,15 @@ class SourceController :
|
||||
afterInsets = {
|
||||
headerHeight = it.systemWindowInsetTop + appBarHeight
|
||||
recycler.updatePaddingRelative(bottom = activity?.bottom_nav?.height ?: 0)
|
||||
},
|
||||
onBottomNavUpdate = {
|
||||
setBottomPadding()
|
||||
}
|
||||
)
|
||||
|
||||
recycler?.post {
|
||||
setBottomPadding()
|
||||
setBottomSheetTabs(if (ext_bottom_sheet?.sheetBehavior.isCollapsed()) 0f else 1f)
|
||||
}
|
||||
recycler.addOnScrollListener(
|
||||
object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
setBottomPadding()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
requestPermissionsSafe(arrayOf(WRITE_EXTERNAL_STORAGE), 301)
|
||||
ext_bottom_sheet.onCreate(this)
|
||||
@ -230,7 +223,6 @@ class SourceController :
|
||||
|
||||
fun setBottomSheetTabs(progress: Float) {
|
||||
val bottomSheet = ext_bottom_sheet ?: return
|
||||
val bottomBar = activity?.bottom_nav ?: return
|
||||
ext_bottom_sheet.tabs.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
topMargin = ((activity?.appbar?.height?.minus(9f.dpToPx) ?: 0f) * progress).toInt()
|
||||
}
|
||||
|
@ -104,7 +104,8 @@ fun Controller.scrollViewWith(
|
||||
swipeRefreshLayout: SwipeRefreshLayout? = null,
|
||||
afterInsets: ((WindowInsets) -> Unit)? = null,
|
||||
liftOnScroll: ((Boolean) -> Unit)? = null,
|
||||
onLeavingController: (() -> Unit)? = null
|
||||
onLeavingController: (() -> Unit)? = null,
|
||||
onBottomNavUpdate: (() -> Unit)? = null
|
||||
): ((Boolean) -> Unit) {
|
||||
var statusBarHeight = -1
|
||||
activity?.appbar?.y = 0f
|
||||
@ -120,6 +121,9 @@ fun Controller.scrollViewWith(
|
||||
recycler.requestApplyInsets()
|
||||
}
|
||||
}
|
||||
recycler.post {
|
||||
onBottomNavUpdate?.invoke()
|
||||
}
|
||||
val randomTag = Random.nextLong()
|
||||
var lastY = 0f
|
||||
var fakeToolbarView: View? = null
|
||||
@ -219,10 +223,17 @@ fun Controller.scrollViewWith(
|
||||
val shortAnimationDuration = resources?.getInteger(
|
||||
android.R.integer.config_shortAnimTime
|
||||
) ?: 0
|
||||
activity!!.appbar.animate().y(0f).setDuration(shortAnimationDuration.toLong())
|
||||
activity!!.appbar.animate().y(0f)
|
||||
.setDuration(shortAnimationDuration.toLong())
|
||||
.start()
|
||||
activity!!.bottom_nav?.animate()?.translationYBy(0f)?.setDuration(shortAnimationDuration.toLong())
|
||||
?.start()
|
||||
activity!!.bottom_nav?.let {
|
||||
val animator = it.animate()?.translationY(0f)
|
||||
?.setDuration(shortAnimationDuration.toLong())
|
||||
animator?.setUpdateListener {
|
||||
onBottomNavUpdate?.invoke()
|
||||
}
|
||||
animator?.start()
|
||||
}
|
||||
lastY = 0f
|
||||
if (elevate) elevateFunc(false)
|
||||
} else {
|
||||
@ -243,6 +254,7 @@ fun Controller.scrollViewWith(
|
||||
tabBar.height.toFloat()
|
||||
)
|
||||
activity!!.bottom_view?.translationY = tabBar.translationY
|
||||
onBottomNavUpdate?.invoke()
|
||||
} else if (tabBar.translationY != 0f) {
|
||||
tabBar.translationY = 0f
|
||||
activity!!.bottom_view?.translationY = 0f
|
||||
@ -279,6 +291,17 @@ fun Controller.scrollViewWith(
|
||||
val atTop = !recycler.canScrollVertically(-1)
|
||||
lastY = if (closerToTop && !atTop) (-activity!!.appbar.height.toFloat()) else 0f
|
||||
activity!!.appbar.animate().y(lastY).setDuration(shortAnimationDuration.toLong()).start()
|
||||
activity!!.bottom_nav?.let {
|
||||
val halfWayBottom = abs((it.height.toFloat()) / 2)
|
||||
val closerToBottom = it.translationY > halfWayBottom
|
||||
val lastBottomY = if (closerToBottom && !atTop) it.height.toFloat() else 0f
|
||||
val animator = it.animate()?.translationY(lastBottomY)
|
||||
?.setDuration(shortAnimationDuration.toLong())
|
||||
animator?.setUpdateListener {
|
||||
onBottomNavUpdate?.invoke()
|
||||
}
|
||||
animator?.start()
|
||||
}
|
||||
if (recycler.canScrollVertically(-1) && !elevate) elevateFunc(true)
|
||||
else if (!recycler.canScrollVertically(-1) && elevate) elevateFunc(false)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user