简体   繁体   English

在 React Native expo 移动应用程序中,BottomTabNavigator 位于顶部而不是底部

[英]BottomTabNavigator coming on top instead of bottom in React Native expo mobile app

I am developing a mobile react native expo app.我正在开发一个移动反应原生 expo 应用程序。 I am using BottomTabNavigator (NavigationContainer).我正在使用 BottomTabNavigator (NavigationContainer)。 As the name suggests it should appear at the bottom but it is incorrectly appearing on top.顾名思义,它应该出现在底部,但它错误地出现在顶部。

I already have another image (logo.png) on the top of the screen and the navigationbar (or NavigationContainer) is also coming on top and overlapping above the image.我已经在屏幕顶部有另一个图像(logo.png),并且导航栏(或 NavigationContainer)也出现在顶部并重叠在图像上方。 Please help me resolve this issue.请帮我解决这个问题。 See my code below:请参阅下面的代码:

In the below code MyTabs is the Navigator created from createBottomTabNavigator() .在下面的代码中MyTabs是从createBottomTabNavigator()创建的导航器。 This is incorrectly appearing on top of the screen.这错误地出现在屏幕顶部。

import React from 'react';
import { Image,  StyleSheet, Text, View, SafeAreaView, StatusBar, Platform } from 'react-native';
import logo from './assets/logo.png';
import { NavigationContainer } from '@react-navigation/native';
import MyTabs from './navigator/AppNavigator';

export default function App() {
  return (
    <SafeAreaView style={{ paddingTop: Platform.OS === 'android' ? StatusBar.currentHeight: 0 }} >
        <View>
            <View style={styles.container}>
                <Image source={logo} style={{ width: 100, height: 100 }} />

                <Text style={{color: '#888', fontSize: 18, alignItems: 'center'}}>
                To share a photo from your phone with a friend or anyone, just press the button below!
                </Text>
            </View>

            <View >
                <NavigationContainer >
                        <MyTabs />        // This is incorrectly coming on top of screen.
                </NavigationContainer>
            </View>

        </View>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
     alignItems: 'center',
    // justifyContent: 'center',
  },
});

The NavigationContainer should be the outermost component in App . NavigationContainer应该是App中最外层的组件。 This then wraps the Tab.Navigator component (in your case MyTabs ), where you create tabs linked to each of your components.然后包装Tab.Navigator组件(在您的情况下MyTabs ),您可以在其中创建链接到每个组件的选项卡。 Inside your components, you are able to utilize SafeAreaView to then display the image at the top of the screen.在您的组件内部,您可以利用SafeAreaView在屏幕顶部显示图像。 Any type of Navigation scheme has to be made the top most component in the hierarchy in react native, wrapping the rest of your components.在 react native 中,任何类型的导航方案都必须成为层次结构中最顶层的组件,包装组件的 rest。 I've altered your code below:我在下面更改了您的代码:

import React from 'react';
import { Image,  StyleSheet, Text, View, SafeAreaView, StatusBar, Platform } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';

export default function App() {
  const Tab = createBottomTabNavigator()

  return (
    <NavigationContainer >
      <Tab.Navigator>  
        <Tab.Screen name="Home" component={myComponent} />
      </Tab.Navigator>
    </NavigationContainer>
  );
}

const myComponent = () => {
  return (
    <SafeAreaView style={{ paddingTop: Platform.OS === 'android' ? StatusBar.currentHeight: 0 }} >
      <View>
        <View style={styles.container}>
          <Image source={require('@expo/snack-static/react-native-logo.png')} style={{ width: 100, height: 100 }} />
          <Text style={{color: '#888', fontSize: 18, alignItems: 'center'}}>To share a photo from your phone with a friend or anyone, just press the button below!</Text>
        </View>
      </View>
    </SafeAreaView>
  )
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
     alignItems: 'center',
    // justifyContent: 'center',
  },
});

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

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