Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item's onPress does not work when inside ScrollView #5

Closed
joonhocho opened this issue May 17, 2016 · 13 comments
Closed

Item's onPress does not work when inside ScrollView #5

joonhocho opened this issue May 17, 2016 · 13 comments

Comments

@joonhocho
Copy link

As title says, selecting item is not working when nested inside a ScrollView.

@joonhocho
Copy link
Author

Related facebook/react-native#7572

@mrlaessig
Copy link
Collaborator

Do you have still problems with RN v0.26.2?

@saemie
Copy link

saemie commented Jun 1, 2016

I am getting the same problem with RN v0.26.2
onPress does not work for items passed to the renderItem property.

I'm testing this with the example app. Any idea what the problem may be?

@mrlaessig
Copy link
Collaborator

@saemie Do you use the same code from the example? Do you test on the device or emulator?

@ajoshdee
Copy link

Hi, I tested it using your example but I'm having a hard time selecting from the list returned by autocomplete. my autocomplete component is inside a scroll view

@bbalu
Copy link

bbalu commented Jul 18, 2016

After removing this following line, TouchOpactity onPress function is being called.
<TextInput
...
onEndEditing={e =>
this._showResults(false) || (onEndEditing && onEndEditing(e))
}
...

@ltquang
Copy link

ltquang commented Aug 5, 2016

Hello,
I have 1 solution for you
please add keyboardShouldPersistTaps={true} in your scrollview

ScrollView keyboardShouldPersistTaps={true}
.
   Autocomplete
                    ....
                    renderItem={data => (
                      <TouchableOpacity onPress={() => this.props.onSelectedProvinceChange(data)}>
                        <Text style={{color: Commons.Colors.gray_dark, fontFamily: Commons.Fonts.regular, fontSize: Commons.Fonts.p}}>{data}</Text>
                      </TouchableOpacity>
                    )}
                  />
/ScrollView

*It's work for me :) Hope to help you

@mrlaessig
Copy link
Collaborator

Thx @ltquang your suggestion to add the keyboardShouldPersistTaps={true} prop to the ScrollView seems to fix the issue.

@panuhorsmalahti
Copy link

panuhorsmalahti commented Mar 20, 2018

While adding keyboardShouldPersistTaps to true (well, "always" these days) fixes this issue, I need to have keyboardShouldPersistTaps "never" to close the keyboard after clicking outside inputs. Therefore this solution is not suitable for me.

@armadillojim
Copy link

@panuhorsmalahti, have you tried setting keyboardShouldPersistTaps to handled? Dunno if that'll fix your issue, but it's worth a try. FWIW, I have a ScrollView with multiple autocomplete fields, and clicking outside them closes the keyboard for me.

@c-goettert
Copy link

@armadillojim 'handled' works great on android, but on iOS the autocomplete scroll still behaves buggy. Although in principle you can select elements and close the autocomplete window by tapped outside the range, the autocomplete view often closes randomly when scrolling inside the autocomplete-view.

@c-goettert
Copy link

@panuhorsmalahti I managed to get it working with keyboardShouldPersistTaps='always' and Naomipols solution for nested ScrollView from another thread.
To automatically dismiss the keyboard again (if the user taps outside the list), I just use componentDidUpdate of the Parent View, e.g. like this:

  componentDidUpdate (prevProps, prevState) {
    const previouslyEnabled = prevState.enableScrollViewScroll
    const newEnabled = this.state.enableScrollViewScroll
    // if scroll was just enabled again, that means user tapped outside of autocomplete list
    // -> manually dismiss keyboard then, because we set keyboardShouldPersistTaps to 'always'
    if (previouslyEnabled !== newEnabled && newEnabled) {
      Keyboard.dismiss()
    }
  }

@gauravgandhigg
Copy link

Hi

Hello,
I have 1 solution for you
please add keyboardShouldPersistTaps={true} in your scrollview

ScrollView keyboardShouldPersistTaps={true}
.
   Autocomplete
                    ....
                    renderItem={data => (
                      <TouchableOpacity onPress={() => this.props.onSelectedProvinceChange(data)}>
                        <Text style={{color: Commons.Colors.gray_dark, fontFamily: Commons.Fonts.regular, fontSize: Commons.Fonts.p}}>{data}</Text>
                      </TouchableOpacity>
                    )}
                  />
/ScrollView

*It's work for me :) Hope to help you

Hey So this solution also works when we use a picker inside a scrollview. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants