设定值:
constructor(props) {
super(props);
this.state = {
navBartoggle: false, // 导航判断
}
}
改变值:
this.setState({navBartoggle:true})
<ScrollView
style={{flex: 1,position: 'relative'}}
onScroll = {(event)=>{{
// console.log(event.nativeEvent.contentOffset.x);//水平滚动距离
console.log(event.nativeEvent.contentOffset.y);//垂直滚动距离
if (event.nativeEvent.contentOffset.y > 200) {
this.setState({navBartoggle:true})
}else if (event.nativeEvent.contentOffset.y <= 200) {
this.setState({navBartoggle:false})
}
}}}
scrollEventThrottle = {20}>
判断值:
navBar() {
if (this.state.navBartoggle === false) {
return(
<Head barStyle={'dark-content'} animated={true} hidden={false} backgroundColor={'#fff'}
/>
)
} else if (this.state.navBartoggle === true) {
return(
<Head barStyle={'dark-content'} animated={true} hidden={false} backgroundColor={'#fff'}
headTitle={'12345678'}/>
)
}
}