react-native
react-native copied to clipboard
feat: fix show soft input on focus behavior
Summary
The showSoftInputOnFocus of TextInput is not working properly. When we set showSoftInputOnFocus to false and subsequently to true, it fails to open the keyboard, we have to re-focus on the input in order for the keyboard to show. It's expected that the keyboard will be opened as soon as showSoftInputOnFocus becomes true. This happens on iOS only.
Reference in React Native doc: https://reactnative.dev/docs/textinput#showsoftinputonfocus.
Changelog
[iOS] [Fixed] - Fix issue where keyboard does not open when TextInput showSoftInputOnFocus changes from false to true
Test Plan
I've made a clean create-react-native-app repo to demonstrate this https://github.com/christianwen/reduced-rn-app.
Here's the steps:
- Clone https://github.com/christianwen/reduced-rn-app
- Run
yarn install - Run
cd ios, thenpod install, thencd .. - Run
yarn ios - See the text input on the top of the screen, it can be observed that the keyboard does not open because
showSoftInputOnFocusisfalse, 3 seconds later it becomestruedue to asetTimeoutthat is used
https://user-images.githubusercontent.com/21312517/200366099-db8626a6-1a31-4bfc-862c-2e37a8b35a3f.mov
However, it can be seen that the keyboard does not open even though showSoftInputOnFocus becomes true
6. Now add the change in this PR to Libraries/Text/TextInput/RCTBaseTextInputView.m
7. Run yarn ios again
8. Now verify the step 5 again, the keyboard will open automatically when showSoftInputOnFocus becomes true
https://user-images.githubusercontent.com/21312517/200363910-726716b1-e76d-420b-848d-a98747868db9.mp4
The reason why I created a fresh RN repo instead of using rn-tester app is because the showSoftInputOnFocus example is not working in rn-tester app for some reasons (it shows the keyboard even though showSoftInputOnFocus is false in the example).
Regarding the code, it's similar to the fix for keyboardType in https://github.com/facebook/react-native/commit/8baaacb66458dd706421fcbc1fc1934cd1ebbb94.
| Platform | Engine | Arch | Size (bytes) | Diff |
|---|---|---|---|---|
| android | hermes | arm64-v8a | 6,995,344 | -70,833 |
| android | hermes | armeabi-v7a | 6,371,882 | -66,679 |
| android | hermes | x86 | 7,408,031 | -73,464 |
| android | hermes | x86_64 | 7,272,040 | -68,849 |
| android | jsc | arm64-v8a | 8,861,159 | -70,836 |
| android | jsc | armeabi-v7a | 7,599,671 | -66,668 |
| android | jsc | x86 | 8,918,904 | -73,462 |
| android | jsc | x86_64 | 9,402,268 | -68,853 |
Base commit: 6152763398efe60521fc86fcf992b6a84361df12 Branch: main
| Platform | Engine | Arch | Size (bytes) | Diff |
|---|---|---|---|---|
| ios | - | universal | n/a | -- |
Base commit: 6152763398efe60521fc86fcf992b6a84361df12 Branch: main
PR build artifact for 42472db389a76f06d340139cb32fb9f03ea2b6e0 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.
@jacdebug has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.