Last active
January 17, 2020 11:48
-
-
Save nikhilpanju/0013aa253c50b23b6c0be802e93eec24 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ToolbarBehavior : CoordinatorLayout.Behavior<AppBarLayout>() { | |
/** Consume if vertical scroll because we don't care about other scrolls */ | |
override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout, child: AppBarLayout, | |
directTargetChild: View, target: View, axes: Int, type: Int): Boolean { | |
getViews(child) | |
return axes == ViewCompat.SCROLL_AXIS_VERTICAL || | |
super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, axes, type) | |
} | |
/** Perform actual animation by determining the dY amount */ | |
override fun onNestedScroll(coordinatorLayout: CoordinatorLayout, child: AppBarLayout, target: View, | |
dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, | |
type: Int, consumed: IntArray) { | |
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, | |
dyConsumed, dxUnconsumed, dyUnconsumed, type, consumed) | |
getViews(child) | |
if (dyConsumed > 0) { | |
// RecyclerView is scrolling down so shrink toolbar and translate | |
// drawerIcon using the dyConsumed variable | |
} else if (dyUnconsumed < 0) { | |
// RecyclerView has reached the top and user is scrolling up more to reveal toolbar | |
// So use the dyUnconsumed variable to bring back the toolbar to resting position | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment