javascript - React Native 如何在同一个动画事件中传递两个事件?

标签 javascript reactjs react-native

我有两个 Action 通过 setParams 传递

componentWillMount() {
                  this.props.navigation.setParams({
                    animatedValue: this._animatedValue.interpolate({
                    inputRange: [0, 800],
                    outputRange: [0, -70],
                    extrapolate: 'clamp'
                  }),
                  colorRange: this.x.interpolate({
                    inputRange: [0, 5,10,15,20,25,30,35,40,49,56],
                    outputRange: ['rgba(0, 0, 0,0)', 'rgba(255, 0, 0,0.1)', 'rgba(255, 0, 0,0.2)', 'rgba(255, 0, 0,0.3)', 'rgba(255, 0, 0,0.4)', 'rgba(255, 0, 0,0.5)', 'rgba(255, 0, 0,0.6)', 'rgba(255, 0, 0,0.7)', 'rgba(255, 0, 0,0.8)', 'rgba(255, 0, 0,0.9)' ,'rgba(255, 0, 0,1)'],
                    extrapolate: 'clamp'
                  })
                });
                }

并且在我只使用一个动画事件中。垂直滚动时如何使用这两个事件

<ScrollView onScroll={ Animated.event([{nativeEvent: {contentOffset: {y: this._animatedValue }}}] )} scrollEventThrottle={16} >

最佳答案

由于 Animated.event 接受您想要的任意多个参数,并且您将 nativeEvent 或自定义监听器传递给它,让我们试试这个:

<ScrollView onScroll={ Animated.event(
  [{nativeEvent: {contentOffset: {y: this._animatedValue }}}],
  { listener: this._customListener },
)} scrollEventThrottle={16}>

让你的听众喜欢:

_customListener(e) {
  // do whatever you want using this.colorRange
}

关于javascript - React Native 如何在同一个动画事件中传递两个事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47201183/

相关文章:

javascript - 使用 html-pdf-node 渲染的 pdf 中未显示 CSS 和图像

javascript - 如何在 openlayers 上显示缩放级别(仅限 js/html 文件)?

javascript - 如何使用正则表达式 javascript 以通用形式提取值

javascript - React js中的复选框不会改变

javascript - 传递给 createStore 的 preloadedState 参数具有意外类型 "Null"。预期参数是具有以下键的对象 : "login"

react-native - react-navigation 3 在嵌套堆栈中重置

javascript - 如何在 googlechart api 中添加函数 SelectHandler

javascript - React Redux - 从 Immutable 渲染时, Prop 未定义

javascript - 单击按钮显示新组件

android - 找不到Gradle插件