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.

when I use snapToItem(index, false) with X > 3, It was usually return me to my Index then turn back to Index 0. I don’t know why?, I don’t add any props

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:18
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
fattomhkcommented, Jun 15, 2020

If you are facing : it would snap to 0 slide when you are trying to snap to position x

simply add prop: getItemLayout to calculate offset.

example:

getItemLayout={(data, index) => (
              {length: viewportWidth, offset: viewportWidth * index, index}
)}
1reaction
kevinvugtscommented, Oct 29, 2019

@bd-arc I found out that this._enableLoop() function in the library is nowhere to be found. Is this on purpose?

Update

I changed the snapToItemFunction to:

snapToItem (index, animated = true, fireCallback = true) {
        const itemsLength = this._getCustomDataLength();
        const { loop, loopClonesPerSide } = this.props;

        if (!index || index < 0) {
            index = 0;
        }

        let positionIndex = this._getPositionIndex(index);
        let newIndex = loop ? positionIndex - loopClonesPerSide : positionIndex;

        if (positionIndex === this._activeItem) {
            return;
        }

        this._snapToItem(newIndex, animated, fireCallback);
    }

And the above code seems to work properly. However it does interfere with the snapToNext() and snapToPrevious methods

Read more comments on GitHub >

github_iconTop Results From Across the Web

Snap Carousel snapToItem bug Android - Snack
Snap Carousel snapToItem bug Android. No description. Open with Expo Go. Open in editor. Need Expo? Don't have the Expo Go? Download the...
Read more >
react-native-snap-carousel/CHANGELOG.md - UNPKG
30, * Fix `snapToItem` call that results in snapping to the wrong item when `loop` is ... 157, * Prevent error when carousel...
Read more >
[#QTBUG-64496] SnapToItem in ListView not correct - Qt Bug Tracker
Please look a the screenshot I've attached. There are two ListViews with rectangles. For both ListViews snapMode is SnapToItem. On the left everything...
Read more >
archriss - Bountysource
Is this a bug report, a feature request, or a question? ... snapToItem/snapToNext not working on Android devices when called from callbacks inside...
Read more >
React Native Snap Carousel - First Item - Stack Overflow
310 : 332} firstItem={22} initialScrollIndex={23} onLayout={() => { this._carousel.snapToItem(22); }} />. react-native · react-native-snap- ...
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