react-native-swiper
react-native-swiper copied to clipboard
onIndexChanged does not fire on android
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 }}
/>
);
};
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 <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, }}
Here what is setActiveItemIndex ?