react-native 滑动ScrollView 隐藏导航
import React from ‘react’
import {View, Text, ScrollView, Button, StyleSheet,Animated} from ‘react-native’
import { observer, inject } from ‘mobx-react’
@inject([‘homeStore’])
@observer
class HomePage extends React.Component{
static navigationOptions = {
title: ‘Home’,
header: null,
};
constructor() {
super();
this.state = {
headerTop: new Animated.Value(0)
}
}
componentWillMount() {
// P.S. 270,217,280区间的映射是告诉interpolate,所有大于270的值都映射成-50
// 这样就不会导致Header在上滑的过程中一直向上滑动了
this.top = this.state.headerTop.interpolate({
inputRange: [0, 270, 271, 280],
outputRange: [0, -65, -65, -65]
});
this.animatedEvent = Animated.event([
{
nativeEvent: {
contentOffset: { y: this.state.headerTop }
}
}
])
}
_onPress = () => {
this.props.navigation.navigate('Detail')
};
onScroll &#