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:
dispatch syncUpLayout synchronously - for that we had to change quite a lot of code (and I initially decided that it will take more code without significant advantages, thats why I dispatch currently asynchronously it)
check that currentInput is present <- that's what I do in this PR.
π’ Changelog
iOS
check that currentInput is actually present before sending an event;
π€ 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
[x] CI successfully passed
[x] I added new mocks and corresponding unit-tests if library API was changed
π Description
Fixed race condition between
keyboardWillHide
andKVO
.π‘ 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-L174And here we may have a race condition: KVO can dispatch an even, after that
keyboardWillHide
can be triggered, and finally we dispatchsyncUpLayout
(but the problem is that by this timecurrentInput
will be alreadynil
and we've already dispatched an eventnoFocusedInput
-> eventually we'll get a crash when we'll try to readabsoluteY
fromlayout
property).To fix this problem we had two ways:
syncUpLayout
synchronously - for that we had to change quite a lot of code (and I initially decided that it will take more code without significant advantages, thats why I dispatch currently asynchronously it)currentInput
is present <- that's what I do in this PR.π’ Changelog
iOS
currentInput
is actually present before sending an event;π€ 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