meliorence / react-native-snap-carousel

Swiper/carousel component for React Native featuring previews, multiple layouts, parallax images, performant handling of huge numbers of items, and more. Compatible with Android & iOS.
BSD 3-Clause "New" or "Revised" License
10.33k stars 2.28k forks source link

RTL support #598

Open niloufarMakhzani opened 4 years ago

niloufarMakhzani commented 4 years ago

Is this a bug report, a feature request, or a question?

Question

Thanks for your great library and documentation. I'm using your library but I want to have the autoPlay to slide from right to left. Is there any props to handle this or is it possible for you to make it happen. I managed to do it by editing snapToNext method, but I prefer to use your library using npm so I need it to be added as a prop.

Thanks in advance

rgouzal commented 4 years ago

Did anyone find a workaround for this issue?

rgouzal commented 4 years ago

After reading the following: https://github.com/archriss/react-native-snap-carousel/blob/master/doc/KNOWN_ISSUES.md#rtl-support-experimental

I found a workaround by reversing order of data array calling .reverse() from data array that was passed to data prop of Carousel:

<Carousel ref={(c) => { this._carousel = c}} data={I18nManager.isRTL? cities.reverse() : cities} renderItem={this.renderCarouselCity} sliderWidth={Dimensions.get("window").width * 0.9} itemWidth={Dimensions.get("window").width * 0.7} onSnapToItem={this.onSnapCarousel} />

shababcreative commented 4 years ago

Use useScrollView and firstItem like this:


          <Carousel
            data={this.state.data}
            useScrollView={I18nManager.isRTL? true: false}
            firstItem={I18nManager.isRTL? this.state.data.length-1: 0}
          />
mainak-shil commented 4 years ago

Before attaching list make list mutation reverse. // i found difficulties while reversion with array.reverse()

const imgList = I18nManager.isRTL ? imageList.slice().reverse() : imageList; return ( <Carousel layout={"default"} data={imgList} ...

This works for me

dohooo commented 2 years ago

Sorry, please allow me to advertise for my open source library! ~ I think this library react-native-reanimated-carousel will solve your problem. It is a high performance and very simple component, complete with React-Native reanimated 2