浏览contentOffset

时间:2018-11-06 20:21:03

标签: javascript reactjs react-native

我正在使用向后导航功能,当您向下滚动然后状态更新时,该功能可以返回到先前的屏幕。但是以下方法不起作用?我在做什么错了?

componentDidUpdate(){

    const scrollY = this.state.scrollY

    if(scrollY > -300 && scrollY < -100){
      this.props.navigation.goBack()
    }

}

ScrollView的onScroll更改很简单,如下所示:

render(){

const scrollY = this.state.scrollY
this.startHeaderHeight = 80
this.endHeaderHeight = 50

this.animatedHeaderHeight = scrollY.interpolate({
  inputRange: [0, 50],
  outputRange: [this.startHeaderHeight, this.endHeaderHeight],
  extrapolate: 'clamp'
})
 return (
  <ScrollView
    scrollEventThrottle={16}
    onScroll={Animated.event([
      { nativeEvent: { contentOffset: { y: this.state.scrollY } } }
    ])}
  >
 )
}

例如,可以很好地更改如下视​​图的样式:

<Animated.View style={{ height: this.animatedHeaderHeight}}>
</Animated.View>

0 个答案:

没有答案
相关问题