leecade / react-native-swiper

The best Swiper component for React Native.
MIT License
10.4k stars 2.34k forks source link

onIndexChanged does not fire on android #1248

Open IIslam opened 3 years ago

IIslam commented 3 years ago

Which OS ?

Android 11

Version

Which versions are you using:

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 }}
      />
    );
  };
rock8808 commented 3 years ago

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

Wael-Zoaiter commented 3 years ago

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, }}

Ritikkk-09 commented 2 years ago

Here what is setActiveItemIndex ?