Skip to content

Instantly share code, notes, and snippets.

@topherPedersen
Last active May 24, 2020 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save topherPedersen/2ed7eb64e85b797ab85a796a9a506f3a to your computer and use it in GitHub Desktop.
Save topherPedersen/2ed7eb64e85b797ab85a796a9a506f3a to your computer and use it in GitHub Desktop.
TextInput autoFocus work-around for use in React-Native Modals
<Modal
visible={true}
onShow={ () => { this.textInput.focus(); }}>
{/* Adapted From: https://stackoverflow.com/questions/42730400/focus-input-on-load-of-modal-in-react-native */}
<KeyboardAvoidingView style={{}}>
<TextInput
style={{}}
ref={ (input) => { this.textInput = input; }}
placeholder=" Enter Text Here"
onChangeText={ (text) => console.log(text) }
value={ null } />
<Button
title="Submit"
onPress={ () => console.log("do stuff...") } />
</KeyboardAvoidingView>
</Modal>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment