react-native - 我如何在我的滚动视图上放置点
问题描述
我正在使用以下代码在其底部显示滚动视图和点。现在我想在我的滚动视图上方显示这些点,但我不知道该怎么做。
我的代码
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<View
style={{ width, height: width }}
>
<ScrollView
horizontal={true}
pagingEnabled={true}
showsHorizontalScrollIndicator={false}
onScroll={Animated.event(
[{ nativeEvent: { contentOffset: { x: this.scrollX } } }]
)}
scrollEventThrottle={16}
>
{this.state.dataSource.map((source, i) => {
return (
<Image
key={i}
style={{ width, height: width }}
source={{uri: source.image}}
/>
);
})}
</ScrollView>
</View>
<View
style={{ flexDirection: 'row' }}
>
{this.state.dataSource.map((_, i) => {
let opacity = position.interpolate({
inputRange: [i - 1, i, i + 1],
outputRange: [0.3, 1, 0.3],
extrapolate: 'clamp'
});
return (
<Animated.View
key={i}
style={{ opacity, height: 5, width: 5, backgroundColor: '#595959', margin: 2, borderRadius: 5 }}
/>
);
})}
</View>
</View>
解决方案
我假设您仍在学习 react-native/react。您已经想出了一半的解决方案,您只需要将点视图放在滚动视图上方:
render(){
return(
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<View
style={{ width, height: width }}
>
{this.renderDotsView(this.state.dataSource, position)}
<ScrollView
horizontal={true}
pagingEnabled={true}
showsHorizontalScrollIndicator={false}
onScroll={Animated.event(
[{ nativeEvent: { contentOffset: { x: this.scrollX } } }]
)}
scrollEventThrottle={16}
>
{this.state.dataSource.map((source, i) => {
return (
<Image
key={i}
style={{ width, height: width }}
source={{uri: source.image}}
/>
);
})}
</ScrollView>
</View>
</View>
)}
renderDotsView = (array, position) =>{
return(
<View
style={{ flexDirection: 'row' }}
>
{array.map((_, i) => {
let opacity = position.interpolate({
inputRange: [i - 1, i, i + 1],
outputRange: [0.3, 1, 0.3],
extrapolate: 'clamp'
});
return (
<Animated.View
key={i}
style={{ opacity, height: 5, width: 5, backgroundColor: '#595959', margin: 2, borderRadius: 5 }}
/>
);
})}
</View>
)
}
推荐阅读
- r - R sumif 基于多个条件
- matlab - 如何在使用 MATLAB Class 文件夹创建的类对象中公开成员?
- html - 选择所有跨区文本时如何获取元素?
- amazon-web-services - 如何从 CloudFormation 模板中检索 AWS 账户名称?
- django - django.db.models.query_utils.InvalidQuery:原始查询必须包含主键
- powerbi - power bi 的 power 查询中的 SUMIFS,有两个不同的表,没有主键
- sql-server - VB.net 参数化查询使用 sp_executesql 但丢失 UTF8 字符
- firebase - 授予用户对特定子域的访问权限
- angular - 分页器始终设置在第一页primeng
- javascript - TypeError: undefined is not an object (evalating 'addTodo(title, description).then') in React Native