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

fix: StoryView was interfering with scroll gestures #440

Merged

Conversation

jonathanj
Copy link
Contributor

@jonathanj jonathanj commented Mar 3, 2023

Some touch interactions, especially scrolling, were not working well after StoryView started wrapping its contents in TouchableWithoutFeedback.

What I did

Switch out the use of TouchableWithoutFeedback and prefer to use onStartShouldSetResponder to listen for touch interactions, dismiss the keyboard, and then decline to handle the touch interaction. This means that the interaction attempt is handed to the next component in the hierarchy to handle.

Unlike Touchable... which wants to handle the interaction, and ends up interfering with interactions.

How to test

There are a few new stories under the "Interaction Examples" section in the storybook. They all work now, but you can see the broken behaviour by making the following local modifications in StoryView.tsx:

  • Remove onStartShouldSetResponder={dismissOnStartResponder}
  • Wrap the story view content:
    <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
      <Box …>…</Box>
    </TouchableWithoutFeedback
    

Most of the interactions are unaffected, but the "Scrolling" story will not be scrollable unless the keyboard is open.

If you remove both the TouchableWithoutFeedback and the onStartShouldSetResponder prop, then the scrolling interaction views will dismiss the keyboard on tap, but the "Static" story won't.

This fix works by using the React Native responder system to detect
the interaction, and dismiss the keyboard, but declines to actually
start handling the gesture. This means that the attempt is handed
to the next component in the hierarchy to handle.

Unlike `Touchable...` which _wants_ to handle the interaction, and
ends up interfering with interactions.
@jonathanj jonathanj requested a review from dannyhw as a code owner March 3, 2023 18:58
@dannyhw
Copy link
Member

dannyhw commented Mar 3, 2023

Looks good!

@dannyhw dannyhw merged commit 6606189 into storybookjs:next-6.0 Mar 3, 2023
@jonathanj jonathanj deleted the fix-story-view-swallowing-gestures branch March 13, 2023 13:23
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

Successfully merging this pull request may close these issues.

2 participants