简体   繁体   English

选项卡栏图标不是垂直居中的 React Native Navigation

[英]Tab Bar Icons not vertically centered React Native Navigation

When testing my react native app (with expo) through the expo go IOS app the icons are not vertically centered, however when testing on web they are vertically centered.当通过 expo go IOS 应用程序测试我的 React 本机应用程序(带有 expo)时,图标不是垂直居中的,但是在 web 上测试时,它们是垂直居中的。 I have tried giving each icon a parent div and centering it vertically, giving it a TabBarIconStyle of textAlignVertical: center, and textAlign: center, everything I can think of to vertically align these icons.我试过给每个图标一个父 div 并将其垂直居中,给它一个 TabBarIconStyle 的 textAlignVertical: center 和 textAlign: center,我能想到的所有垂直对齐这些图标的方法。

My Navigator:我的导航器:

<TabNav.Navigator screenOptions={TabNavOptions}>
                <TabNav.Screen
                    name="Home"
                    component={HomeScreen}
                    options={{
                        tabBarIconStyle: { textAlignVertical: "center", textAlign: "center" },
                        tabBarIcon: ({ color, size }) => (
                            <View style={{}}>
                                <Ionicons name="home" color={color} size={size} style={{ textAlignVertical: "center" }} />
                            </View>
                        ),
                    }}
                />
                <TabNav.Screen name="Workouts" component={HomeScreen} options={{ tabBarIcon: ({ color, size }) => <Ionicons name="barbell" color={color} size={size} /> }} />
                <TabNav.Screen name="Exercises" component={HomeScreen} options={{ tabBarIcon: ({ color, size }) => <Ionicons name="bicycle" color={color} size={size} /> }} />
            </TabNav.Navigator>

My screen options for the Navigator:我的导航器屏幕选项:

const TabNavOptions: BottomTabNavigationOptions = {
        tabBarShowLabel: false,
        tabBarActiveTintColor: "#4B7079",
        tabBarInactiveTintColor: "#FFFFFF",
        tabBarStyle: { width: "90%", height: 60, position: "absolute", left: "5%", bottom: 30, borderRadius: 100, borderTopWidth: 0, backgroundColor: "#75B1BC" },
    };

This is what it looks like on web (and what it should look like)这是它在 web 上的样子(以及它应该的样子)

在此处输入图像描述

This is what it looks like on expo go这是它在 expo go 上的样子

在此处输入图像描述

I managed to fix this issue with paddingBottom: 0 within the Navigator options, not sure why it only appeared on IOS would love insight if someone has an idea why.我设法在 Navigator 选项中使用paddingBottom: 0解决了这个问题,不确定为什么它只出现在 IOS 上,如果有人知道原因,我会很高兴。

Try adding this to the styling of the parent view of each icon:尝试将其添加到每个图标的父视图的样式中:

{flex: 1, alignItems: "center" }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM