React Native 导航显示白屏

2024-03-23

使用反应本机导航进行编译时出现白屏,请问为什么会这样?我似乎没有收到任何错误代码,什么也没有,我只看到一个白屏。为什么会这样呢?我的代码看起来像这样,表明到目前为止我似乎没有任何错误。

Here is what the Error seems to look like Error-Drawer.png

正如您所看到的,它看起来并成功编译,但是当我尝试查看到目前为止我所做的事情时,我得到一个纯白色的屏幕

我的代码如下所示:

App.js

//import liraries
import React, { Component } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import DrawerNavigator from './components/ControlPage';

// create a component
class App extends Component {
  render() {
    return (
      <View style={styles.container}>
        <DrawerNavigator/>
      </View>
    );
  }
}

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

//make this component available to the app
export default App;

控制页面.js

import React, { Component } from 'react';
import { StyleSheet, View, Text, TouchableHighlight, Image } from 'react-native';

import { createAppContainer} from 'react-navigation';
import { createDrawerNavigator } from 'react-navigation-drawer'; 
import Main from './Main';
import Screen1 from './Screen1';
import Screen2 from './Screen2';

const MyDrawerNavigator = createDrawerNavigator({
Home : {screen : Main},
Screen1:{screen : Screen1},
Screen2:{screen : Screen2},
 },
{
   InitialRouteName : 'Home',
   drawerWidth : 300,
   drawerPosition: 'left'
}
);
const AppContainer = createAppContainer(MyDrawerNavigator);

// create a component
class DrawerNavigator extends Component {
    render() {
        return (
            <View style={styles.container}>
                <AppContainer/>
            </View>
        );
    }
}

// define your styles 
const styles = StyleSheet.create({
    view:{
    flex:1,
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: 'white',
},
text:{
    fontSize: 26,
    color: 'purple'
},

touchableHighlight: {
    width: 50,
    height: 50,
    backgroundColor: 'red',
    borderRadius : 50,
    alignItems : 'center',
    justifyContent: 'center',
    position: 'absolute',
    left: 10,
    top : 10
},

open: {
    color : 'white',
    fontSize : 16,
    fontWeight: 'bold'
},

});

//make this component available to the app
export default DrawerNavigator;

Main.js

//import liraries
import React, { Component } from 'react';
import { StyleSheet, View, Text, TouchableHighlight, Image } from 'react-native';

// create a component
class Main extends Component {
        static navigationOptions = {
        drawerLabel: 'Home',
        drawerIcon : () =>(
            <Image source ={require('../icons/home.png')}/>
        ),
    }
    render() {
        return (
            <View style={styles.container}>
            <TouchableHighlight onPress ={() => this.props.navigation.dispatch(DrawerActions.openDrawer())} style={styles.touchableHighlight} underlayColor={'rgba(0,0,0,0.8)'}>
            <Text style={styles.open}>OPEN</Text>
            </TouchableHighlight>
            <Text style={styles.text}> Welcome to Home Screen </Text>
            </View>
        );
    }
}

// define your styles
const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#FFFF',
    },

    text:{
    fontSize: 26,
    color: 'purple'
},
});

//make this component available to the app
export default Main;

其他屏幕只是显示和隐藏抽屉。 请问我需要指导吗?我错过了什么吗?


这是一个常见问题,当alignItems: 'center'应用于导航器的容器。 将其从App.js它应该有效。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

React Native 导航显示白屏 的相关文章

