diff --git a/app/src/main/kotlin/com/xiaocydx/insets/sample/compat/ImeAnimationCompatActivity.kt b/app/src/main/kotlin/com/xiaocydx/insets/sample/compat/ImeAnimationCompatActivity.kt index 982e237..bb4b751 100644 --- a/app/src/main/kotlin/com/xiaocydx/insets/sample/compat/ImeAnimationCompatActivity.kt +++ b/app/src/main/kotlin/com/xiaocydx/insets/sample/compat/ImeAnimationCompatActivity.kt @@ -39,6 +39,19 @@ class ImeAnimationCompatActivity : AppCompatActivity() { // 该函数能避免跟window.modifyImeAnimation()的实现产生冲突。 window.setWindowInsetsAnimationCallbackCompat( object : WindowInsetsAnimationCompat.Callback(DISPATCH_MODE_STOP) { + override fun onPrepare(animation: WindowInsetsAnimationCompat) { + // 此时未修改animation.durationMillis和animation.interpolator + super.onPrepare(animation) + } + + override fun onStart( + animation: WindowInsetsAnimationCompat, + bounds: WindowInsetsAnimationCompat.BoundsCompat + ): WindowInsetsAnimationCompat.BoundsCompat { + // 此时已修改animation.durationMillis和animation.interpolator + return super.onStart(animation, bounds) + } + override fun onProgress( insets: WindowInsetsCompat, runningAnimations: MutableList diff --git a/insets-compat/src/main/kotlin/com/xiaocydx/insets/compat/InsetsAnimationCompat.kt b/insets-compat/src/main/kotlin/com/xiaocydx/insets/compat/InsetsAnimationCompat.kt index feafb20..b9d6370 100644 --- a/insets-compat/src/main/kotlin/com/xiaocydx/insets/compat/InsetsAnimationCompat.kt +++ b/insets-compat/src/main/kotlin/com/xiaocydx/insets/compat/InsetsAnimationCompat.kt @@ -135,8 +135,7 @@ private class InsetsAnimationCompat private constructor(window: Window) : Window insetsCallback!!.typeMask = typeMask insetsCallback!!.durationMillis = durationMillis insetsCallback!!.interpolator = interpolator - // 对视图树的根View(排除ViewRootImpl)decorView设置insetsCallback, - // 是为了避免WindowInsetsAnimation.Callback分发的过程产生歧义,例如: + // 对decorView设置insetsCallback,是为了避免分发产生歧义: // decorView.setWindowInsetsAnimationCallback(callback) // childView.setWindowInsetsAnimationCallback(insetsCallback) // 1. callback的dispatchMode是DISPATCH_MODE_CONTINUE_ON_SUBTREE。 @@ -220,7 +219,7 @@ private class InsetsAnimationCompat private constructor(window: Window) : Window * * [onStart]修改第4步的[WindowInsetsAnimation],[onDraw]修改第6步构建的属性动画。 * - * 选择在[onDraw]修改第6步构建的属性动画的原因: + * 在[onDraw]修改第6步构建的属性动画的原因: * 最初是在[onStart]修改`InsetsController.SYNC_IME_INTERPOLATOR`,使得第6步获取修改结果构建属性动画, * 但部分设备的`InsetsController.InternalAnimationControlListener.getInsetsInterpolator()`不会获取 * 修改结果构建属性动画,导致`durationMillis`修改成功,`interpolator`修改失败。