【问题标题】:How to just add a small dot to react nativation bottom tab navigator icon - badges如何只添加一个小点来响应导航底部选项卡导航器图标 - 徽章
【发布时间】:2020-12-19 20:53:17
【问题描述】:

我正在尝试在底部选项卡导航器中的活动图标顶部实现通知点。这是我的代码:

const Tab = createBottomTabNavigator();

@inject('store')
@observer
class HomeTabs extends React.Component<HomeProps> {

  render() {
    return (
      <NavigationContainer independent={true} ref={mainNavigationRef}>
        <Tab.Navigator
          screenOptions={({ route }) => ({
            tabBarIcon: ({ focused }) => {
              let iconName='question';
              if (route.name === 'Home') {
                iconName = focused
                  ? 'home'
                  : 'home-outline';
              } 
              else if (route.name === 'Activity') {
                iconName = focused ? 'bell' : 'bell-outline';
              }
              else if (route.name === 'Search') {
                iconName = focused ? 'search-web' : 'magnify';
              }
              else if (route.name === 'Profile') {
                iconName = focused ? 'account' : 'account-outline';
              }

              // You can return any component that you like here!
              return <Icon name={iconName} type='material-community' color='#000000' size={24}/>;
            },
          })}
          tabBarOptions={{
            activeTintColor: 'black',
            inactiveTintColor: 'gray',
          }}
        >
        <Tab.Screen name="Home" component={YourPostsStack} />
        <Tab.Screen name="Activity" component={ActivityStack} options={{tabBarBadge: true}} />
        <Tab.Screen name="Search" component={SearchStack} />
        <Tab.Screen name="Profile" component={ProfileScreen} />
      </Tab.Navigator>
    </NavigationContainer>
    )
  }
}

我在 reactNavigation 文档中看到了“tabBarBadge”,但将其设为空字符串,徽章对于我的需要来说是超大的。我只需要一个小点来表示有通知可以看到。有没有其他方法可以使用bottomTabNavigation 做到这一点?还有其他想法吗?

【问题讨论】:

    标签: node.js react-native react-navigation badge


    【解决方案1】:

    有点晚了,但这会奏效:

    tabBarBadgeStyle: { backgroundColor: 'blue', height: 12, minWidth: 12, borderRadius: 6},
    

    【讨论】:

      猜你喜欢
      • 2017-09-29
      • 2020-12-02
      • 2020-03-19
      • 1970-01-01
      • 2017-07-29
      • 2021-05-02
      • 2020-06-16
      • 2022-10-24
      • 1970-01-01
      相关资源
      最近更新 更多