Skip to content

Instantly share code, notes, and snippets.

@ValCanBuild
Last active November 27, 2019 17:47
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/381b77eb86c35a726632e1390f2f87eb to your computer and use it in GitHub Desktop.
Save ValCanBuild/381b77eb86c35a726632e1390f2f87eb to your computer and use it in GitHub Desktop.
class BottomNavigationFABBehavior(context: Context?, attrs: AttributeSet?) : CoordinatorLayout.Behavior<View>(context, attrs) {
override fun layoutDependsOn(parent: CoordinatorLayout, child: View, dependency: View): Boolean {
return dependency is Snackbar.SnackbarLayout
}
override fun onDependentViewRemoved(parent: CoordinatorLayout, child: View, dependency: View) {
child.translationY = 0f
}
override fun onDependentViewChanged(parent: CoordinatorLayout, child: View, dependency: View): Boolean {
return updateButton(child, dependency)
}
private fun updateButton(child: View, dependency: View): Boolean {
if (dependency is Snackbar.SnackbarLayout) {
val oldTranslation = child.translationY
val height = dependency.height.toFloat()
val newTranslation = dependency.translationY - height
child.translationY = newTranslation
return oldTranslation != newTranslation
}
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment