React Navigation活动标签颜色覆盖SafeArea

huangapple go评论81阅读模式
英文:

React Navigation Active Tab color cover SafeArea

问题

我正在使用React Navigation Bottom Tabs开发一个应用,并希望突出显示活动选项卡的颜色与非活动选项卡不同。目前,我已经有了正确的突出显示颜色,但这种颜色没有填充手机底部的安全区域:

React Navigation活动标签颜色覆盖SafeArea

这是我的代码片段:

<MainTabs.Navigator
    initialRouteName="HomeTab"
    screenOptions={({ route }) => ({
        headerShadowVisible: false,
        tabBarStyle: {
            backgroundColor: theme.colors.primaryColor,
        },
        tabBarActiveBackgroundColor: theme.colors.secondaryColor,
        tabBarInactiveBackgroundColor: theme.colors.primaryColor,
        tabBarActiveTintColor: theme.colors.white,
        tabBarInactiveTintColor: theme.colors.white,
        tabBarLabelStyle: {
            fontSize: 12,
            alignSelf: "center",
            textAlign: "center",
            fontFamily: theme.font.familyBold,
        },
    })}
>;
英文:

I'm working on an app using React Navigation Bottom Tabs and I want to highlight the active tab with a different color then when it's inactive. Currently, I have the correct highlight color, but that color is not filling up the safe area at the bottom of the phone:

React Navigation活动标签颜色覆盖SafeArea

And here's a snippet of my code:

        &lt;MainTabs.Navigator
            initialRouteName=&quot;HomeTab&quot;
            screenOptions={({ route }) =&gt; ({
                headerShadowVisible: false,
                tabBarStyle: {
                    backgroundColor: theme.colors.primaryColor,
                },
                tabBarActiveBackgroundColor: theme.colors.secondaryColor,
                tabBarInactiveBackgroundColor: theme.colors.primaryColor,
                tabBarActiveTintColor: theme.colors.white,
                tabBarInactiveTintColor: theme.colors.white,
                tabBarLabelStyle: {
                    fontSize: 12,
                    alignSelf: &quot;center&quot;,
                    textAlign: &quot;center&quot;,
                    fontFamily: theme.font.familyBold,
                },
            })}
        &gt;

答案1

得分: 0

我找到了如何解决此问题的方法。以下是我的代码:

        &lt;MainTabs.Navigator
            initialRouteName=&quot;HomeTab&quot;
            safeAreaInsets={{ bottom: 0 }}
            screenOptions={({ route }) =&gt; ({
                headerShadowVisible: false,
                tabBarIconStyle: {
                    marginTop: 5,
                },
                tabBarStyle: {
                    backgroundColor: theme.colors.primaryColor,
                    height: 85,
                },
                tabBarActiveBackgroundColor: theme.colors.secondaryColor,
                tabBarInactiveBackgroundColor: theme.colors.primaryColor,
                tabBarActiveTintColor: theme.colors.white,
                tabBarInactiveTintColor: theme.colors.white,
                tabBarLabelStyle: {
                    fontSize: 12,
                    alignSelf: &quot;center&quot;,
                    textAlign: &quot;center&quot;,
                    fontFamily: theme.font.familyBold,
                    marginBottom: insets.bottom,
                },
            })}
        &gt;

基本上只需添加safeAreaInsets,然后在选项卡标签样式中添加marginBottominsets 变量来自于使用 react-native-safe-area-context 中的 useSafeAreaInsets

英文:

For anyone having the same issue, I found out how to fix it. Here's my code below:

        &lt;MainTabs.Navigator
            initialRouteName=&quot;HomeTab&quot;
            safeAreaInsets={{ bottom: 0 }}
            screenOptions={({ route }) =&gt; ({
                headerShadowVisible: false,
                tabBarIconStyle: {
                    marginTop: 5,
                },
                tabBarStyle: {
                    backgroundColor: theme.colors.primaryColor,
                    height: 85,
                },
                tabBarActiveBackgroundColor: theme.colors.secondaryColor,
                tabBarInactiveBackgroundColor: theme.colors.primaryColor,
                tabBarActiveTintColor: theme.colors.white,
                tabBarInactiveTintColor: theme.colors.white,
                tabBarLabelStyle: {
                    fontSize: 12,
                    alignSelf: &quot;center&quot;,
                    textAlign: &quot;center&quot;,
                    fontFamily: theme.font.familyBold,
                    marginBottom: insets.bottom,
                },
            })}
        &gt;

Basically just added safeAreaInsets and then marginBottom in the tab bar label style. the insets variable comes from using useSafeAreaInsets from react-native-safe-area-context

huangapple
  • 本文由 发表于 2023年3月7日 04:36:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75655593.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定