Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to setup Onpress On Textinput in react-native

I am developing an app on react native. I want to call a date picker when i press on a Text-Input and after selecting a date it should show on the Text-Input

like image 822
Savad Avatar asked Feb 15 '19 10:02

Savad


People also ask

How do you set focus on TextInput in React Native?

You need to use the ref prop for the TextInput component. Then you need a create a function that gets called on onSubmitEditing prop that moves the focus on the second TextInput ref.

How do you increase TextInput height in React Native?

To grow height of TextInput upon text wrapping with React Native, we can set the height of the TextInput to the content's height when the content size changes. to set the onContentSizeChange prop to a function that calls setHeight with event. nativeEvent. contentSize.


3 Answers

Wrap TextInput into a view and set pointerEvents as none. Now you can use Pressable component from react-native to listen to the onpress event.

<Pressable onPress={() => alert('Hi!')}>
 <View pointerEvents="none">
  <TextInput />
 </View>
</Pressable>
like image 167
Kuldeep Saxena Avatar answered Oct 18 '22 11:10

Kuldeep Saxena


You cannot explicitly call onPress for TextInput. You could only use. onFocus which will be called when you press the input box to get cursor over there. No need to focus on onBlur as your use case doesn't required.. Handle close within onFocus if possible.

onFocus = () => {
  // do something
}

render() {
  <TextInput onFocus={onFocus} />
}
like image 34
Naveen Vignesh Avatar answered Oct 18 '22 11:10

Naveen Vignesh


You can make text input field read only by providing

 editable={false}
 pointerEvents="none"

prop to TextInput.

like image 22
Ram Rana Avatar answered Oct 18 '22 12:10

Ram Rana