fix: race condition in onApplyWindowInsets
#277
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📜 Description
Fixed race condition in
onApplyWindowInsets
.💡 Motivation and Context
A rare case. I've reproduced it when I used
Microsoft SwiftKey Keyboard
.I had a full cycle of
onStart
/onProgress
/onEnd
events (keyboard height was 283). And then two events were dispatched toonApplyWindowInsets
(changing height to 213 and then to 283).With a previous implementation we were running an animation from 283 -> 213 and in parallel from 213 to 283. As a result an animated view was jumpy.
With new implementation we're cancelling our previous animations, so we have monotonic values.
📢 Changelog
Android
onKeyboardResized
method (copied part of body ofonApplyWindowInsets
);ValueAnimator
when animation starts;null
) current animation indoOnEnd
;onApplyWindowInsets
is dispatched;persistentKeyboardHeight
if we cancel animation;🤔 How Has This Been Tested?
Tested manually on Pixel 7 Pro:
📸 Screenshots (if appropriate):
📝 Checklist