fix(android): prevent useAnimatedKeyboard crash "Can't change insets on an animation that is cancelled"#9670
Open
piaskowyk wants to merge 1 commit into
Open
fix(android): prevent useAnimatedKeyboard crash "Can't change insets on an animation that is cancelled"#9670piaskowyk wants to merge 1 commit into
useAnimatedKeyboard crash "Can't change insets on an animation that is cancelled"#9670piaskowyk wants to merge 1 commit into
Conversation
useAnimatedKeyboard crash "Can't change insets on an animation that is cancelled"useAnimatedKeyboard crash "Can't change insets on an animation that is cancelled"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fix for a keyboard animation race update crash:
Crash logs
useAnimatedKeyboard()enables edge-to-edge mode (setDecorFitsSystemWindows(window, false)) and registers aWindowInsetsAnimationCompat.Callback. As a result, the system — not Reanimated — animates the keyboard insets through Android'sInsetsController.The bug
When the keyboard is shown,
InsetsControllercreates an inset-animation runner and defers its start to the next pre-draw. At that point Android, in order:KeyboardAnimationCallback.onStart(viadispatchWindowInsetsAnimationStart), and thenonReady→setInsetsAndAlpha.The problem is step 1. Our
onStartsynchronously calls worklet, which re-enters Reanimated on the same thread. That reentrancy can cancel the still-pending runner inside this fragile window (e.g. a competingKeyboard.dismiss()/blur gets flushed). WhenonReadythen fires in step 2, it callssetInsetsAndAlphaon a runner that is already cancelled and throws.Reanimated doesn't cancel runner itself, it only opens a window to make it possibly.
This mirrors the fix the
react-native-keyboard-controllermaintainer landed for theidentical crash in kirillzyusko/react-native-keyboard-controller#1461.
Test plan
Reproduction code
Note that, system animation should be turned off in developer settings to make it crash more deterministic.