2018-12-10 08:38:03 -08:00
|
|
|
package cash.z.android.wallet.ui.view
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.util.AttributeSet
|
2019-02-07 19:18:32 -08:00
|
|
|
import android.util.Log
|
2018-12-10 08:38:03 -08:00
|
|
|
import androidx.constraintlayout.motion.widget.MotionLayout
|
|
|
|
import com.google.android.material.appbar.AppBarLayout
|
|
|
|
|
|
|
|
class CollapsingMotionToolbar @JvmOverloads constructor(
|
|
|
|
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
|
|
|
) : MotionLayout(context, attrs, defStyleAttr), AppBarLayout.OnOffsetChangedListener {
|
|
|
|
|
|
|
|
override fun onOffsetChanged(appBarLayout: AppBarLayout, verticalOffset: Int) {
|
|
|
|
progress = -verticalOffset / appBarLayout.totalScrollRange.toFloat()
|
2019-02-07 19:18:32 -08:00
|
|
|
Log.e("MotionL", "progress: $progress verticalOffset: $verticalOffset scrollRange: ${appBarLayout.totalScrollRange.toFloat()}")
|
2018-12-10 08:38:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow()
|
|
|
|
(parent as? AppBarLayout)?.let { appBarLayout ->
|
|
|
|
// appBarLayout.removeOnOffsetChangedListener(this)
|
|
|
|
appBarLayout.addOnOffsetChangedListener(this)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|