【发布时间】:2020-03-23 18:20:43
【问题描述】:
我正在使用 this 包在 React Native 中创建 Swiper。
我使用了静态数据并且它正在工作,但现在我正在从服务器获取数据并将其保存为Array 的状态。
问题是当在 swiper 内映射数据以创建动态滑块时,它没有显示任何内容,但如果我在 Swiper 之外执行它,它正在呈现。
我该如何解决这个问题?
<Swiper
from={0}
minDistanceForAction={0.1}
controlsProps={{
dotsTouchable: true,
prevPos: 'left',
nextPos: 'right',
nextTitle: '',
prevTitle: '',
dotsWrapperStyle: { marginTop: ScaleHelpers.CalcHeight(8), width: ScaleHelpers.CalcWidth(7), height: ScaleHelpers.CalcHeight(7), borderRadius: ScaleHelpers.CalcWidth(7) },
dotActiveStyle: { width: ScaleHelpers.CalcWidth(7), height: ScaleHelpers.CalcHeight(7), borderRadius: ScaleHelpers.CalcWidth(7) },
}}
>
{
this.state.notifications.map((notif, index) => {
return (
<View style={[styless.slideContainer]}>
<Card transparent style={{
flex: 0,
elevation: 3,
shadowColor: "#000",
shadowOpacity: 0.1,
shadowOffset: { width: 0, height: 2 },
shadowRadius: 1.0,
}}>
<CardItem
style={{ paddingTop: ScaleHelpers.CalcHeight(14), paddingLeft: ScaleHelpers.CalcWidth(14), paddingBottom: ScaleHelpers.CalcHeight(14) }}
>
<Left>
<View style={{
width: ScaleHelpers.CalcWidth(60),
height: ScaleHelpers.CalcHeight(60),
borderRadius: ScaleHelpers.CalcWidth(60) / 2,
margin: 0,
padding: 0,
justifyContent: 'center',
backgroundColor: '#FF004E',
elevation: 5,
shadowColor: "#000",
shadowOpacity: 0.1,
shadowOffset: { width: 0, height: ScaleHelpers.CalcHeight(2) },
shadowRadius: 1.0,
}}>
<Image source={bmwerror} style={{ alignSelf: 'center' }} />
</View>
<Body style={{ marginLeft: ScaleHelpers.CalcWidth(23) }}>
<Text style={styles.cardUpperText}>{notif.msg}</Text>
<Text style={styles.cardLowerText}>{notif.axle}{notif.side}</Text>
</Body>
</Left>
</CardItem>
</Card>
</View>
)
})
}
</Swiper>
【问题讨论】:
标签: react-native swiper