Skip to content

Instantly share code, notes, and snippets.

@ValCanBuild
Created March 14, 2018 05:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ValCanBuild/ef48279bb9e3fa8fb04d84a49247eaf4 to your computer and use it in GitHub Desktop.
Save ValCanBuild/ef48279bb9e3fa8fb04d84a49247eaf4 to your computer and use it in GitHub Desktop.
BottomNavigationView Behavior - no snackbar support
class BottomNavigationBehavior<V : View>(context: Context, attrs: AttributeSet) :
CoordinatorLayout.Behavior<V>(context, attrs) {
override fun onStartNestedScroll(
coordinatorLayout: CoordinatorLayout, child: V, directTargetChild: View, target: View, axes: Int, type: Int
): Boolean {
return axes == ViewCompat.SCROLL_AXIS_VERTICAL
}
override fun onNestedPreScroll(
coordinatorLayout: CoordinatorLayout, child: V, target: View, dx: Int, dy: Int, consumed: IntArray, type: Int
) {
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type)
child.translationY = max(0f, min(child.height.toFloat(), child.translationY + dy))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment