【问题标题】:React native Animated Value this.props.onScroll is not a function反应原生动画值 this.props.onScroll 不是一个函数
【发布时间】:2021-08-20 07:26:27
【问题描述】:

我怎么能理解scrollY是一个空节点,我不明白为什么

const scrollY= new Animated.Value(0)
const onScroll = Animated.event([{ nativeEvent: { contentOffset: { y: scrollY } } }], {
    listener: (event: any) => console.log('listerner', event),
    useNativeDriver: false,
  });
 <ScrollView       
            scrollEventThrottle={16}
              onScroll={onScroll}>
content....
            </ScrollView>

在 console.log 中滚动

AnimatedValue {__lastLoopID: {…}, 
__memoizedValue: {…}, 
__children: Array(0),
 __nodeID: 1190, 
__nodeConfig: {…},
 …}__children: (9)
 [AnimatedOperator, AnimatedOperator, AnimatedCallFunc, AnimatedOperator, AnimatedOperator, AnimatedCallFunc, AnimatedOperator, AnimatedOperator, AnimatedCallFunc]__initialized: true__inputNodes: undefined__lastLoopID: {"": -1}__memoizedValue: {"": null}__nodeConfig: {type: "value", value: 0}__nodeID: 1190_animation: null_constant: false_startingValue: 0_value: 0[[Prototype]]: InternalAnimatedValue

【问题讨论】:

    标签: react-native animation onscroll


    【解决方案1】:

    我不知道您要做什么,但也许您可以尝试从这里开始:

     function handleScroll(event){
    console.log(event)
    }
    
    <ScrollView       
                scrollEventThrottle={16}
                  onScroll={(e) => handleScroll(e)}>
    content....
                </ScrollView>
    

    这就是我获得滚动 y 位置的方式。

    【讨论】:

      猜你喜欢
      • 2021-12-08
      • 1970-01-01
      • 1970-01-01
      • 2021-09-05
      • 2022-01-04
      • 2020-03-23
      • 2018-02-27
      • 2015-08-06
      • 2022-11-04
      相关资源
      最近更新 更多