Created
March 22, 2023 08:36
-
-
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.
This file contains 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
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