在最外部聲明:
let that;
在class內(nèi)部:
constructor(props){
super(props);
that = this;
}
在const * = StackNavigation({})中:
navigationOptions:{
headerTitle: (
<TouchableOpacity
style={{width: width - 80, alignItems: 'center'}}
>
<Text>123</Text>
</TouchableOpacity>
),
headerRight: (
<TouchableOpacity
style={{
justifyContent: 'center',
width: 80,
height: 50,
alignItems: 'center'
}}
onPress={()=>that.props.navigation.navigate('Msg')}
>
<Image
style={{
height: 20,
width: 25,
}}
source={require('./icons/msg-icon.png')}
/>
</TouchableOpacity>
),
headerLeft: (
<TouchableOpacity
style={{
justifyContent: 'center',
width: 80,
height: 50,
alignItems: 'center'
}}
onPress={() => that.props.navigation.navigate('Find')}
>
<Image
style={{
height: 25,
width: 25,
}}
source={require('./icons/find-icon.png')}
/>
</TouchableOpacity>
),