Skip to content

Instantly share code, notes, and snippets.

@prabhatsdp
Created March 22, 2023 08:36
Show Gist options
  • Save prabhatsdp/27f5a671536dd156798e523fb6e0ee9a to your computer and use it in GitHub Desktop.
Save prabhatsdp/27f5a671536dd156798e523fb6e0ee9a to your computer and use it in GitHub Desktop.
View visibility change with transition. It uses TransitionManger.beginDelayedTransition to acheive the transition.
package dev.prabhatpandey.android.utils
import android.transition.ChangeBounds
import android.transition.Fade
import android.transition.Transition
import android.transition.TransitionManager
import android.transition.TransitionSet
import android.view.View
import android.view.ViewGroup
/**
* By default uses expand with fade in
*/
fun View.showWithTransition(
transition: Transition = TransitionSet().apply {
addTransition(ChangeBounds())
addTransition(Fade(Fade.IN))
}
) {
TransitionManager.beginDelayedTransition(
this.parent as ViewGroup,
transition
)
this.visibility = View.VISIBLE
}
/**
* By default uses collapse transition with fade out
*/
fun View.hideWithTransition(
transition: Transition = TransitionSet().apply {
addTransition(ChangeBounds())
addTransition(Fade(Fade.OUT))
}
) {
TransitionManager.beginDelayedTransition(
this.parent as ViewGroup,
transition
)
this.visibility = View.GONE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment