Skip to content

Question for “Props” #813

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

Open
Shahidunofficial opened this issue May 17, 2025 · 1 comment
Open

Question for “Props” #813

Shahidunofficial opened this issue May 17, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@Shahidunofficial
Copy link

is it feasible to sync the scroll of two carosels using rnrc

Copy link

dosubot bot commented May 17, 2025

Hello @Shahidunofficial! I'm Dosu, your friendly bot here to help you with bugs, questions, and contributions while you wait for a human maintainer. Let’s dive into your issue!

Yes, it is feasible to synchronize the scroll of two carousels using react-native-reanimated-carousel. You can achieve this by utilizing useSharedValue and useAnimatedReaction hooks. Here's a brief overview of how you can do it:

  1. Initialize a Shared Value: Create a shared value to hold the scroll position that both carousels will use.

    const sharedScrollPosition = useSharedValue(0);
  2. Set Up Animated Reaction: Use useAnimatedReaction to update the scroll position of the second carousel whenever the first carousel's scroll position changes.

    useAnimatedReaction(
      () => sharedScrollPosition.value,
      (currentScrollPosition) => {
        // Update the second carousel's scroll position
        secondCarouselScrollHandler.value = currentScrollPosition;
      }
    );
  3. Attach Shared Value to Carousels: Ensure that the first carousel updates the sharedScrollPosition whenever it scrolls, and the second carousel uses this shared value to set its scroll position.

    // First carousel
    <Carousel
      onScroll={Animated.event(
        [{ nativeEvent: { contentOffset: { x: sharedScrollPosition } } }],
        { useNativeDriver: true }
      )}
      // other props
    />
    
    // Second carousel
    <Carousel
      scrollHandler={secondCarouselScrollHandler}
      // other props
    />

By using these hooks, you can effectively synchronize the scroll positions of two carousels [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot dosubot bot added the enhancement New feature or request label May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant