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

Cannot scroll up/down in a scrollview on mobile web #658

Open
qwertychouskie opened this issue Aug 20, 2024 · 10 comments
Open

Cannot scroll up/down in a scrollview on mobile web #658

qwertychouskie opened this issue Aug 20, 2024 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@qwertychouskie
Copy link

Describe the bug
Using the code at #465 (comment) fixes the issue on iOS and Android, but the issue is still present on mobile web.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://app.carusosignature.com/ on mobile web browser (or responsive design mode on desktop with touch input simulation enabled)
  2. Scroll down to the carousels
  3. Attempt to scroll the page up/down

Versions (please complete the following information):

  • react: 18.2.0
  • react-native: 0.74.3
  • react-native-reanimated: ~3.10.1
  • react-native-reanimated-carousel: ^4.0.0-alpha.12
  • react-native-gesture-handler: ~2.16.1

Smartphone (please complete the following information):

  • Device: N/A
  • OS: N/A
  • Browser: Any
@qwertychouskie qwertychouskie added the bug Something isn't working label Aug 20, 2024
Copy link

dosubot bot commented Aug 20, 2024

Hey there, @qwertychouskie! 👋 I'm here to help you with bug fixes, answer your questions, and guide you on becoming a contributor. Let's squash those bugs together!

To fix the issue where vertical scrolling does not work on mobile web for the react-native-reanimated-carousel, you can use the fixedDirection prop that was introduced to address scroll direction issues.

Here is an example of how you can use the fixedDirection prop:

import Carousel from 'react-native-reanimated-carousel';

<Carousel
  data={data}
  renderItem={renderItem}
  width={width}
  height={height}
  fixedDirection="vertical" // or "horizontal" depending on your requirement
/>

By setting fixedDirection to "vertical", you should be able to fix the vertical scrolling issue on mobile web [1].

To continue talking to Dosu, mention @dosu.

@qwertychouskie
Copy link
Author

That's not what fixedDirection does.

@JenkinsDev
Copy link

Had this issue and almost abandoned, but then found out that you can hook into pan gesture configuration, and adjust the activeOffsetX.

      <Carousel
        ...
        onConfigurePanGesture={(panGesture: PanGesture) => {
          panGesture.activeOffsetX([-20, 20]);
        }} />

@qwertychouskie
Copy link
Author

Had this issue and almost abandoned, but then found out that you can hook into pan gesture configuration, and adjust the activeOffsetX.

      <Carousel
        ...
        onConfigurePanGesture={(panGesture: PanGesture) => {
          panGesture.activeOffsetX([-20, 20]);
        }} />

That's functionally identical to what I linked, it works on iOS and Android, but not web.

@andresouza-maple
Copy link

@JenkinsDev I confirmed it; it doesn't fix mobile web, unfortunately.
@qwertychouskie have you found a solution for that?

@qwertychouskie
Copy link
Author

@qwertychouskie have you found a solution for that?

Not yet, unfortunately.

@MarkKravchuk
Copy link

Had this issue and almost abandoned, but then found out that you can hook into pan gesture configuration, and adjust the activeOffsetX.

      <Carousel
        ...
        onConfigurePanGesture={(panGesture: PanGesture) => {
          panGesture.activeOffsetX([-20, 20]);
        }} />

Thanks buddy, for us this was the solution and resolved the problem!

Good job and thanks!!

@nmassey
Copy link
Contributor

nmassey commented Sep 17, 2024

hey @qwertychouskie - This workaround seems to do the trick for me!

I was able to implement this solution for my RNRC carousel inside of a ScrollView by:

  1. upgrade react-native-gesture-handler to 2.16.0 (or higher) -- note that I don't know whether this might cause any other issues!! - I know specific Expo SDKs prefer certain versions of RNGH
  2. add touchAction="pan-y" prop to the GestureDetector - https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/gesture-detector/#touchaction-web-only

For number 2, one could either patch RNRC ScrollViewGesture.tsx to include it as a property (probably the preferred route), e.g.

    <GestureDetector gesture={gesture} touchAction="pan-y">

but, as a hacky workaround, updating the onConfigurePanGesture callback worked well enough for me. Note that this works by updating the internal state of panGesture, which is, well, not recommended. Use at your own risk!! (See RNGH source code here and here for hints about why this works.)

    <Carousel
      ...
      onConfigurePanGesture={(panGesture: PanGesture) => {
        // fix panGesture so that the carousel works correctly
        // within a ScrollView
        panGesture.config.touchAction = 'pan-y' // for web

        // for iOS and Android
        panGesture.activeOffsetX([-5, 5]);
        panGesture.failOffsetY([-5, 5]);
      }}
    />

I hope this helps get you moving forward? 🙏

Also, this seems to work fine with react-native's ScrollView (so, you shouldn't need to import ScrollView from RNGH unless there's some other reason for it).


Perhaps we can huddle up sometime to discuss a good way to resolve this that'll be more resilient for the long-term.

@qwertychouskie
Copy link
Author

That works perfectly, thanks! Ideally, the settings for both mobile and web would be set by default for the relevant carousel types, but setting it manually works fine for now.

@LunatiqueCoder
Copy link

    <Carousel
      ...
      onConfigurePanGesture={(panGesture: PanGesture) => {
        // fix panGesture so that the carousel works correctly
        // within a ScrollView
        panGesture.config.touchAction = 'pan-y' // for web

        // for iOS and Android
        panGesture.activeOffsetX([-5, 5]);
        panGesture.failOffsetY([-5, 5]);
      }}
    />

This worked for me for mobile web, however, pinch-to-zoom will not work :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants