react-native-swiper icon indicating copy to clipboard operation
react-native-swiper copied to clipboard

onMomentumScrollEnd & onTouchStartCapture: wrong index

Open losikov opened this issue 5 years ago • 5 comments

Which OS ?

MacOS: both iOS and Android simulator

Version

Which versions are you using:

Expected behaviour

Valid indexes on swipe forward and back. Actual log using v1.6.0-rc.2 which doesn't have an issue:

LOG index: 1 << yes, 1, as 0 is just dismissed LOG index: 2 LOG index: 3 << just swiped to the last slide LOG index: 2 << going back LOG index: 1 LOG index: 0 << to the beginning

onTouchStartCapture has the same issue.

Actual behaviour

LOG index: 0 << it is an index of second view, expected "1" LOG index: 1 LOG index: 2 << just swiped to the last slide LOG index: 3 << I swiped back, but index is increased LOG index: 2 LOG index: 1 << I'm on the first slide

How to reproduce it>

examples/components/Swiper/index.js with loop={false} doesn't work. I couldn't build and run examples in forked project, too many errors (gyp, not found simulator, etc). So, I gave up fixing them and google solutions, and I just copied and pasted it to my own project.

Steps to reproduce

  1. run the example examples/components/Swiper/index.js with loop={false}
  2. swipe to the end and check log along the way
  3. swipe to the beginning and check log along the way

losikov avatar Jan 12 '20 08:01 losikov

yes,it has this problem!

confidence68 avatar Jan 15 '20 10:01 confidence68

We do get the correct index on expo though, On RN it's giving wrong index as described. Swiper version : 1.5.14 RN: 0.60.5

paddy57 avatar Sep 01 '20 09:09 paddy57

@losikov , I found temporary solution.

  const handleScrollEnd = useCallback((e, state, context) => {
    setTimeout(() => {
      console.log(context.state.index);  // here you will get right index
    });
  }, []);
  
  return (
      <Swiper
        onMomentumScrollEnd={handleScrollEnd}
        containerStyle={styles.wrapper}
        showsPagination={false}
      >
        {t.map((_t, index) => {
          return (
            <View key={index} style={styles.test}>
              <Text>{_t}</Text>
            </View>
          );
        })}
      </Swiper>
  )

ilyarudnitsky avatar Jan 22 '21 15:01 ilyarudnitsky

Not working for me...

@losikov , I found temporary solution.

  const handleScrollEnd = useCallback((e, state, context) => {
    setTimeout(() => {
      console.log(context.state.index);  // here you will get right index
    });
  }, []);
  
  return (
      <Swiper
        onMomentumScrollEnd={handleScrollEnd}
        containerStyle={styles.wrapper}
        showsPagination={false}
      >
        {t.map((_t, index) => {
          return (
            <View key={index} style={styles.test}>
              <Text>{_t}</Text>
            </View>
          );
        })}
      </Swiper>
  )

eat46 avatar Oct 19 '21 02:10 eat46

any update here?

deyanskiq avatar Sep 25 '23 15:09 deyanskiq