getCurrentIndex returns wrong value when data count is < 3
See original GitHub issueDescribe the bug In my project I have map with markers and carousel with detail of selected marker. Swiping the carousel moves the map to the next (previous) marker. When I use onSnapToItem to set new index it’s quite slow because the event is fired after the swipe is fully completed. So I decided to set the current index using getCurrentIndex in onProgressChange. It works great if data count is 3 or more. But when looping carousel with 2 items I get indexes 0, 1, 2, 3, 0, 1, 2, 3… instead of 0, 1, 0, 1, 0, 1…
To Reproduce
import React, { useRef } from 'react';
import { View, Dimensions } from 'react-native';
import Carousel from 'react-native-reanimated-carousel';
const colors = ['red', 'green'];
export default function App() {
const carouselRef = useRef();
return (
<Carousel
ref={carouselRef}
data={colors}
renderItem={({ item }) => <View style={{ flex: 1, backgroundColor: item }} />}
width={Dimensions.get('window').width}
onProgressChange={(offsetProgress, absoluteProgress) => {
const index = carouselRef?.current?.getCurrentIndex();
console.log(index);
}}
/>
);
}
Expected behavior Get right current index.
Versions (please complete the following information):
- react: v18.0.0
- react-native: v0.69.6
- react-native-reanimated: v2.9.1
- react-native-reanimated-carousel: v3.1.3
- react-native-gesture-handler: v2.5.0
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
INDEX returns wrong value and no value - Stack Overflow
Having that data, I want to get a separate table with two Columns(Name and training). In Column C, I want the names and...
Read more >Solved: Re: Splunk - Stat count return wrong values
- I send 3 JSON events. Each event has one "correlationId" top-level JSON field with the same value. So filtering on that corelationId...
Read more >QComboBox Class | Qt Widgets 6.4.1 - Qt Documentation
Returns the data for the given role in the given index in the combobox, or an invalid QVariant if there is no data...
Read more >total hit count is wrong for exists query · Issue #89760 - GitHub
The returned hits a alright, but the value value in the total relation object is wrong. This worked in 8.3.3, but erros in...
Read more >Using foreach with index in C# - Thomas Levesque's .NET Blog
Just a quick tip today! for and foreach loops are among the most useful constructs in a C# developer's toolbox. To iterate a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
And also you need to add
autoFillData={false}
prop when the data length is less than 3.This helped 👍 Thank you!