【问题标题】:How can I detect when the user gets a View and do something after getting this position on React Native?在 React Native 上获得这个位置后,如何检测用户何时获得视图并执行某些操作?
【发布时间】:2020-04-23 17:27:55
【问题描述】:

我有一个 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>

【问题讨论】:

    标签: react-native animation view position scrollview


    【解决方案1】:

    您可以使用FlatList,而不是使用ScrollView,这为您尝试执行的索引类型提供了更多支持。

    要检测用户何时到达特定点,您可以使用 onViewableItemsChanged 并定义屏幕上需要哪些可视项目才能触发动画。

    FlatLists 还支持许多内置动画,例如 scrollToEndScrollToIndex,这可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-12
      • 2021-02-07
      • 1970-01-01
      • 2020-08-23
      • 2017-03-29
      • 1970-01-01
      相关资源
      最近更新 更多