Prevent crash when no first responder in keyboardWillShow.
💡 Motivation and Context
It happens because we can not find first responder when keyboardWillShow is triggerred:
Then we get NPE here (read absoluteY of nil):
And finally app crashes:
To fix this problem I've decided to add guard statement - there is no sense to execute code further if we don't have a reference to TextInput - no sense to store it in holder, no sense to add listeners/observers, substitute delegates etc.
📢 Changelog
iOS
check that first responder is actually present before executing the code that relies on its presence;
📜 Description
Prevent crash when no first responder in
keyboardWillShow
.💡 Motivation and Context
It happens because we can not find first responder when
keyboardWillShow
is triggerred:Then we get NPE here (read
absoluteY
ofnil
):And finally app crashes:
To fix this problem I've decided to add
guard
statement - there is no sense to execute code further if we don't have a reference toTextInput
- no sense to store it in holder, no sense to add listeners/observers, substitute delegates etc.📢 Changelog
iOS
🤔 How Has This Been Tested?
Tested manually on iPhone 15.
📸 Screenshots (if appropriate):
https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/83ecde49-69de-483e-8403-92c4dd41c4c7
📝 Checklist