2019-07-28 02:10:22 -07:00
|
|
|
package com.topjohnwu.magisk.extensions
|
2019-05-06 19:03:28 +02:00
|
|
|
|
|
|
|
import android.view.View
|
2019-10-20 11:14:49 +02:00
|
|
|
import android.view.ViewGroup
|
2019-05-06 19:03:28 +02:00
|
|
|
import android.view.ViewTreeObserver
|
2019-10-20 11:14:49 +02:00
|
|
|
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
|
|
|
import androidx.transition.AutoTransition
|
|
|
|
import androidx.transition.TransitionManager
|
2019-05-06 19:03:28 +02:00
|
|
|
|
|
|
|
fun View.setOnViewReadyListener(callback: () -> Unit) = addOnGlobalLayoutListener(true, callback)
|
|
|
|
|
|
|
|
fun View.addOnGlobalLayoutListener(oneShot: Boolean = false, callback: () -> Unit) =
|
|
|
|
viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
|
|
|
override fun onGlobalLayout() {
|
|
|
|
if (oneShot) viewTreeObserver.removeOnGlobalLayoutListener(this)
|
|
|
|
callback()
|
|
|
|
}
|
2019-10-20 11:14:49 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
fun ViewGroup.startAnimations() {
|
2019-10-29 16:52:42 +01:00
|
|
|
val transition = AutoTransition().setInterpolator(FastOutSlowInInterpolator()).setDuration(400)
|
2019-10-20 11:14:49 +02:00
|
|
|
TransitionManager.beginDelayedTransition(this, transition)
|
|
|
|
}
|