react-native-snap-carousel icon indicating copy to clipboard operation
react-native-snap-carousel copied to clipboard

onSnapToItem wrong Index (RTL mode, Android)

Open AbanoubNassem opened this issue 6 years ago • 5 comments

when using RTL or inverted , what happen is , it invertes the indices as well, so if the data array is [0,1,2,3,4] becomes [4,3,2,1,0] , which is wrong , because despite the fact the carousel showing the layout in LTR or RTL fashion, the index should be the same!

also trying to disable inversion using inverted={false} not working, any suggestions here?

EDIT: only happens on Android

AbanoubNassem avatar Sep 15 '19 08:09 AbanoubNassem

Is it working properly if you change this line to return false;?

bd-arc avatar Sep 16 '19 12:09 bd-arc

@bd-arc nope , unfortunately it didn't fix the issue!

AbanoubNassem avatar Oct 06 '19 11:10 AbanoubNassem

try setting inverted to true in rtl

mohshafie avatar Jul 29 '21 13:07 mohshafie

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

dohooo avatar Oct 08 '21 05:10 dohooo

this line in function _needsRTLAdaptations in Carousel.tsx or Carousel.js in snap_carousel src folder is causing error: error line: return IS_RTL && IS_ANDROID && !vertical;

convert the line into => return IS_RTL && IS_ANDROID && !vertical;

so the function should now look like this _needsRTLAdaptations () { const { vertical } = this.props; return IS_RTL && !IS_ANDROID && !vertical; }

it has fixed the issue in case of rtl on my end

make sure you do this as well: onSnapItem(index => setActiveSlide(isRtl ? data.length - 1 -index : index))

Sheharyar3364 avatar Jan 01 '25 09:01 Sheharyar3364