React native JS线程似乎暂停了

React native JS线程似乎暂停了,react-native,realm,mobx,mobx-react,react-native-navigation,React Native,Realm,Mobx,Mobx React,React Native Navigation,我有个问题。我仍然是react native的新手,但我找不到任何与我的问题相关的东西。react/react原生文档中没有,谷歌也没有 我在上一个项目中已经遇到了这个问题,但我从未完成它,也没有试图解决它 所以问题是: 如果我从中使用this.setState()或this.props.navigator.reseto(),则在我触摸显示器的某个位置或旋转设备之前,它不会执行任何操作。此外,对ios模拟器进行聚焦和取消聚焦也足够了 在我输入一些东西之前,JS线程似乎会暂停。当我使用mobx o

我有个问题。我仍然是react native的新手,但我找不到任何与我的问题相关的东西。react/react原生文档中没有,谷歌也没有

我在上一个项目中已经遇到了这个问题,但我从未完成它,也没有试图解决它

所以问题是:

如果我从中使用
this.setState()
this.props.navigator.reseto()
,则在我触摸显示器的某个位置或旋转设备之前,它不会执行任何操作。此外,对ios模拟器进行聚焦和取消聚焦也足够了

在我输入一些东西之前,JS线程似乎会暂停。当我使用
mobx observable
时也会发生这种情况。但是对于可观察的
,它的发生频率并不比
setState()
高。这就是为什么我将所有的本地状态移动到本地mobx商店,这改善了我的情况,但有时仍然会发生react native以某种方式等待触摸输入的情况。我还尝试过的一件事是将每个
reseto()
包装在
requestAnimationFrame()
中,这也稍微改善了我的情况

下面是一个示例代码:

这是我打开领域数据库的初始屏幕

import React,{Component}来自'React';
从“react native”导入{View,Dimensions};
从“../Schema”导入架构;
从“../Stores/index”导入{Everything,Untis,NavigateEverywhere};
从“react native elements”导入{Text};
//将*作为进度从“反应本机进度”导入;
从“百分比计算”中输入百分比;
从“领域”导入领域;
从“mobx”导入{observable}
从'mobx react'导入{observer};
从“react native material kit”导入{MKProgress};
@观察者
类数据库扩展组件{
建造师(道具){
超级(道具);
console.ignoreWarnings=['Realm.openAsync'];
NavigateEverywhere.setNavigator(this.props.navigator);
}
//状态={
//statusText:'正在初始化数据库…',
//上载进度:0,
//下载进度:0,
//上载最大值:0,
//下载量上限:0,
//上载电流:0,
//下载电流:0,
//工作提示:错误,
//workingDownload:false,
//realmHost:this.realmHost,
//realmServer:`http://${this.realmHost}/`,
//realm:`realm://${this.realmHost}/~/sitnu`
// };
@可观察状态文本=“正在初始化数据库…”;
@可观察的上传进度=0;
@可观察下载进度=0;
@可观察上传最大值=0;
@可观测下载量max=0;
@可观测上传电流=0;
@可观测下载电流=0;
@可观察的工作载荷=false;
@可观察工作下载=错误;
realmHost='';
realmServer=`http://${this.realmHost}/`;
realm=`realm://${this.realmHost}/~/sitnu`;
componentDidMount(){
this.bootStrap().catch(console.error);
}
异步引导{
让用户;
if(this.props.token&&this.props.provider){
试一试{
user=wait Realm.Sync.user.registerWithProvider(this.realmServer{
提供者:this.props.provider,
providerToken:this.props.token
});
}捕获(e){
返回this.props.navigator.reseto({
屏幕:“io.LoginRealm”,
标题:“登录到领域”,
通行证:{
错误:e
}
});
}
}
if(this.props.username&&this.props.password){
试一试{
用户=等待新承诺((解决、拒绝)=>{
Realm.Sync.User.login(this.realmServer,this.props.username,this.props.password,(err,u)=>{
如果(错误)返回拒绝(错误);
决议(u);
});
});
}捕获(e){
返回this.props.navigator.reseto({
屏幕:“io.LoginRealm”,
标题:“登录到领域”,
通行证:{
错误:e
}
});
}
}
让用户=[];
for(输入Realm.Sync.User.all){
push(Realm.Sync.User.all[key]);
}
if(users.length!==0&&!user){
用户=用户[0];
}
如果(!用户){
返回this.props.navigator.reseto({
屏幕:“io.LoginRealm”,
标题:“登录到领域”,
通行证:{
错误:“用户未定义或为空”
}
});
}
让王国;
试一试{
领域=等待新承诺((解决、拒绝)=>{
Realm.openAsync({
schema:schema,
同步:{
用户:用户,,
url:this.realm
}
},(错误,领域)=>{
如果(错误)返回拒绝(错误);
决心(境界);
},this.downloadCallback.bind(this));
});
}捕获(e){
console.log(“为什么”);
返回requestAnimationFrame(()=>{
this.props.navigator.reseto({
屏幕:“io.LoginRealm”,
标题:“登录到领域”,
通行证:{
错误:e
}
});
});
}
this.workingUpload=false;
this.workingDownload=false;
this.statusText='Finishing Database…';
一切。设置领域(领域);
const username=realm.objectForPrimaryKey('KeyValue','username');
const password=realm.objectForPrimaryKey('KeyValue','password');
const host=realm.objectForPrimaryKey('KeyValue','host');
const school=realm.objectForPrimaryKey('KeyValue','school');
const setup=realm.objectForPrimaryKey('KeyValue','setup');
如果(用户名类型=='object'&&typeof password=='object'&&typeof host=='object'&&typeof school=='object'&&typeof setup=='object'&&username.value&&password.value&&host.value&&school.value&&setup.value){
设置凭证(username.value、password.value、host.value、school.value);
联合设置设置(username.value、password.value、host.value、school.value);
requestAnimationFrame(()=>{
this.props.navigator.reseto({
屏幕:“io.Home”,
是的,
标题:“家”
});
});
}否则{
requestAnimationFrame(()=>{
this.props.navigator.reseto({
屏幕:“io.Login”,
是的,
导航方式:{
纳瓦尔:是的,
statusBarTextColorSchemeSingleScreen:“暗”
}
});
});
}
}
downloadCallback=异步(已传输、可转移)=>{
this.workingDownload=true;
this.downloadMax=可转让;
这个,放下