react-native - 在 React Native 上获得这个位置后,如何检测用户何时获得视图并执行某些操作?
问题描述
我有一个 ScrollView,里面有一些 View,但是我想在用户到达特定 View 并在它启动我的动画之后启动动画。
例子:
<ScrollView style={{ width: DeviceWidth, height: DeviceWidth * 0.5 }}>
{/* When user position scroll is here,
is where I want to start the animation,
not since the page is loaded */}
<View style={{
width: DeviceWidth * 0.4,
height: DeviceWidth * 0.4,
resizeMode: "contain",
}}>
<ProgressBarAnimated
width={barWidth}
value={65}
backgroundColor="#F68D29"
height={40}
barAnimationDuration={6000}
/>
</View>
</ScrollView>
解决方案
ScrollView
您可以使用 a 而不是使用 a ,FlatList
这为您尝试执行的索引类型提供了更多支持。
要检测用户何时到达特定点,您可以使用onViewableItemsChanged
并定义哪些可视项目需要在屏幕上以触发动画。
FlatLists
还支持许多内置动画,例如scrollToEnd
或ScrollToIndex
可能有帮助。
推荐阅读
- image - TensorFlow、Keras:测试图像大于训练图像
- laravel - 无法在项目根目录中运行 composer 命令
- python-3.x - 我可以在不调用蜘蛛的情况下使用 Scrapy 吗?
- javascript - 使用 flatMap 订阅 onComplete 永远不会完成
- eclipse - 如何在 Eclipse 4.2 中安装 Perforce 插件
- ruby-on-rails - Rails 操作视图表单助手“f.email_field”未显示与同一页面上的其他助手相同的格式
- javascript - 如何将过滤器应用于照片并将其保存到数据库 php css javascript
- php - 在 Yii2 基本应用程序控制器中接收 Json 数据
- r - 如何在 R 中的 ggsurvplot/survminer 的 x 轴上添加特定值?
- ios - 仅触发最后添加的通知