dohooo / react-native-reanimated-carousel

🎠 React Native swiper/carousel component, fully implemented using reanimated v2, support to iOS/Android/Web. (Swiper/Carousel)
https://react-native-reanimated-carousel.vercel.app
MIT License
2.85k stars 329 forks source link

Nested sliders #637

Closed StefSchalks closed 4 months ago

StefSchalks commented 4 months ago

Hey, I've been digging into this library a bit lately and it works pretty well. There's one thing that I'm wondering. For my implementation, I need two nested horizontal carousels (something like this: https://naver.github.io/egjs-flicking/Demos#nested-flickings). I'd appreciate to hear if this is possible or not. Thanks in advance.

dosubot[bot] commented 4 months ago

Hey @StefSchalks! I'm here to help you with any issues or questions you have. I can assist with bug fixes, code improvements, and more. Let me know how I can help!

Yes, it is possible to create nested horizontal carousels using the react-native-reanimated-carousel library. Here are some best practices and configurations to ensure smooth functionality:

  1. Flexbox Layout: Use flex: 1 to ensure that the carousel takes up the available space within its parent container.
  2. Width and Height: Set explicit width and height for the carousel to ensure it renders correctly.
  3. Alignment: Use alignItems and justifyContent to center the carousel items.

Here is an example configuration:

<View style={{ flex: 1 }}>
  <Carousel
    style={{
      width: "100%",
      height: 240,
      alignItems: "center",
      justifyContent: "center",
    }}
    width={280}
    height={210}
    pagingEnabled={true}
    snapEnabled={true}
    mode="horizontal-stack"
    loop={true}
    autoPlay={false}
    autoPlayReverse={false}
    data={[...new Array(6).keys()]}
    modeConfig={{
      snapDirection: "left",
      stackInterval: 18,
    }}
    customConfig={() => ({ type: "positive", viewCount: 5 })}
    renderItem={({ index }) => (
      <SBItem
        index={index}
        key={index}
        entering={FadeInRight.delay((5 - index) * 100).duration(200)}
      />
    )}
  />
</View>

This configuration ensures that the carousel is centered and takes up the appropriate amount of space within its container [1].

To continue talking to Dosu, mention @dosu.