React-navigation ReferenceError: Can’t find variable: width

react-navigation 组件库在使用时按照官方文档设置tab图片
可是却出现了报错,最后的解决办法

Unhandled JS Exception: ReferenceError: ReferenceError: Can’t find variable: width

这是需要设置React 子元素
出错代码

const BottomTabNavigator = createBottomTabNavigator({
    Home: {
        screen: MainScreenNavigator1,
        navigationOptions: {
            title: '首页',
            tabBarIcon: ({ focused, horizontal, tintColor }) => {
                let iconName = 'ios-home';//`ios-home${focused ? '' : '-outline'}`;
                return ( <Icon name=iconName size={30} color="yellow" />)
            },
        },
        tabBarOptions: {
            activeTintColor: 'tomato',
            inactiveTintColor: 'gray',
        },
    },

把Image 改成React.createElement 创建就好了
修改后代码

const BottomTabNavigator = createBottomTabNavigator({
    Home: {
        screen: MainScreenNavigator1,
        navigationOptions: {
            title: '首页',
            tabBarIcon: ({ focused, horizontal, tintColor }) => {
                let iconName = 'ios-home';//`ios-home${focused ? '' : '-outline'}`;
                return React.createElement(
                    Ionicons,
                    { name: iconName, size: horizontal ? 20 : 25, color: tintColor },
                )
            },
        },

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注