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