gpt4 book ai didi

react-native - 如何使用 react-navigation 的 headerLeft 和 headerRight

转载 作者:行者123 更新时间:2023-12-05 01:17:36 31 4
gpt4 key购买 nike

使用react-navigation,发现headerLeft没有响应?而且没有headerLeft,headerRight

class Message extends React.Component {
static navigationOptions = {
tabBarLabel: '消息',
headerTitle: () => (
<View style={styles.headerWrapper}>
<Text
adjustsFontSizeToFit
style={styles.headerText}>消息</Text>
</View>
),
tabBarIcon: ({ focused, tintColor }) => (
<Image
source={focused ? require('../images/clickmessage.png') :
require('../images/message.png')}
style={{ width: 26, height: 26, tintColor: tintColor }}
/>
),
headerLeft: ({ focused, tinColor }) => {
<Image
source={focused ? require('../images/clickmessage.png') :
require('../images/message.png')}
style={{ width: 26, height: 26, tintColor: tintColor }}
/>
}
};
render() {
return (
<View style={styles.container}>
<MessageContent />
</View>
);
}

headerLeft 和 headerRight 无效

最佳答案

您可以像这样左右使用标题:

static navigationOptions = ({navigation}) => {
return {
headerTitle: (
<View style={{flex: 1, alignSelf: 'center'}}>
<AppFontLoader>
<Text style={{
color: '#fff',
alignSelf: 'center',
...Platform.select({
ios: {
fontFamily: 'Some implemented font',
},
android: {
fontFamily: 'Another font for android',
}
}),
}}>Place you title here</Text>
</AppFontLoader>
</View>
),
headerRight: (
<TouchableOpacity onPress={() => navigation.navigate({routeName: 'PriceList'})}
style={{right: Platform.OS === 'ios' ? Dimensions.get("window").height < 667 ? '10%' : '5%' : '25%', backgroundColor: 'transparent', paddingLeft: 15}}>
<Image style={{width: 25, height: 25}} source={require('../../assets/icons/info2.png')}/>
</TouchableOpacity>
),
headerLeft: (
<TouchableOpacity onPress={() => navigation.goBack(null)} style={{left: Dimensions.get("window").height < 667 ? '8%' : '3%', backgroundColor: 'red', width: '100%'}}>
<Image style={{width: 30, height: 30}} source={require('../../assets/icons/back-icon-50x50.png')}/>
</TouchableOpacity>
),
headerStyle: {
backgroundColor: '#14b6e4',
},
headerTintColor: '#fff',

};
};

关于react-native - 如何使用 react-navigation 的 headerLeft 和 headerRight,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49629150/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com