import { TouchableOpacity,Platform,BackHandler,Image } from 'react-native'
class Dome extends React.Component {
static navigationOptions = ({navigation, screenProps}) => ({
headerTitle: '导航',
headerLeft:(
<TouchableOpacity onPress={()=>navigation.state.params.navigatePress()} style={{padding:10}} >
<Image
source={require('../../../images/icon-arrow-left.png')}
style={{ width: 9, height: 16 }}
/>
</TouchableOpacity>
)
});
_onBackAndroid=()=>{
this.props.navigation.navigate('Home')
return true
}
componentWillMount(){
this.props.navigation.setParams({ navigatePress:this._onBackAndroid })
if (Platform.OS === 'android') {
BackHandler.addEventListener("hardwareBackPress", this._onBackAndroid);
}
}
componentWillUnmount() {
if (Platform.OS === 'android') {
BackHandler.removeEventListener("hardwareBackPress", this._onBackAndroid);
}
}
}
网友评论