React native text input onblur event gets called on its own, preventing keyboard input to be processed - react-native

trying to build an OTP input screen. From what I read, it can be achieved by hiding the TextInput component and displaying the inputted text in views. I have shared a basic Expo snack link. The text input is not taking the values I press on the keyboard. here is the expo link - https://snack.expo.dev/oD72PI5Xch. Can someone help me with what I am doing wrong?
Another issue I have noticed is that the keyboard doesn't show up if I press the back button and then again press the <Text> component from where I have called the onPress to call focus() on the TextInput. It will come up if I press the back button and then press the Text component only once. If I again close it using the back button, after that the keyboard stops coming up.
Below is the console log output based on the logging statements I have in the code snack (my actions are marked with >>>>>) -
1>>>>> App opens up
text input onfocus called
text input onblur called
keyboard did show
2>>>>> App stabilizes
3>>>>> I press the back button
keyboard did hide
4>>>>> I press the text component
calling focus
keyboard did show
5>>>>> I press the back button
keyboard did hide
6>>>>> I keep pressing the text component
calling focus
calling focus
calling focus
calling focus
calling focus
calling focus
I think the issue might be before the 2>>>>> part. The TextInput's onBlur is already called. That might be the reason why it is not taking keyboard inputs. Also, even after calling focus, the onFocus logging is absent, meaning that the text input never came into focus. What am I doing wrong? Thanks in advance :)
And if you solve this, please help me out with the issue of keyboard not appearing on pressing the Text component multiple times (6>>>>> part of the console output).

I don't clearly understand what are you trying to do by giving 0 height and width to TextInput, If you are trying to create an OTP input field you can simply use any third-party libraries like react-native-otp-input or try to use code from this existing snack

Related

How to activate text input on press of a button in react native?

I'm creating a basic note pad app. In the app, the user can press a button to "add a note". When pressed, a modal is rendered displaying a text input for the user to type their note.
The issue I'm having is once the modal has opened, the user has to manually tap the text input to pull up the keyboard and type their note. Instead I want the text input to be activated automatically the moment the modal is displayed on press of the button. So in other words, allow the user to start typing their note, once the modal opens up.
So I assume I have to some how activate a text input on press of a button? Is this possible?
Thanks.
Use the autoFocus prop.
<TextInput autoFocus={true}
Note that the input will focus when the component is mounted, so you may want to render the modal conditionally.

How to always show a keypad in react native?

I have a view, in which there is a redux form field linked to a text input.
First of all, is there a way to show that keypad on initial rendering without the sliding in animation?
Second, on finished editing, is there a way to still keep the keypad up there?
I have tried to set blurOnSubmit to false in TextInput, it seems to stop me from losing the focus by clicking outside.
Lastly, there is also a button on that page which will start a request with the input value, on resolved, a modal will slide up from the bottom to show a success screen. This modal is implemented using react-navigation. The modal is a relatively small rectangle shape with the rest part transparent. So users can see the original page even when the success modal is up. In this case, is there a way to always show the keypad in the original screen even when the modal is up?
First of all, is there a way to show that keypad on initial rendering without the sliding in animation?
No. React Native doesn't support a way to disable the slide animation.
Second, on finished editing, is there a way to still keep the keypad up there?
If the TextInput is being rendered inside a ScrollView, add keyboardShouldPersistTaps=handled. https://facebook.github.io/react-native/docs/scrollview#keyboardshouldpersisttaps. It will hold the focus.

TextInput fullscreen onFocus react native

Hi is there a way to make an multiline TextInput go fullscreen onFocus and return to its normal size after the user finished editting (for ex: when the user hits the android Back button).
I plan to allow user to type a long paragraph in my App, and I think it would improve the UX if I can make the multiline text go fullscreen when user typing.
I imagine a multiline TextInput like that would be a helpful for many other developers as well, it's shocking that I couldn't find a pre-built component like that.
I think the best way to achieve this is to put a TouchableOpacity with an onPress listener around the TextInput and have it navigate to another screen which has a full-screen text input and receives the onChange listener via params (there will be a warning with react-navigation-5 but in most cases you can safely ignore it).

How to prevent React Native to dismiss keyboard

In a react-native form, when switching from one TextInput to the next one, the second grabs focus for an instant and then suddenly RN dismisses the keyboard.
I have onSubmitEditing coded to move to next input, but the user needs to click on enter in the keyboard, I can also override onEndEditing however that forces you to move to the next input and maybe you didn't touch that one.
I found out that the problem is related to having TextInputs within a ScrollView, focus between inputs in this component doesn't work as expected.
keyboardShouldPersistTaps={true} is deprecated so need to use keyboardShouldPersistTaps="always"

How can we provide default Back key press behaviour to a custom button tap event in Windows Phone 8?

I'm developing an Windows Phone 8 application. In a page i have placed one Button and one textbox. When user Taps on textbox, the default keyboard comes up. Now, keyboard is on display mode and i clicked on button which navigates me to another screen. After navigation it is giving me half the screen size to be in black and that is actually keyboard. So can anyone tell me how to hide the keyboard first and then navigate to another screen?
Is it possible to assign override OnBackKeyPress method to the button control? If not, what is the other way to get out of this problem?
All you have to do is changing the focus from textbox to page. Just add this code to button's tap event:
this.Focus();