图标/图像在React Native中不显示TabBarBottom

问题描述:

我几乎从TabNavigator文档中获取示例代码,并且图标的/图像不会显示在iOS或Android上。即使标签覆盖似乎也不会生效。我究竟做错了什么?图标/图像在React Native中不显示TabBarBottom

enter image description here

这里的链接来我一直在使用的文档: https://reactnavigation.org/docs/navigators/tab

这里是我的代码:

class MyHomeScreen extends React.Component { 
    static navigationOptions = { 
    tabBarLabel: 'Not displayed', 
    // Note: By default the icon is only shown on iOS. Search the showIcon option below. 
    tabBarIcon: ({ tintColor }) => (
     <Image 
     source={require('./chats-icon.png')} 
     style={[styles.icon, {tintColor: tintColor}]} 
     /> 
    ), 
    }; 

    render() { 
    return (
     <Button 
     onPress={() => this.props.navigation.navigate('Notifications')} 
     title="Go to notifications" 
     /> 
    ); 
    } 
} 

class MyNotificationsScreen extends React.Component { 
    static navigationOptions = { 
    tabBarLabel: 'Notifications', 
    tabBarIcon: ({ tintColor }) => (
     <Image 
     source={require('./notif-icon.png')} 
     style={[styles.icon, {tintColor: tintColor}]} 
     /> 
    ), 
    }; 

    render() { 
    return (
     <Button 
     onPress={() => this.props.navigation.goBack()} 
     title="Go back home" 
     /> 
    ); 
    } 
} 

const styles = StyleSheet.create({ 
    icon: { 
    width: 26, 
    height: 26, 
    }, 
}); 

const MyApp = TabNavigator({ 
    Displayed: { 
    screen: MyHomeScreen, 
    }, 
    Notifications: { 
    screen: MyNotificationsScreen, 
    }, 
}, { 
    tabBarOptions: { 
    activeTintColor: '#e91e63', 
    }, 
}); 
+0

你确定在'styles.icon'中设置了'width'和'height'吗? –

+0

@ViktorSeč是的,它就在那里的样式sheet.create代码。 – theHarvester

好吧,我终于想通了想踩住后,我面对键盘。

标题和标签栏图标实际上是与文档内部结构不同的结构。

const MyApp = TabNavigator({ 
    Displayed: { 
     screen: MyHomeScreen, 
     navigationOptions: { 
      title: 'Favorites', 
      tabBar: { 
      icon: ({tintColor}) => (<Image 
       source={require('./chats-icon.png')} 
       style={{width: 26, height: 26, tintColor: tintColor}} 
      />) 
      }, 
     }, 
    }, 
    ... 

class MyHomeScreen extends React.Component { 
    static navigationOptions = { 
     title: 'Foo Bar', 
     tabBar: { 
      icon: ({ tintColor }) => (
       <Image 
       source={require('./chats-icon.png')} 
       style={{width: 26, height: 26, tintColor: tintColor}} 
       /> 
      ), 
     } 
     }; 
... 

得到了同样的问题,但这种解决方案并没有为我工作。在导航选项中定义了无效的'tabBar'... 编辑: 当我从tab选项卡导航器中删除tabBarOptions时,它工作正常。 改为使用activeTintColor和inactiveTintColor作为TabBarBottom的道具。

+1

这并没有真正回答这个问题。如果您有不同的问题,可以通过单击[提问](https://*.com/questions/ask)来提问。您可以[添加赏金](https://*.com/help/privileges/set-bounties)在您拥有足够的[声誉](https://*.com/help/)后吸引更多关注此问题什么声誉)。 - [来自评论](/ review/low-quality-posts/18561715) – Ghost

+0

并删除tabBar键。并将tabBarIcon和tabBarLabel与标签导航器屏幕放在一起。 –