Hide toolbar when scrolling up
parent
6e975b9d66
commit
a7a943c8dc
@ -0,0 +1,22 @@
|
||||
package org.koitharu.kotatsu.core.ui.util
|
||||
|
||||
import android.view.View
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
|
||||
class FadingAppbarHelper(
|
||||
private val target: View
|
||||
) : AppBarLayout.OnOffsetChangedListener {
|
||||
|
||||
fun setup(appBarLayout: AppBarLayout) {
|
||||
appBarLayout.addOnOffsetChangedListener(this)
|
||||
}
|
||||
|
||||
override fun onOffsetChanged(appBarLayout: AppBarLayout?, verticalOffset: Int) {
|
||||
val scrollRange = appBarLayout?.totalScrollRange
|
||||
if (scrollRange == null || scrollRange == 0) {
|
||||
return
|
||||
}
|
||||
|
||||
target.alpha = 1f + verticalOffset / (scrollRange / 2f)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue