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