kirillzyusko / react-native-keyboard-controller

Keyboard manager which works in identical way on both iOS and Android
https://kirillzyusko.github.io/react-native-keyboard-controller/
MIT License
1.38k stars 55 forks source link

fix: race condition between keyboardWillHide and KVO #446

Closed kirillzyusko closed 1 month ago

kirillzyusko commented 1 month ago

πŸ“œ Description

Fixed race condition between keyboardWillHide and KVO.

πŸ’‘ Motivation and Context

The problem is that we dispatch syncUpLayout asynchronously: https://github.com/kirillzyusko/react-native-keyboard-controller/blob/091af29004ff756614cd240e488754a3fe477569/ios/observers/FocusedInputObserver.swift#L172-L174

And here we may have a race condition: KVO can dispatch an even, after that keyboardWillHide can be triggered, and finally we dispatch syncUpLayout (but the problem is that by this time currentInput will be already nil and we've already dispatched an event noFocusedInput -> eventually we'll get a crash when we'll try to read absoluteY from layout property).

To fix this problem we had two ways:

πŸ“’ Changelog

iOS

πŸ€” How Has This Been Tested?

Tested manually on iPhone 15 Pro.

πŸ“Έ Screenshots (if appropriate):

No sense to attach a video, because it's very hard to reproduce the problem (I could reproduce it by swipe a screen back and forth and after ~30 seconds I was getting a crash).

πŸ“ Checklist

github-actions[bot] commented 1 month ago

πŸ“Š Package size report

Current size Target Size Difference
136087 bytes 136075 bytes 12 bytes πŸ“ˆ