Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native textInput scrollView android

I am trying to write a very simple app to test react native.

I have some TextInput components in a big ScrollView, as a register formulary.

Everything works fine, but when I scroll clicking on a TextInput, it doesn't scroll.

I can only scroll through the page when I click in blank spaces. Any idea of how to do it?

Thanks.

<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>
like image 562
user2849167 Avatar asked Sep 28 '16 15:09

user2849167


1 Answers

I had the same problem and after searching for a while no answer helped me; so I solved it myself by putting a <TouchableWithoutFeedback /> over each <TextInput> and sending the touch event back to the <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>

You can create a custom component which wraps TextInput like that and use them in your ScrollViews.

like image 182
Dusk Avatar answered Nov 15 '22 02:11

Dusk