反应导航,道具验证中缺少 tintColor
React-navigation, tintColor is missing in props validation
我已将我的反应导航代码放入一个单独的 Routes 文件中,然后将其导入到我的 App.js 文件中。一切正常,但我在 Atom/Nuclide 中使用 Airbnb ESLint 配置,但 tintColor 出现错误...
"tintColor is missing in props validation"
试过这个:
Routes.propTypes = { 颜色: PropTypes.string.isRequired,}
然后报错"tintColor PropType is defined but prop is never used"
这是代码的一部分
const Routes = () = {
const ContentNavigator = TabNavigator(
{
Profile: { screen: ProfileStack },
History: { screen: HistoryStack },
Questions: {
screen: QuestionsStack,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon name="question-circle" type="font-awesome" size={20} color=
{tintColor} />
),
},
},
Notifications: { screen: NotificationsStack },
},
{
initialRouteName: 'Profile',
swipeEnabled: true,
tabBarOptions: {
activeTintColor: COLOR_PRIMARY,
},
backBehavior: 'none',
});
您可以为它创建一个额外的 Functional Component, add PropTypes
并在您的主要组件中使用。例如:
...
import PropTypes from 'prop-types';
...
const QuestionsTabBarIcon = ({ tintColor }) => (
<Icon name="question-circle" type="font-awesome" size={20} color={tintColor} />
);
QuestionsTabBarIcon.propTypes = {
tintColor: PropTypes.string.isRequired,
};
...
const ContentNavigator = TabNavigator(
{
Profile: { screen: ProfileStack },
History: { screen: HistoryStack },
Questions: {
screen: QuestionsStack,
navigationOptions: {
tabBarIcon: QuestionsTabBarIcon
},
},
Notifications: { screen: NotificationsStack },
},
{
initialRouteName: 'Profile',
swipeEnabled: true,
tabBarOptions: {
activeTintColor: COLOR_PRIMARY,
},
backBehavior: 'none',
}
);
...
我已将我的反应导航代码放入一个单独的 Routes 文件中,然后将其导入到我的 App.js 文件中。一切正常,但我在 Atom/Nuclide 中使用 Airbnb ESLint 配置,但 tintColor 出现错误...
"tintColor is missing in props validation"
试过这个:
Routes.propTypes = { 颜色: PropTypes.string.isRequired,}
然后报错"tintColor PropType is defined but prop is never used"
这是代码的一部分
const Routes = () = {
const ContentNavigator = TabNavigator(
{
Profile: { screen: ProfileStack },
History: { screen: HistoryStack },
Questions: {
screen: QuestionsStack,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon name="question-circle" type="font-awesome" size={20} color=
{tintColor} />
),
},
},
Notifications: { screen: NotificationsStack },
},
{
initialRouteName: 'Profile',
swipeEnabled: true,
tabBarOptions: {
activeTintColor: COLOR_PRIMARY,
},
backBehavior: 'none',
});
您可以为它创建一个额外的 Functional Component, add PropTypes
并在您的主要组件中使用。例如:
...
import PropTypes from 'prop-types';
...
const QuestionsTabBarIcon = ({ tintColor }) => (
<Icon name="question-circle" type="font-awesome" size={20} color={tintColor} />
);
QuestionsTabBarIcon.propTypes = {
tintColor: PropTypes.string.isRequired,
};
...
const ContentNavigator = TabNavigator(
{
Profile: { screen: ProfileStack },
History: { screen: HistoryStack },
Questions: {
screen: QuestionsStack,
navigationOptions: {
tabBarIcon: QuestionsTabBarIcon
},
},
Notifications: { screen: NotificationsStack },
},
{
initialRouteName: 'Profile',
swipeEnabled: true,
tabBarOptions: {
activeTintColor: COLOR_PRIMARY,
},
backBehavior: 'none',
}
);
...