javascript - 模块 AppRegistry 未为 Expo 注册可调用模块(调用 runApplication)
问题描述
我正在尝试使用 expo 编写一个 react-native 应用程序,并且我开始将其启动代码用于具有多个选项卡的应用程序。然后我创建了一个 LoginScreen.js 文件,如下所示:
import React, { Component } from 'react';
import { AppRegistry, TextInput, Button } from 'react-native';
export default class Login extends React.Component {
constructor(props) {
super(props);
this.state = { username: '', passwd: '', };
}
render() {
return (
<React.Fragment>
<TextInput>
style={{height: 40, borderColor: 'gray', borderWidth: 1}}
onChangeText={(username) => this.setState({username})}
value={this.state.username}
</TextInput>
<TextInput>
style={{height: 40, borderColor: 'gray', borderWidth: 1}}
onChangeText={(passwd) => this.setState({passwd})}
value={this.state.passwd}
</TextInput>
<Button>
onPress={this.verifyLogin}
title = "Login"
</Button>
</React.Fragment>
);
}
verifyLogin() {
if (this.state.username == 'test' && this.state.passwd == 'test'){
this.setState( () => ({username: 'login succeeded!'}));
}
}
}
我想将此用作用户看到的第一页,而不是默认的 HomeScreen.js。我试图通过将以下行添加到我的 app.json 文件来做到这一点:
"entryPoint": "screens/LoginScreen.js"
但是,当我尝试此操作时,我收到以下错误消息:Module AppRegistry is not registered callable module (calling runApplication)我已经找到了关于同一错误消息的另外两个 stackoverflow 问题(Module AppRegistry is not registered callable module (calling runApplication)和React-Native: Module AppRegistry is not a registered callable module ),并且我已经尝试过第一个中的解决方案(例如重新启动npm,添加该行
AppRegistry.registerComponent("Login", () => Login))
这给了我以下错误消息:应用程序主尚未注册)。另外,我引用的两个stackoverflow页面没有使用expo,而是直接使用react-native,这意味着它们引用的一些文件对我来说并不存在(例如index.ios.js文件)。此外,我尝试将 HomeScreen.js 文件的全部内容复制并粘贴到 Login.js 文件中,它仍然给了我同样的错误,让我相信我需要设置一些其他设置,但是我不知道是什么。摆脱此错误或以其他方式使首页成为登录页面的任何帮助都会有所帮助。
解决方案
推荐阅读
- python - 如何显示计数和速率之间的相关性?
- r - 按组可视化混合模型中随机效应的方差
- mysql - 发生异常。_TypeError(类型'列表
' 不是类型 'Map 的子类型 ') - amazon-web-services - 使用非默认密钥通过 SSH 连接到 AWS Lightsail 时出现问题
- angular - 将 eventListener 添加到 Angular 中的多个项目
- python - 如何获取在 cv2.warp 方法中“从无到有”扭曲的像素的蒙版?
- css - 显示 SVG 图标的 Angular 可重用组件的宽度/高度未在任何地方设置并位于图标正下方,stackblitz 内部
- laravel - Laravel 雄辩的独特选择与调用关系的可能性?
- javascript - 为什么firebase中的订单不起作用,但在控制台中工作正常?
- python - 我想使用 python 库从给定的日语文本中识别名称、地址