【发布时间】:2020-04-13 13:26:49
【问题描述】:
从昨天开始我就一直被这个问题困扰,我找不到解决方案。
我一直在尝试调整 iPhone X 中 safeArea 的颜色,它在顶部和底部都可以很好地用于没有标签的屏幕,但是,在带有标签导航器的屏幕中,底部的 safeArea 始终是白色的如屏幕截图所示。有谁知道如何解决这个问题?
另外,我想问一下使用普通的 SafeAreaView 组件并删除 SafeAreaProvider 并删除 react-native-safe-area-context 包是否会更好,我只是将它作为解决此问题的试验添加但我是首先使用 react native 正常的 SafeAreaView 组件;
在应用组件中:
import { SafeAreaProvider } from "react-native-safe-area-context";
<SafeAreaProvider>
<NavigationContainer>
<CatNavigator />
</NavigationContainer>
</SafeAreaProvider>
在 CatNavigator 组件中:
const CatNavigator = () => {
return (
<Drawer.Navigator
initialRouteName="Home" >
<Drawer.Screen
name="Home"
component={SettingsNavigator}
options={{ title: "Inicio" }}
/>
</Drawer.Navigator>
在设置选项卡导航器中:
const SettingsNavigator = () => {
return (
<Tab.Navigator
screenOptions={({ route }) => ({
tabBarIcon: ({ focused, color, size }) => {
let iconName;
const iconType = Platform.OS === "ios" ? "ios" : "md";
if (route.name === "Home") {
iconName = iconType + "-home";
} else if (route.name === "Settings") {
iconName = iconType + "-settings";
}
const tabColor = focused ? Colors.buttonBackColor : Colors.titleColor;
return <Ionicons name={iconName} size={size} color={color} />;
},
})}
tabBarOptions={{
activeTintColor: Colors.activeTabColor,
inactiveTintColor: Colors.inactiveTabColor,
activeBackgroundColor: Colors.tabBackgroundColor,
inactiveBackgroundColor: Colors.tabBackgroundColor,
safeAreaInset: { bottom: "never", top: "never" },
}}
>
<Tab.Screen
name="Home"
component={HomeNavigator}
options={{ title: "Inicio" }}
/>
<Tab.Screen
name="Settings"
component={SettingStackNavigator}
options={{ title: "Ajustes" }}
/>
</Tab.Navigator>
在设置导航器中:
const SettingStackNavigator = (props) => {
return (
<SettingStack.Navigator screenOptions={defaultNavOptions}>
<SettingStack.Screen
name="Settings"
component={SettingScreen}
options={settingsOptions}
/>
</SettingStack.Navigator>
);
};
最后在设置屏幕中:
import { SafeAreaView } from "react-native-safe-area-context";
return (
<SafeAreaView
style={{
flex: 1,
backgroundColor: Colors.backgroundColor,
justifyContent: "center",
alignItems: "center",
}}
>
{colorScheme === "dark" && <StatusBar barStyle="light-content" />}
// Other components
</SafeAreaView>
【问题讨论】:
标签: react-native react-navigation react-navigation-bottom-tab safeareaview