React native 组件标题中的图标未显示
我按照以下步骤在组件标题中添加一个加号+:React native 组件标题中的图标未显示,react-native,react-navigation,React Native,React Navigation,我按照以下步骤在组件标题中添加一个加号+: import React, { Component} from 'react'; import { SectionList, View, Image, StyleSheet, Text, TouchableOpacity, Platform, TouchableHighlight, AppRegistry } from 'react-native'; import {Icon } from "react-native-elements"; expor
import React, { Component} from 'react';
import { SectionList, View, Image, StyleSheet, Text, TouchableOpacity, Platform, TouchableHighlight, AppRegistry } from 'react-native';
import {Icon } from "react-native-elements";
export default class Event extends React.Component {
static navigationOptions = ({navigation}) => {
console.log("in event header");
return {
headerTitle: 'Event',
headerRight: (
<TouchableOpacity>
<Icon
name="plus"
size={30}
type='octicon'
onPress={navigation.getParam('navToNewEvent')}
/>
</TouchableOpacity>
),
};
}
_navToNewEvent = () => {
console.log("Route to new event");
this.props.navigation.navigate("NewEvent");
};
async componentDidMount(){
this.props.navigation.setParams({ navToNewEvent: this._navToNewEvent })
....
}
简单地看一下代码似乎没有错。有一个陷阱。您想修改这个吗
静态导航选项=({navigation})=>{
日志(“在事件头中”);
返回{
标题:“事件”,
头灯:(
navigation.getParam('navToNewEvent')}
/>
),
};
}
您可以使用defaultNavigationOptions
您表示的事件选项卡不是单个屏幕。作为常用标题,在defaultNavigationOptions中配置标题和按钮
defaultNavigationOptions:({navigation})=>({
...
标题:“事件”,
头灯:(
),
您必须将onPress={()=>navigation.getParam('navToNewEvent')}
向上移动到TouchableOpacity
,同时尝试为图标添加颜色。我注释掉了onPress
,加号仍然没有显示。您尝试添加颜色了吗?颜色={tintColor}没有执行任何操作。加号仍然不显示。根据文档,调用getParam的任何方法都可以。问题是加号没有显示。我尝试更改代码。是否尝试此操作?问题是没有显示图标。更改onPress的调用模式后没有区别。两种调用模式都是pr在官方文件中显示。。我在新闻稿中对整个内容进行了注释,也没有任何区别。@user938363我更改了名称标题=>标题@user938363我可以查看您的导航器设置文件代码吗?
return createBottomTabNavigator(
{
Event: {screen: EventStack},
Group: {screen: GroupStack},
Contact: {screen: ContactStack},
}, bottomTabNavOptions
);
const bottomTabNavOptions = {
defaultNavigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
console.log("route name", routeName);
let iconName;
if (routeName === 'Event') {
iconName = `list-unordered`;
} else if (routeName === 'NewEvent') {
iconName = "kebab-horizontal";
} else if (routeName === 'NewUser') {
iconName = `person`;
} else if (routeName === 'ListUser') {
iconName = `organization`
}
return <Icon name={iconName} size={30} color={tintColor} type='octicon' />;
},
}),
tabBarOptions: {
activeTintColor: 'tomato',
inactiveTintColor: 'gray',
},
};
const EventStack = createStackNavigator({
Event: {
screen: EventWithSelf,
navigationOptions: {
title: 'Event',
},
},
NewEvent: {
screen: NeweventWithSelf,
navigationOptions: {
title: 'New Event',
},
},
EditEvent: {
screen: EditEventWithSelf,
navigationOptions: {
title: 'Edit Event',
},
},
Chat: {
screen: ChatWithSocket,
navigationOptions: {
title: 'Chat',
},
},
});