question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getCurrentIndex returns wrong value when data count is < 3

See original GitHub issue

Describe 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:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dohooocommented, Nov 4, 2022

Hi, I still get wrong indexes in 3.1.5

And also you need to add autoFillData={false} prop when the data length is less than 3.

0reactions
jb-5murfcommented, Nov 7, 2022

And also you need to add autoFillData={false} prop when the data length is less than 3.

This helped 👍 Thank you!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found