Closed erleizh closed 2 years ago
class FixTranslateDeferringInsetsAnimationCallback(
private val proxy: WindowInsetsAnimationCompat.Callback,
private val deferredInsetTypes: Int,
dispatchMode: Int = DISPATCH_MODE_STOP
) : WindowInsetsAnimationCompat.Callback(dispatchMode) {
private var typeMask = -1
override fun onProgress(insets: WindowInsetsCompat, runningAnimations: MutableList<WindowInsetsAnimationCompat>): WindowInsetsCompat {
runningAnimations.find { it.typeMask == typeMask }?.let {
proxy.onProgress(insets, runningAnimations)
}
return insets
}
override fun onPrepare(animation: WindowInsetsAnimationCompat) {
super.onPrepare(animation)
if (typeMask == -1 && animation.typeMask and deferredInsetTypes != 0) {
typeMask = animation.typeMask
proxy.onPrepare(animation)
}
}
override fun onStart(animation: WindowInsetsAnimationCompat, bounds: WindowInsetsAnimationCompat.BoundsCompat): WindowInsetsAnimationCompat.BoundsCompat {
if (typeMask == animation.typeMask) {
return proxy.onStart(animation, bounds)
}
return super.onStart(animation, bounds)
}
override fun onEnd(animation: WindowInsetsAnimationCompat) {
super.onEnd(animation)
if (typeMask == animation.typeMask) {
proxy.onEnd(animation)
typeMask = -1
}
}
}
https://user-images.githubusercontent.com/15859155/153391289-8767f5c4-401f-401e-83e9-b0497a863e2b.mp4