React-native-swiper: onIndexChanged does not fire on android

Created on 23 Nov 2020  Â·  2Comments  Â·  Source: leecade/react-native-swiper

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 }}
      />
    );
  };

Most helpful comment

This is the workaround that have worked for me:
width is the item width: Dimensions.get('screen').width
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,
}}
>

All 2 comments

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

This is the workaround that have worked for me:
width is the item width: Dimensions.get('screen').width
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,
}}
>

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kylehagler picture kylehagler  Â·  3Comments

nicolabortignon picture nicolabortignon  Â·  3Comments

ghost picture ghost  Â·  3Comments

tokict picture tokict  Â·  3Comments

commit-master picture commit-master  Â·  3Comments