Prevent insets switch during IME predictive back animation...
...when app has animation callback registered
This CL changes an important aspect of the IME predictive back
animation: When the app has an animation callback registered, insets are
now HIDDEN from the start of the predictive back animation, instead of
remaining as SHOWN during the precommit phase and switching to HIDDEN as
soon as the back gesture is committed.
The reason for this change is to be compatible with apps that are
following the official documentation at
https://developer.android.com/develop/ui/views/layout/sw-keyboard to
animate app content in sync with the IME. The official documentation
states that insets always switch at the beginning of the animation
(between onPrepare and onStart of WindowInsetsAnimation.Callback). This
needs to be valid for IME predictive back too, otherwise some apps
animation logic might break.
Here's a brief explanation of the changes in this CL:
1. The custom handling for ime-predictive-back in
InsetsController#getLayoutInsetsDuringAnimationMode is only applied if
there is no animation callback registered.
2. We must prevent ViewRootImpl from moving app content back to it's
original position at the start of the back gesture in the adjust_pan
case. The pan is controlled by ImeBackAnimationController instead.
When the refactor_insets_controller flag is enabled, these two changes
would already be sufficient. For the case of that flag not being
enabled, two additional targeted fixes are necessary:
1. In InsetsController#collectSourceControls, we want to treat the
ime-predictive-back case (with animation-callback) as a hide request
instead of a show request. Without that change, starting a
predictive-back gesture while the IME is still animating in doesn't work
properly.
2. In ImeInsetsSourceConsumer it needs to be ensured that the insets are
reported as changed after a predictive back gesture is cancelled and the
IME was animated back to its shown position. Without that change, there
would be a flicker in that case.
Bug: 359175310
Test: Manual, i.e. extensive manual testing with refactor_insets_controller flag enabled and disabled in different apps (ChatActivity test app, Instagram, Launcher all apps, Settings, Google Keep etc.) and various use cases (animation interruptions, quick refocusing, quick rehiding etc.)
Test: ImeBackAnimationControllerTest, InsetsControllerTest
Flag: android.view.inputmethod.predictive_back_ime
Change-Id: I288c7acadb12f84394f8a64b3b0a7898fde3ab7e
6 files changed