Skip to content

fix: switch between inputs with KeyboardGestureArea on iOS#938

Merged
kirillzyusko merged 5 commits into
mainfrom
fix/interactive-keyboard-switch-between-inputs
Jun 3, 2025
Merged

fix: switch between inputs with KeyboardGestureArea on iOS#938
kirillzyusko merged 5 commits into
mainfrom
fix/interactive-keyboard-switch-between-inputs

Conversation

@kirillzyusko
Copy link
Copy Markdown
Owner

@kirillzyusko kirillzyusko commented May 12, 2025

📜 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

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:

      <AnimatedTextInput
        multiline
        nativeID="chat-input"
        style={{width: "100%", height: 50, backgroundColor: "blue"}}
        testID="chat.input"
      />

📸 Screenshots (if appropriate):

ScreenRecording_06-03-2025.11-58-17.AM_1.MP4

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@kirillzyusko kirillzyusko self-assigned this May 12, 2025
@kirillzyusko kirillzyusko added 🐛 bug Something isn't working 🍎 iOS iOS specific 👆 interactive keyboard Anything related to interactive keyboard dismissing labels May 12, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 12, 2025

📊 Package size report

Current size Target Size Difference
197896 bytes 197665 bytes 231 bytes 📈

@kirillzyusko kirillzyusko force-pushed the fix/interactive-keyboard-switch-between-inputs branch from b72342f to 17513a8 Compare May 26, 2025 10:49
@kirillzyusko kirillzyusko force-pushed the fix/interactive-keyboard-switch-between-inputs branch from 54f78bc to 5e7c320 Compare June 3, 2025 10:00
@kirillzyusko kirillzyusko marked this pull request as ready for review June 3, 2025 10:11
@kirillzyusko kirillzyusko merged commit 98df8d8 into main Jun 3, 2025
18 of 19 checks passed
@kirillzyusko kirillzyusko deleted the fix/interactive-keyboard-switch-between-inputs branch June 3, 2025 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working 👆 interactive keyboard Anything related to interactive keyboard dismissing 🍎 iOS iOS specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant