Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: race condition in onApplyWindowInsets #277

Merged
merged 3 commits into from
Nov 19, 2023

Conversation

kirillzyusko
Copy link
Owner

@kirillzyusko kirillzyusko commented Nov 17, 2023

📜 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 to onApplyWindowInsets (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

  • added onKeyboardResized method (copied part of body of onApplyWindowInsets);
  • save current ValueAnimator when animation starts;
  • clean (set to null) current animation in doOnEnd;
  • cancel animation if previous one is in progress and onApplyWindowInsets is dispatched;
  • update persistentKeyboardHeight if we cancel animation;

🤔 How Has This Been Tested?

Tested manually on Pixel 7 Pro:

  • API 34 (Android 14);
  • API 31 (Android 12).

📸 Screenshots (if appropriate):

Before After
image image

📝 Checklist

  • CI successfully passed

@kirillzyusko kirillzyusko added 🐛 bug Something isn't working 🤖 android Android specific labels Nov 17, 2023
@kirillzyusko kirillzyusko self-assigned this Nov 17, 2023
Copy link
Contributor

github-actions bot commented Nov 17, 2023

📊 Package size report

Current size Target Size Difference
80164 bytes 79940 bytes 224 bytes 📈

@kirillzyusko kirillzyusko marked this pull request as ready for review November 17, 2023 20:48
@kirillzyusko kirillzyusko merged commit f251c51 into main Nov 19, 2023
@kirillzyusko kirillzyusko deleted the fix/on-apply-window-insets-race-condition branch November 19, 2023 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 android Android specific 🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant