我正在try 使用React导航创建一个如下图所示的选项卡栏.

我试过一些密码,但都没用.一些代码来自以前的React导航版本.真正的问题是让标签栏从底部到两侧都有一个边距,并且边框是圆形的.

谁能帮帮我?!

enter image description here

推荐答案

这里是演示:https://snack.expo.io/@nomi9995/createbottomtabnavigator-%7C-react-navigation

你可以使用tabBar个props 来定制TABBAR个props

<NavigationContainer>
      <Tab.Navigator tabBar={props => <MyTabBar {...props} />}>
        <Tab.Screen name="Home" component={HomeScreen} />
        <Tab.Screen name="Settings" component={SettingsScreen} />
      </Tab.Navigator>
    </NavigationContainer>

MyTabBar Component

function MyTabBar({ state, descriptors, navigation }) {
  return (
    <View style={{ flexDirection: 'row',backgroundColor:"#F4AF5F",height:50,borderRadius:50,justifyContent:"center",alignItems:"center" }}>
      {state.routes.map((route, index) => {
        const { options } = descriptors[route.key];
        const label =
          options.tabBarLabel !== undefined
            ? options.tabBarLabel
            : options.title !== undefined
            ? options.title
            : route.name;

        const isFocused = state.index === index;

        const onPress = () => {
          const event = navigation.emit({
            type: 'tabPress',
            target: route.key,
          });

          if (!isFocused && !event.defaultPrevented) {
            navigation.navigate(route.name);
          }
        };

        const onLongPress = () => {
          navigation.emit({
            type: 'tabLongPress',
            target: route.key,
          });
        };

        return (
          <TouchableOpacity
            accessibilityRole="button"
            accessibilityStates={isFocused ? ['selected'] : []}
            accessibilityLabel={options.tabBarAccessibilityLabel}
            testID={options.tabBarTestID}
            onPress={onPress}
            onLongPress={onLongPress}
            style={{ flex: 1, alignItems:"center" }}
          >
            <Text style={{ color: isFocused ? '#673ab7' : '#222' }}>
              {label}
            </Text>
          </TouchableOpacity>
        );
      })}
    </View>
  );
}

React-native相关问答推荐

单击react 本机时如何从同一屏幕更改内容

一旦我关闭应用程序,Json struct 就会发生变化

找不到变量:firebase/react native(expo)上的 IDBIndex

react native :navigationOptions 中的标题样式不起作用

从 .apk 到 .aab 的本地构建版本react,如何将应用程序发送给客户端?

withNavigation 只能用于导航器的视图层次 struct

React-native android 样式化 textInput

如何在react-native android中打开应用程序设置页面?

如何实时从 react-native-camera 获取帧

Soundcloud API /stream 端点给出 401 错误

Test suite无法运行 TypeError:Cannot read property ‘default’ of undefined

Property body[41] of BlockStatement expected node to be of a type ["Statement"] but instead got "AssignmentExpression"

React native base headers for ios not found

将 svg 转换为 react-native-svg

当组件在react-native 中重新呈现时,动态不透明度不会改变

如何在自定义组件上使用 onPress?

如何将时刻日期转换为字符串并删除时刻对象

INSTALL_FAILED_INSUFFICIENT_STORAGE 运行 npm run android 命令时出错

React Native 中的 CSS 三角形

React Native:无法解析模块 fs