react-native - 滚动 ScrollView 时动画高度

标签 react-native animation

因此,当用户滚动特定的 ScrollView 时,我试图通过更改 View 的高度来为 View 设置动画。它在 IOS 上看起来不错,虽然它有一些抖动,但闪烁在 Android 上非常明显。这是我的代码。

Scrollview 处于滚动状态

 onScroll={(e) => {         
     this.state.profileTabAnimatedValue.setValue(e.nativeEvent.contentOffset.y);
 }}

高度插值对象

const headerHeight = this.state.profileTabAnimatedValue.interpolate({
      inputRange: [0,1],
      outputRange: [1,100]
});

然后我会将 headerHeight 应用到 View 以调整它的高度

最佳答案

尝试使用动画事件方法:

onScroll={Animated.event(
  [{nativeEvent: {contentOffset: {y: this.state.profileTabAnimatedValue}}}]
)}

此外,如果您不想要一些奇怪的行为,例如负高度等,请将其添加到您的插值中:

const headerHeight = this.state.profileTabAnimatedValue.interpolate({
      inputRange: [0,1],
      outputRange: [1,100]
      extrapolate: 'clamp'
});

最后一件事是,您可以使用 scrollEventThrottle 来限制在 ScrollView 上触发的事件,请阅读 this

关于react-native - 滚动 ScrollView 时动画高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51996940/

相关文章:

java - ValueAnimator 让一个元素消失?

react-native - 是否可以通过托管工作流程将 Apple 和/或 Firebase 推送通知集成到 React Native/Expo 应用程序?

react-native - 无法找到 EventDispatcher React Native 的模块

reactjs - Stripe react native : Merchant display name cannot be an empty string

angularjs - react native 与 ionic 2

java - 在 Animation EditText 专注于输入之后

javascript - 如何从对象中映射唯一且不重复的项目

javascript - jQuery Animate 中不需要的延迟

jquery - 我怎样才能让动画跟随我的光标

javascript - Angular 动态组件动画离开不起作用