Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Keyboard automatically shown after open the screen

I am building the app in react native and expo.
I want to make the screen that when I go to this screen the keyboard should be already opened without possibility to close it.
I mean – the screen should look like in the photo below just after I open this

enter image description here

Is there any way to do this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the autoFocus prop of the TextInput in order to open the keyboard on mount of the screen (e.g. it is triggered in the useEffect).

const [number, setNumber] = useState()

<View keyboardShouldPersistTaps='always'>
<TextInput
   autoFocus={true}
   onChangeText={x => setNumber(x)}
   value={number}
   blurOnSubmit={false}
/>
</View>

Use blurOnSubmit={false} in order to prevent keyboard dismis on enter and use keyboardShouldPersistTaps='always' on the parent view in order to prevent dismiss if tapping outside the screen.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading