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

Prevent swiping and clicking at the same time in Tabs #11313

Closed
5 of 11 tasks
Eloy8 opened this issue Mar 30, 2023 · 12 comments
Closed
5 of 11 tasks

Prevent swiping and clicking at the same time in Tabs #11313

Eloy8 opened this issue Mar 30, 2023 · 12 comments

Comments

@Eloy8
Copy link

Eloy8 commented Mar 30, 2023

Current behavior

Currently it's not possible to distinguish between a click event and swipe event in a Tab screen.

As seen in the recording bellow, when one swipes to a different tab from a clickable component, it also triggers a click event besides the swipe:
Recording_2023-03-30-12-49-49(1)

This combination of events will trigger both the click event (aka a navigation from the FlatList to a child component) as a swipe to a different Tab. It also seems to glitch a bit, so immediately after opening the child component it will go back to the parent component.

At this moment I haven't found a way to disable the click action when swiping, a solution would be a great improvement.
Since the code stack is private, no code is supplied. When necessary, a code snippet can be produced.

Expected behavior

When an user swipes on a Tab screen, it won't be accompanied by click events.

Reproduction

Platform

  • Android
  • iOS
  • Web
  • Windows
  • MacOS

Packages

  • @react-navigation/bottom-tabs
  • @react-navigation/drawer
  • @react-navigation/material-top-tabs
  • @react-navigation/stack
  • @react-navigation/native-stack
  • react-native-tab-view

Environment

  • [] I've removed the packages that I don't use
package version
@react-navigation/native 6.0.13
@react-navigation/bottom-tabs 6.4.0
@react-navigation/drawer -
@react-navigation/material-top-tabs 6.3.0
@react-navigation/stack 6.3.2
@react-navigation/native-stack 6.9.1
react-native-safe-area-context 4.5.0
react-native-screens 3.20.0
react-native-gesture-handler 2.9.0
react-native-reanimated -
react-native-tab-view 3.3.0
react-native-pager-view -
react-native 0.71.4
expo 48.0.0
node 16.19.0
yarn 1.22.19
@github-actions
Copy link

Hey @Eloy8! Thanks for opening the issue. It seems that the issue doesn't contain a link to a repro.

The best way to get attention to your issue is to provide an easy way for a developer to reproduce the issue.

You can provide a repro using any of the following:

A snack link is preferred since it's the easiest way to both create and share a repro. If it's not possible to create a repro using a snack, link to a GitHub repo under your username is a good alternative. Don't link to a branch or specific file etc. as it won't be detected.

Try to keep the repro as small as possible by narrowing down the minimal amount of code needed to reproduce the issue. Don't link to your entire project or a project containing code unrelated to the issue. See "How to create a Minimal, Reproducible Example" for more information.

You can edit your original issue to include a link to the repro, or leave it as a comment. The issue will be closed automatically after a while if you don't provide a repro.

@github-actions
Copy link

Couldn't find version numbers for the following packages in the issue:

  • @react-navigation/drawer

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • @react-navigation/native (found: 6.0.13, latest: 6.1.6)
  • @react-navigation/bottom-tabs (found: 6.4.0, latest: 6.5.7)
  • @react-navigation/material-top-tabs (found: 6.3.0, latest: 6.6.2)
  • @react-navigation/stack (found: 6.3.2, latest: 6.3.16)
  • react-native-tab-view (found: 3.3.0, latest: 3.5.1)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

@Eloy8
Copy link
Author

Eloy8 commented Mar 31, 2023

Upgrading to the specific package numbers doesn't solve the issue, there is no change in the previously described behavior.

@intergalacticspacehighway
Copy link

intergalacticspacehighway commented Apr 1, 2023

@Eloy8 are you using Pressable from React Native for clickable items? Did you try using RectButton?
Also, sharing a minimal repro (an expo snack or a GitHub repo with an example) would be really helpful. It really saves a ton of time 😄

@Eloy8
Copy link
Author

Eloy8 commented Apr 4, 2023

@intergalacticspacehighway Thanks for your reply! Indeed we use the RN Pressable, I haven't tried RectButton.

I will provide an minimal repo later today!

@Eloy8
Copy link
Author

Eloy8 commented Apr 5, 2023

@intergalacticspacehighway Thanks for your patience, I just finished creating a minimal repo to demonstrate the problem.

All relevant code is put in the App.js file. It exists out of an overview and a detail Stack Screen.
The Overview has a swipeable Tab Navigator with three screens. When one swipes quite often and quick horizontally (so your finger stays on the same clickable listitem), the detail page will be opened. For this issue I seek a solution.

https://github.com/Eloy8/react-navigation-swipe-click-issue/blob/main/App.js

Feel free to ask if there're any further questions! :)

@Eloy8
Copy link
Author

Eloy8 commented Apr 11, 2023

@Dhananjay-JSR Is the "needs response" label still relevant?

@DominicWiedman
Copy link

I had the same problem, but this solution helped

satya164/react-native-tab-view#1241 (comment)

@Eloy8
Copy link
Author

Eloy8 commented Apr 17, 2023

@DominicWiedman Thanks for your reply and suggestion!

I've implemented it with the Pressable component and changed the position treshhold to 5 instead of 2.
Although it is a work-around, it works incredibelly well. Thanks again!

@github-actions
Copy link

Hello 👋, this issue has been open for more than a month without a repro or any activity. If the issue is still present in the latest version, please provide a repro or leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution or workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix it.

@mharrison-nzme
Copy link

Late to the party, just wanted to reply with my solution.
Using the Touchable components from react-native-gesture-handler, rather than react-native, solved the issue for me

@github-actions
Copy link

github-actions bot commented Sep 8, 2023

Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.

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

No branches or pull requests

5 participants