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

onIndexChanged does not fire on android

Open IIslam opened this issue 4 years ago • 3 comments

Which OS ?

Android 11

Version

Which versions are you using:

  • react-native-swiper v ^1.6.0
  • react-native v https://github.com/expo/react-native/archive/sdk-39.0.3.tar.gz
  • expo v ^39.0.0

Expected behaviour

onIndexChanged should fire with the correct Index index in renderPagination should render with correct index

Actual behaviour

onIndexChanged is not fired at all. renderPagination is always fired with index equals Zero

How to reproduce it>

This is the component Used

const swiper = ()=>
( <Swiper
            onIndexChanged={onImageIndexChange}
            renderPagination={(index, total, context) => {
              console.log(index, total, context);
              return (
                <View>
                  <Text >
                    {index}/{total}
                  </Text>
                </View>
              );
            }}
          >
         {images.map(renderImage)}
    </Swiper>);`

const   onImageIndexChange = (index) => {
    console.log(index);
    // this.setState({currentImageIndex:index})
  };

const  renderImage = (image, index) => {
    const uri = `${imagePath}${image}`;
    return (
      <Image
        key={index}
        resizeMode={"stretch"}
        source={{ uri }}
      />
    );
  };

IIslam avatar Nov 23 '20 08:11 IIslam

src/index.js 文件 line303 修改为 const offset = (this.internals.offset = {x:0, y:0})

rock8808 avatar Dec 31 '20 07:12 rock8808

This is the workaround that have worked for me: width is the item width: Dimensions.get('screen').width <Swiper showsButtons={false} showsPagination={false} height={150} index={activeItemIndex} onMomentumScrollEnd={e => setActiveItemIndex(e.nativeEvent.contentOffset.x / width)} containerStyle={{ position: 'absolute', zIndex: 1, left: 0, right: 0, bottom: BOTTOM_TAB_BAR_HEIGHT, }}

Wael-Zoaiter avatar Apr 02 '21 19:04 Wael-Zoaiter

Here what is setActiveItemIndex ?

Ritikkk-09 avatar Jul 15 '22 06:07 Ritikkk-09