2016-05-27 07:21:21 -04:00
|
|
|
package eu.kanade.tachiyomi.widget
|
2016-02-22 16:36:44 -05:00
|
|
|
|
|
|
|
import android.support.design.widget.CoordinatorLayout
|
|
|
|
import android.support.design.widget.FloatingActionButton
|
|
|
|
import android.support.v4.view.ViewCompat
|
|
|
|
import android.view.View
|
|
|
|
|
2016-04-28 15:51:50 -04:00
|
|
|
abstract class FABAnimationBase() : FloatingActionButton.Behavior() {
|
2016-02-22 16:36:44 -05:00
|
|
|
|
2016-04-28 15:51:50 -04:00
|
|
|
var isAnimatingOut = false
|
|
|
|
|
|
|
|
override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout, child: FloatingActionButton,
|
|
|
|
directTargetChild: View, target: View, nestedScrollAxes: Int): Boolean {
|
2016-02-22 16:36:44 -05:00
|
|
|
// Ensure we react to vertical scrolling
|
|
|
|
return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL ||
|
|
|
|
super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes)
|
|
|
|
}
|
|
|
|
|
2016-04-28 15:51:50 -04:00
|
|
|
override fun onNestedScroll(coordinatorLayout: CoordinatorLayout, child: FloatingActionButton, target: View,
|
|
|
|
dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int) {
|
2016-02-22 16:36:44 -05:00
|
|
|
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed)
|
2016-04-28 15:51:50 -04:00
|
|
|
if (dyConsumed > 0 && !isAnimatingOut && child.visibility == View.VISIBLE) {
|
2016-02-22 16:36:44 -05:00
|
|
|
// User scrolled down and the FAB is currently visible -> hide the FAB
|
|
|
|
animateOut(child)
|
2016-04-28 15:51:50 -04:00
|
|
|
} else if (dyConsumed < 0 && child.visibility != View.VISIBLE) {
|
2016-02-22 16:36:44 -05:00
|
|
|
// User scrolled up and the FAB is currently not visible -> show the FAB
|
|
|
|
animateIn(child)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 15:51:50 -04:00
|
|
|
abstract fun animateOut(button: FloatingActionButton)
|
|
|
|
abstract fun animateIn(button: FloatingActionButton)
|
2016-02-22 16:36:44 -05:00
|
|
|
}
|