Skip to content

Instantly share code, notes, and snippets.

@sajjadjaved01
Created January 8, 2020 14:40
Show Gist options
  • Save sajjadjaved01/2b98d613e65b76a9386c5feb5079235a to your computer and use it in GitHub Desktop.
Save sajjadjaved01/2b98d613e65b76a9386c5feb5079235a to your computer and use it in GitHub Desktop.
Android Animation using AndroidX Transition API.
/* usage fabMessages.toggle(Slide(Gravity.Bottom)) : Slide() & Fade() */
fun View.toggle(transition: Transition) {
transition.duration = 500
transition.addTarget(this)
TransitionManager.beginDelayedTransition(this.parent as ViewGroup, transition)
visibility = if (!isVisible) View.VISIBLE else View.GONE
}
// Usage extend any of your view with toggle, like (Button, FabButton, etc).
// use views Id.
// There are Two types of Transhions. (Fade(), Slide())
// Gravity is where do you want it to slide from.
fabMessages.toggle(Slide(Gravity.Bottom))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment