如何在 react-native 中设置 Onpress On Textinput

Stv*_*lam 8 textinput react-native onpress

我正在开发一个关于本机反应的应用程序。我想在按下文本输入时调用日期选择器,并且在选择日期后它应该显示在文本输入上

Kul*_*ena 21

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>
Run Code Online (Sandbox Code Playgroud)


Nav*_*esh 12

你不能显式调用onPressTextInput。你只能用。onFocus当您按下输入框将光标移到那里时,它将被调用。无需关注 onBlur,因为您的用例不需要。. onFocus如果可能,请靠近内部处理。

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

render() {
  <TextInput onFocus={onFocus} />
}
Run Code Online (Sandbox Code Playgroud)