Skip to content

Touchable: use within body scroller / outside of ScrollView #829

@necolas

Description

@necolas

Possible feature enhancement, to help incremental adoption in existing body-scroller React apps.

There are 2 significant issues with using Touchable* components within an app that relies on the document.body (rather than ScrollView) being the root scroller. I believe the root cause of both issues is that the body is not part of the responder system, which Touchable and ScrollView rely on to coordinate transfer of the responder grant.

Touchable* press events will fire under a finger that is scrolling the body

This is because the Touchable* remains the touch responder during a body scroll. Unlike ScrollView, the body element is not under React's control, and is not connected to the responder system.

This can be reproduced in the storybook's documentation for Touchable{Highlight,Opacity}.

  1. Start a scroll on top of a Touchable
  2. Release the Touchable

Actual: press events fire during the gesture.
Expected: no press events fire during the gesture.

TouchableHighlight underlay can remain visible for a couple of seconds after the gesture

All the events fire when expected. But the visual underlay gets stuck. This problem only occurs under the following conditions: it's the first touch to occur after a body-scroll AND a ScrollView has not been scrolled yet. (I've actually occasionally seen this happen with TouchableHighlight within a ScrollView, but I don't have any reliable steps to reproduce.)

This can be reproduced in the storybook's documentation for TouchableHighlight.

  1. Go straight to the TouchableHighlight screen.
  2. Scroll down to the examples
  3. Press an example

Actual: underlay remains visible long after touch finishes
Expected: underlay immediately disappears

  1. Without doing anything else, press again

Actual/Expected: underlay immediately disappears.

  1. Scroll the screen
  2. Press the example again

Actual: underlay remains visible long after touch finishes
Expected: underlay immediately disappears

  1. Repeat previous steps. The behaviour should reproduce consistently.
  2. Go to the ScrollView screen.
  3. Find an example ScrollView and scroll it.
  4. Go back to the TouchableHighlight screen.
  5. Attempt to reproduce steps 3-7.

You should find that the issue has magically been resolved.

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

  • OS: all
  • Device: all
  • Browser: all
  • React Native for Web (version): all
  • React (version): all

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementRequires extension or creation of new React Native API

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions