反应本机 textInput scrollView android

use*_*167 6 javascript textinput scrollview reactjs react-native

我正在尝试编写一个非常简单的应用程序来测试 React Native。

我在一个大的 ScrollView 中有一些 TextInput 组件,作为注册公式。

一切正常,但是当我滚动单击 TextInput 时,它不滚动。

我只能在空白处单击时滚动页面。知道怎么做吗?

谢谢。

<ScrollView>
  <TextInput onChangeText={email => this.setState({email})} label={ I18n.t("contactEmail") }/>
  <TextInput onChangeText={email => this.setState({email})} label={ I18n.t("contactEmail") }/>
  <TextInput onChangeText={email => this.setState({email})} label={ I18n.t("contactEmail") }/>
  <TextInput onChangeText={email => this.setState({email})} label={ I18n.t("contactEmail") }/>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

Dus*_*usk 3

我遇到了同样的问题,搜索了一段时间后没有答案对我有帮助;所以我自己解决了这个问题,方法是在<TouchableWithoutFeedback />每个上放置一个<TextInput>并将触摸事件发送回<TextInput />

<View>
    <TextInput ref ={(ref)=>this.textInput = ref}>
    <TouchableWithoutFeedback style={{position: 'absolute', top:0, bottom:0, left:0, right:0}}
    onPress={()=>this.textInput.focus()}/>
</View>
Run Code Online (Sandbox Code Playgroud)

您可以创建一个像这样包装 TextInput 的自定义组件,并在 ScrollViews 中使用它们。