diff options
| author | Jorim Jaggi <jjaggi@google.com> | 2020-03-20 23:46:38 +0100 |
|---|---|---|
| committer | Jorim Jaggi <jjaggi@google.com> | 2020-03-24 21:25:46 +0100 |
| commit | 2751c29414d17650b1737e19c250ffbe4f266b82 (patch) | |
| tree | 27a74ef73d27a709d50a6910638567b3c0ce5741 /core/java/android/view/InsetsSourceConsumer.java | |
| parent | 5bd455ac5f0f09280ae59e3eeb74ea7e3b7e4823 (diff) | |
Defer updating InsetsSource.mFrame while animating
...otherwise developer will get onApplyWindowInsets which don't
match end value of animation. Super confusing
Test: InsetsControllerTest
Bug: 152071027
Change-Id: Ic1819512a5ce78843433bf7c231d062e12de0e7b
Diffstat (limited to 'core/java/android/view/InsetsSourceConsumer.java')
| -rw-r--r-- | core/java/android/view/InsetsSourceConsumer.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/core/java/android/view/InsetsSourceConsumer.java b/core/java/android/view/InsetsSourceConsumer.java index 332573449e18..f36621c0a49e 100644 --- a/core/java/android/view/InsetsSourceConsumer.java +++ b/core/java/android/view/InsetsSourceConsumer.java @@ -16,11 +16,13 @@ package android.view; +import static android.view.InsetsController.ANIMATION_TYPE_NONE; import static android.view.InsetsController.AnimationType; import static android.view.InsetsState.toPublicType; import android.annotation.IntDef; import android.annotation.Nullable; +import android.graphics.Rect; import android.view.InsetsState.InternalInsetsType; import android.view.SurfaceControl.Transaction; import android.view.WindowInsets.Type.InsetsType; @@ -64,6 +66,8 @@ public class InsetsSourceConsumer { private final Supplier<Transaction> mTransactionSupplier; private @Nullable InsetsSourceControl mSourceControl; private boolean mHasWindowFocus; + private Rect mPendingFrame; + private Rect mPendingVisibleFrame; public InsetsSourceConsumer(@InternalInsetsType int type, InsetsState state, Supplier<Transaction> transactionSupplier, InsetsController controller) { @@ -215,6 +219,38 @@ public class InsetsSourceConsumer { // no-op for types that always return ShowResult#SHOW_IMMEDIATELY. } + void updateSource(InsetsSource newSource) { + InsetsSource source = mState.peekSource(mType); + if (source == null || mController.getAnimationType(mType) == ANIMATION_TYPE_NONE + || source.getFrame().equals(newSource.getFrame())) { + mState.addSource(newSource); + return; + } + + // Frame is changing while animating. Keep note of the new frame but keep existing frame + // until animaition is finished. + newSource = new InsetsSource(newSource); + mPendingFrame = new Rect(newSource.getFrame()); + mPendingVisibleFrame = newSource.getVisibleFrame() != null + ? new Rect(newSource.getVisibleFrame()) + : null; + newSource.setFrame(source.getFrame()); + newSource.setVisibleFrame(source.getVisibleFrame()); + mState.addSource(newSource); + } + + boolean notifyAnimationFinished() { + if (mPendingFrame != null) { + InsetsSource source = mState.getSource(mType); + source.setFrame(mPendingFrame); + source.setVisibleFrame(mPendingVisibleFrame); + mPendingFrame = null; + mPendingVisibleFrame = null; + return true; + } + return false; + } + /** * Sets requested visibility from the client, regardless of whether we are able to control it at * the moment. |
