Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pressing twice to make the button work when TextInput is focused

I have problem when trying to submit data from the TextInput component. When trying to press the button that invoke the callback that handle the text, there is a need to press it twice for it to work. Once for the TextInput lose its focus and the second time to invoke the callback. I tried this solution but it didnt worked for me.

COMPONENT:

  <Modal>
    <ScrollView>
      <Card>
        <CardImage source={{uri: this.props.linkImage}}/>
        <CardContent/>
      </Card>
      {
        this.state.single.map((comment) => {
          return comment[3] ?  
            <Comp/> : null                                           
          })
      }
  </ScrollView> 
    <KeyboardAvoidingView behavior="padding" enabled>   
      <CardAction>
      <TouchableOpacity>
        <IconFA name="reply"/>
      </TouchableOpacity>
      <TouchableOpacity>
        <IconEn name="thumbs-up"/>
      </TouchableOpacity>
      <TouchableOpacity>
        <IconEn name="thumbs-down"/>
      </TouchableOpacity>

      </CardAction> 
      <CardAction>
        <TextInput ref={input => this.input = input}/>
        <TouchableOpacity>
          <IconFA name="rocket"/>
        </TouchableOpacity> 
      </CardAction> 
    </KeyboardAvoidingView>             
  </Modal>
like image 643
obiwankenoobi Avatar asked Oct 22 '25 22:10

obiwankenoobi


1 Answers

Just pass keyboardShouldPersistTaps="always" prop to ScrollView wrapping your component like this:

<ScrollView keyboardShouldPersistTaps="always">
   ...content
<ScrollView>
like image 161
Shivam Kakkar Avatar answered Oct 24 '25 18:10

Shivam Kakkar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!