Android 11
Which versions are you using:
onIndexChanged should fire with the correct Index
index in renderPagination should render with correct index
onIndexChanged is not fired at all.
renderPagination is always fired with index equals Zero
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
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,
}}
>
Most helpful comment
This is the workaround that have worked for me:
showsButtons={false}
width is the item width: Dimensions.get('screen').width
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,
}}
>