随机推荐

  • 詹金斯 HTTPS Git

    目前正在研究自动化概念验证 所以我试图让 Jenkins 使用我们的 GIT 存储库 但在填写凭据后 我遇到了一个奇怪的错误 Failed to connect to repository Could not init C apache t
  • 在返回带有取消的 IAsyncEnumerable 的函数中迭代 IAsyncEnumerable

    正如标题所说 我必须执行以下功能 public async IAsyncEnumerable
  • 减少深度优先树遍历的空间使用

    在 Haskell 中 我们可以在恒定空间中对无限列表进行过滤 求和等操作 因为 Haskell 仅在需要时生成列表节点 并且垃圾收集它完成的节点 我希望它能与无限的树一起使用 下面是一个相当愚蠢的程序 它生成一个无限二叉树 其中的节点代表
  • Flutter 自定义 Google 地图标记信息窗口

    我正在 Flutter 中研究 Google 地图标记 单击每个标记时 我想显示一个自定义信息窗口 其中可以包含按钮 图像等 但是在 Flutter 中有一个属性TextInfoWindow只接受String 我如何实现向地图标记添加按钮
  • 在Python中反序列化Protobuf 3字节数组

    如何通过 bytearray 响应读取 Protobuf 消息作为字符串 我尝试查找 Protobuf 库 https developers google com protocol buffers docs reference python
  • 使用 LIMIT 关键字的 SQL Server 查询中的语法错误[关闭]

    Closed 这个问题是无法重现或由拼写错误引起 help closed questions 目前不接受答案 我正在尝试运行此查询 但收到错误 关键字 limit 附近的语法错误 SQL查询 select from messages as
  • 更新 SQL“关系”表的有效方法

    假设我有三个正确标准化的表 一种人 一种资格 以及一种将人映射到资格的方法 People id Name 1 Alice 2 Bob Degrees id Name 1 PhD 2 MA 人与学位 person id degree id 1
  • 使用 cfsqltype 是一个好的做法吗?

    编写 cfqueryparam 或 cfprocparam 时 cfsqltype 是可选的 不过 我通常会看到它的编码 指定 cfsqltype 有什么好处吗 主要好处是在将查询输入传递到查询之前对查询输入进行额外的健全性检查 另外 对于
  • 如何在powershell中修改GOPATH

    我正在尝试将我的项目目录添加到 GOPATH 在 linux 中我可以这样做 export GOPATH HOME mygo在 bashrc中 powershell中的等价物是什么 这应该遵循使用 Powershell 设置任何环境变量的方
  • TypeError: 无法连接 'str' 和 'list' 对象是什么意思?

    这个错误是什么意思 类型错误 无法连接 str 和 list 对象 这是代码的一部分 for j in 90 52 62263 26 5651 10 8123 if j 90 z 0 elif j 52 62263 z 0 72 144 2
  • RecyclerView 在 ConstraintLayout 内时更改其滚动位置

    我遇到了一个问题RecyclerView当它是 a 的孩子时ConstraintLayout 本来 RecyclerView位于视图层次结构深处的某个地方Relative Frame and LinearLeayout一切都运行良好 直到我
  • 无法从另一个 Maven 子项目调用 Hibernate/QueryDSL

    我有两个 Maven 子项目 jetty runner1 和 jetty runner2 我的目录结构如下所示 jetty runner1 pom xml jetty runner1 src main java com jetty runn
  • 尝试在现有的flutter应用程序中实现flutter_contacts示例

    我正在尝试实现这里的 flutter contacts 示例 颤动接触 https github com pavelshackih flutter contacts blob master android app src main kotl
  • 如何在 django DRF 中处理时区而不重复太多?

    Intro 我的项 目TIME ZONE等于 UTC 而我的用户来自太多时区 所以 当我用户 makePOST or PUT with date or time or dateTime字段我将这些字段转换为UTC before serial
  • 将 FirestoreCollection 转换为数组?

    我在将 Firestore 数据转换为 Chart js 图表的数组时遇到困难 从 Firestore 获取数据 fetchData Get data this updatesCollection this afs collection p
  • 如何为多个 #id 创建 ::before

    是否可以在前面插入多个id I have ps4 before ps3 before 我尝试过 ps4 ps3 before但什么也没有 是否可以在之前插入更多 id 我想保持CSS尽可能干净和简短 我尝试查看 css trick 但找不到
  • 采用 OpenGL 中的 Wu 算法的数字微分分析仪

    我正在尝试制作一种使用 DDA 数字差分分析器 绘制线条的算法 该算法也使用 Wu 的算法作为抗锯齿 问题是输出看起来不太好 尤其 我选择的颜色 它改变了 我知道为什么 但我想知道它是否必须是这样的 像素颜色越亮则越亮 我怎样才能选择我想要
  • 从数据框中仅提取数字列[重复]

    这个问题在这里已经有答案了 我在互联网上查找 但没有找到简单而干净的解决方案 这是我的 df 的一部分 structure list ID structure c 12L 12L 12L 12L 12L 12L 12L 12L 12L 12
  • 缺少 1 个必需的位置参数:“key”

    class Keys def init self self key list 1 one 2 two 3 three def get name self key self ddd key key1 Keys key1 get name 1
  • React Native 导航显示白屏

    使用反应本机导航进行编译时出现白屏 请问为什么会这样 我似乎没有收到任何错误代码 什么也没有 我只看到一个白屏 为什么会这样呢 我的代码看起来像这样 表明到目前为止我似乎没有任何错误 Here is what the Error seems