Skip to content

Touchable: onPress is triggered when scrolling at the top of a ScrollView #731

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

Closed
wjielim opened this issue Dec 7, 2017 · 12 comments
Closed
Labels

Comments

@wjielim
Copy link

wjielim commented Dec 7, 2017

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
TouchableOpacity inside a ScrollView will be triggered if one try to scroll up while the ScrollView is already at its top. See the below gif for better understanding:

scrollview touchable issue

This also happens to horizontal ScrollView.

If the current behavior is a bug, please provide the steps to reproduce and
if a minimal demo of the problem via Glitch or similar (template:
https://glitch.com/edit/#!/react-native-web-playground).

copy paste this code:

<ScrollView style={{backgroundColor: '#f1f2f3', flex: 1, height: Dimensions.get('window').height, width: Dimensions.get('window').width}}>
{
          (() => {for (let i=0; i < 10; i++){
            buttons.push(
              <TouchableOpacity onPress={() => {alert(`button ${i} Pressed!`)}}
                                style={{width: 300, height: 150, backgroundColor: 'blue', color: 'white', margin: 10}}>
                <Text>Button {i}</Text>
              </TouchableOpacity>
            )
          }})()
}

{buttons}
</ScrollView>

What is the expected behavior?

TouchableOpacity should not trigger onPress when it's inside a ScrollView (with height set to screen/window height) when scrolling under any circumstances.

Environment (include versions). Did this work in previous versions?

  • OS: Windows
  • Device: Microsoft Surface Pro 3
  • Browser: Google Chrome v62.0.3202.94 (Official Build) (64-bit)
  • React Native for Web (version): 0.1.16
  • React (version): 16.2.0
@necolas necolas changed the title TouchableOpacity unintentionally trigger onPress in ScrollView with bounded height TouchableOpacity: unintentionally triggers onPress in ScrollView with bounded height Dec 18, 2017
@necolas necolas added the bug label Dec 18, 2017
@aizigao
Copy link

aizigao commented Jan 19, 2018

same problem, mark

@jondkoon
Copy link

I made a glitch to try and repro this and it seems to be working as expected when using a ScrollView:

View: https://giant-planet.glitch.me/
Edit: https://glitch.com/edit/#!/giant-planet?path=src/App/index.js:1:0

If you replace the ScrollView with a View then it fails as described

@necolas
Copy link
Owner

necolas commented Jan 27, 2018

I can't reproduce this issue either. Perhaps it is Windows-only, but that seems unlikely given the browser is Chrome.

@necolas necolas closed this as completed Jan 27, 2018
@aizigao
Copy link

aizigao commented Jan 30, 2018

@necolas
Copy link
Owner

necolas commented Feb 3, 2018

I can actually reproduce this with both Touchables when you drag-down and release while still over the button. On native, the scrollview becomes the responder as soon as you start to drag after pressing on a touchable. On web, the touchable remains the responder.

@necolas necolas reopened this Feb 3, 2018
@necolas necolas changed the title TouchableOpacity: unintentionally triggers onPress in ScrollView with bounded height Touchable: onPress is triggered when scrolling at the top of a ScrollView Feb 3, 2018
rxrossi added a commit to rxrossi/react-native-web that referenced this issue Feb 9, 2018
… would

not prevent the onPress event of being triggered

This would affect users clicking on a Touchable by accident while
scrolling up or down on mobile browsers

It is probably a fix for the issue necolas#731
rxrossi added a commit to rxrossi/react-native-web that referenced this issue Feb 9, 2018
Canceling a event by moving outside from the Touchable area would not prevent the onPress event of being triggered
This would affect users clicking on a Touchable by accident while scrolling up or down on mobile browsers

It is probably a fix for the issue necolas#731
rxrossi added a commit to rxrossi/react-native-web that referenced this issue Feb 9, 2018
Canceling a event by moving outside from the Touchable area would not prevent the onPress event of being triggered
This would affect users clicking on a Touchable by accident while scrolling up or down on mobile browsers

It is probably a fix for the issue necolas#731
@necolas
Copy link
Owner

necolas commented Feb 15, 2018

I think I understand the root of the issue. In React Native, ScrollView will trigger onScroll events if you're dragging down when at the top of the scroll view - this allows the responder system to transfer the responder grant from the touchable back to the scroll view. But the web stops dispatching scroll events when scrollTop === 0, so the responder system leaves the touchable as the responder.

The reported issue goes away when ScrollView dispatches a DOM scroll event after it receives a touchmove that occurs when scrollTop === 0. But I will need to investigate a more sophisticated solution that accounts for drag/scroll direction, and think about what problems this approach might introduce.

@mho79

This comment has been minimized.

@hushicai
Copy link
Contributor

I think custom scroller that supports momentum scroll event will solve this problem.

@MoOx
Copy link
Contributor

MoOx commented Dec 31, 2018

I think I found something that might help to debug this. While investigating for #829, I tried to wrap my app with a ScrollView without any actual scroll (no specific height or flex). A sort of useless ScrollView, but not that useless as touch events are still triggered. It's just that scroll is never fired.
And with this setup, I experienced some weird cases, while touching/moving. I didn't always get a cancel for a given touch. I am not able yet to reproduce but playing with on mobile clearly show that the opacity effect is not always canceled while scrolling... https://v84xmm7l37.codesandbox.io/

We can clearly see most scroll trigger onPress, but not all. And we know it before releasing the finger.

demo

@necolas
Copy link
Owner

necolas commented Jan 3, 2019

Closing this issue so we can coordinate findings and solutions in #1219

@Diaa-Ghonim
Copy link

Diaa-Ghonim commented Sep 9, 2023

@necolas this issue is still happening with me on mobile browsers.

I use this release 0.11.7
and I upgraded to 0.13.0 and 0.14.0 and it is still happening with me.

any one solved it here??

@necolas
Copy link
Owner

necolas commented Sep 11, 2023

Update to 0.19.

Repository owner locked as resolved and limited conversation to collaborators Sep 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants