react-native - 在 React Native 中,图标/图像不会与 TabBarBottom 一起显示

标签 react-native react-navigation

我几乎从 TabNavigator 文档中获取了示例代码,并且图标/图像根本不会出现在 iOS 或 Android 上。甚至标签覆盖似乎也没有生效。我做错了什么?

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',
  },
});

最佳答案

好吧,我想把脸撞到键盘上后终于想通了。

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

  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}}
              />
            ),
        }
      };
 ...

关于react-native - 在 React Native 中,图标/图像不会与 TabBarBottom 一起显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43555419/

相关文章:

javascript - 对对象使用 Promise

javascript - 在第二个输入上 react native 动画 PanResponder 反转

android - 无法在React Native中以 Debug模式运行应用

javascript - 在 React native 中创建自定义底部选项卡导航器

react-native - 是否可以在导航选项中使用 navigation.toggleDrawer()

android - react 导航 : Swipe on drawer does not work in Android

react-native - 在 StackNavigator 中更改特定屏幕的动画方向?

javascript - 如何从 react 导航中删除默认样式?

Android 深层链接在我链接的应用程序中打开,而不是启动我的应用程序的单独实例

react-native - react 导航 "go back"到另一个 StackNavigator (v5) 中的上一个屏幕