Hiding blocking bottom view on scroll + appbar/bottombar snap together

just as a reminder bottom view is the view under bottom nav to block touches while bottom nav is showwing
This commit is contained in:
Jays2Kings 2021-03-26 00:10:06 -04:00
parent 0bb399979f
commit 003c6ed255
2 changed files with 33 additions and 22 deletions

View File

@ -250,6 +250,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
} }
bottom_nav.visibleIf(!hideBottomNav) bottom_nav.visibleIf(!hideBottomNav)
bottom_view.visibility = if (hideBottomNav) View.GONE else bottom_view.visibility
bottom_nav.alpha = if (hideBottomNav) 0f else 1f bottom_nav.alpha = if (hideBottomNav) 0f else 1f
router.addChangeListener( router.addChangeListener(
object : ControllerChangeHandler.ControllerChangeListener { object : ControllerChangeHandler.ControllerChangeListener {
@ -625,7 +626,8 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
} }
alphaAnimation.addListener( alphaAnimation.addListener(
EndAnimatorListener { EndAnimatorListener {
bottom_nav.visibility = if (hideBottomNav) View.GONE else View.VISIBLE bottom_nav.visibleIf(!hideBottomNav)
bottom_view.visibility = if (hideBottomNav) View.GONE else bottom_view.visibility
} }
) )
alphaAnimation.duration = 200 alphaAnimation.duration = 200

View File

@ -15,6 +15,7 @@ import androidx.appcompat.widget.SearchView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.math.MathUtils import androidx.core.math.MathUtils
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
@ -123,8 +124,12 @@ fun Controller.scrollViewWith(
recycler.requestApplyInsets() recycler.requestApplyInsets()
} }
} }
recycler.post { val updateViewsNearBottom = {
onBottomNavUpdate?.invoke() onBottomNavUpdate?.invoke()
activity?.bottom_view?.translationY = activity?.bottom_nav?.translationY ?: 0f
}
recycler.post {
updateViewsNearBottom()
} }
val randomTag = Random.nextLong() val randomTag = Random.nextLong()
var lastY = 0f var lastY = 0f
@ -248,13 +253,15 @@ fun Controller.scrollViewWith(
activity!!.appbar.animate().y(0f) activity!!.appbar.animate().y(0f)
.setDuration(shortAnimationDuration.toLong()) .setDuration(shortAnimationDuration.toLong())
.start() .start()
activity!!.bottom_nav?.let { if (router.backstackSize == 1) {
val animator = it.animate()?.translationY(0f) activity!!.bottom_nav?.let {
?.setDuration(shortAnimationDuration.toLong()) val animator = it.animate()?.translationY(0f)
animator?.setUpdateListener { ?.setDuration(shortAnimationDuration.toLong())
onBottomNavUpdate?.invoke() animator?.setUpdateListener {
updateViewsNearBottom()
}
animator?.start()
} }
animator?.start()
} }
lastY = 0f lastY = 0f
if (elevate) elevateFunc(false) if (elevate) elevateFunc(false)
@ -275,8 +282,7 @@ fun Controller.scrollViewWith(
0f, 0f,
tabBar.height.toFloat() tabBar.height.toFloat()
) )
activity!!.bottom_view?.translationY = tabBar.translationY updateViewsNearBottom()
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
@ -305,24 +311,27 @@ fun Controller.scrollViewWith(
activity != null && activity!!.appbar.height > 0 && activity != null && activity!!.appbar.height > 0 &&
recycler.translationY == 0f recycler.translationY == 0f
) { ) {
val halfWay = abs((-activity!!.appbar.height.toFloat()) / 2) val halfWay = activity!!.appbar.height.toFloat() / 2
val shortAnimationDuration = resources?.getInteger( val shortAnimationDuration = resources?.getInteger(
android.R.integer.config_shortAnimTime android.R.integer.config_shortAnimTime
) ?: 0 ) ?: 0
val closerToTop = abs(activity!!.appbar.y) - halfWay > 0 val closerToTop = abs(activity!!.appbar.y) > halfWay
val halfWayBottom = activity!!.bottom_nav.height.toFloat() / 2
val closerToBottom = activity!!.bottom_nav.translationY > halfWayBottom
val atTop = !recycler.canScrollVertically(-1) val atTop = !recycler.canScrollVertically(-1)
lastY = if (closerToTop && !atTop) (-activity!!.appbar.height.toFloat()) else 0f val closerToEdge = if (activity!!.bottom_nav.isVisible) closerToBottom else closerToTop
lastY = if (closerToEdge && !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 { if (activity!!.bottom_nav.isVisible) {
val halfWayBottom = abs((it.height.toFloat()) / 2) activity!!.bottom_nav?.let {
val closerToBottom = it.translationY > halfWayBottom val lastBottomY = if (closerToEdge && !atTop) it.height.toFloat() else 0f
val lastBottomY = if (closerToBottom && !atTop) it.height.toFloat() else 0f val animator = it.animate()?.translationY(lastBottomY)
val animator = it.animate()?.translationY(lastBottomY) ?.setDuration(shortAnimationDuration.toLong())
?.setDuration(shortAnimationDuration.toLong()) animator?.setUpdateListener {
animator?.setUpdateListener { updateViewsNearBottom()
onBottomNavUpdate?.invoke() }
animator?.start()
} }
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)