You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: switch between inputs with KeyboardGestureArea on iOS (#938)
## 📜 Description
Fixed a problem with autoclosing keyboard if you switch between inputs +
`KeyboardGestureArea` has active `offset`.
## 💡 Motivation and Context
The key problem here is that in previous implementation
`resignFirstResponder` call gets delayed, so first of all we call
`becomeFirstResponder`, then we call `resignFirstResponder`, but it's
getting delayed, so new input get focus and then we call
`resignFirstResponder` and keyboard gets closed.
First fix that I did was saving pending request in
`resignFirstResponder` - I found out that it's getting called two times,
and I thought if we call it second time and we have pending request ->
we can immediately remove focus and cancel previous task. It works on
simulator, but not on a real device - on a real device keyboard becomes
hidden and then becomes visible.
To fix all problems I decided to intercept `becomeFirstResponder` event,
and save new focused input. If `resignFirstResponder` is getting called
and we have a pending request, then we should remove
`inputAccessoryView` immediately + don't add any delays. In its turn
`becomeFirstResponder` should store new focus request only for short
amount of time - otherwise, if we store it permanently we can not
distinguish a case "focus switch" vs "dismiss a keyboard", so current
algorithm looks like:
- we have `resignFistResponder` and in the past frame we had
`becomeFirstResponder` request -> we switch focus, so do a cleanup
immediately;
- we have `resignFistResponder` and in the past frame we didn't have
`becomeFirstResponder` request -> remove `inputAccessoryView` and close
the keyboard (similar to how it was working before).
## 📢 Changelog
<!-- High level overview of important changes -->
<!-- For example: fixed status bar manipulation; added new types
declarations; -->
<!-- If your changes don't affect one of platform/language below - then
remove this platform/language -->
### iOS
- swizzle `becomeFirstResponder`;
- store current first responder for one frame;
- check in `resignFirstResponder` presence of current first responder
and if we have it -> do a cleanup immediately.
## 🤔 How Has This Been Tested?
Tested manually on iPhone 11 (iOS 17.4), with following code added
before `ScrollView`:
```tsx
<AnimatedTextInput
multiline
nativeID="chat-input"
style={{width: "100%", height: 50, backgroundColor: "blue"}}
testID="chat.input"
/>
```
## 📸 Screenshots (if appropriate):
https://github.com/user-attachments/assets/ff7d54d9-452b-432c-b587-2660132c3deb
## 📝 Checklist
- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed
0 commit comments