React Native 无法在SafeAreaView中换行导航器

rqcrx0a6  于 2023-05-23  发布在  React
关注(0)|答案(3)|浏览(201)

在iPhone X模拟器上运行应用程序时,Material Top Tab Navigator会切入凹口和底部按钮。
为了解决这个问题,我尝试在应用应用程序容器之前实现SafeAreaView,并将每个单独的屏幕 Package 在SafeAreaView中。这可以使文本远离这些区域,但不会远离导航器。

import React, { Component } from 'react';
import { Text, View } from 'react-native';
import { createAppContainer, createMaterialTopTabNavigator, SafeAreaView } from 'react-navigation';

class Calculator extends Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Calculator!</Text>
      </View>
    );
  }
}

class Camera extends Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Camera!</Text>
      </View>
    );
  }
}

class Solution extends Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Solution!</Text>
      </View>
    );
  }
}

const TabNavigator = createMaterialTopTabNavigator(
  {
    Calculator,
    Camera,
    Solution
  },
  {
    tabBarPosition: 'bottom',
  }
);

const AppContainer = createAppContainer(TabNavigator);

class App extends Component {
  render() {
    return (
      <SafeAreaView>
        <AppContainer/>
      </SafeAreaView>
    );
  }
}

export default App;

运行此应用程序时,不存在任何错误。但是,没有任何渲染。我所期望的是一个标签导航器呈现三个标签,不削减下的缺口或底部按钮。

q9rjltbz

q9rjltbz1#

给予SafeAreaView一个大小

<SafeAreaView style={{ flex: 1 }}>
  <AppContainer/>
</SafeAreaView>

如果AppContainer仍然展开全屏,
更改import { SafeAreaView } from 'react-navigation'
import { SafeAreaView } from 'react-native'

wgmfuz8q

wgmfuz8q2#

您需要将flex: 1作为样式提供给SafeAreaView组件

<SafeAreaView style={{flex: 1}}>
{/* Component here */}
</SafeAreaView>
kknvjkwl

kknvjkwl3#

import { SafeAreaView } from "react-native-safe-area-context";

<NavigationContainer>
        <SafeAreaView style={{ flex: 1 }}>
          <MainNavigation />
        </SafeAreaView>
</NavigationContainer>

对于我的情况,这是我需要的进口

相关问题