- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个问题。我仍然是 react-native 的新手,但找不到与我的问题相关的任何内容。不在谷歌的 react/react-native 文档中。
我在上一个项目中已经遇到过这个问题,但我没有完成它,也没有尝试解决它。
所以问题是:
如果我使用来自 react-native-navigation 的 this.setState()
或 this.props.navigator.resetTo()
,直到我触摸显示器上的某处或旋转我的设备之前,它什么都不做。聚焦和取消聚焦 ios 模拟器也足够了。
在我输入某些内容之前,JS 线程似乎暂停了。当我使用 mobx observable
时也会发生这种情况。但是对于 observable
,它发生的频率不如 setState()
。这就是为什么我将所有本地状态移动到本地 mobx 存储的原因,它改善了我的情况,但有时仍然会发生 react-native 以某种方式等待触摸输入。我还尝试过的一件事是将每个 resetTo()
包装在 requestAnimationFrame()
中,这也稍微改善了我的情况。
现在是一个示例代码:
这是我打开 Realm 数据库的初始屏幕。
import React, {Component} from 'react';
import {View, Dimensions} from 'react-native';
import Schema from '../Schema';
import {Everything, Untis, NavigateEverywhere} from '../Stores/index';
import {Text} from 'react-native-elements';
// import * as Progress from 'react-native-progress';
import percentage from 'percentage-calc';
import Realm from 'realm';
import {observable} from "mobx"
import {observer} from 'mobx-react';
import {MKProgress} from 'react-native-material-kit';
@observer
class Database extends Component {
constructor(props) {
super(props);
console.ignoreWarnings = ['Realm.openAsync'];
NavigateEverywhere.setNavigator(this.props.navigator);
}
// state = {
// statusText: 'Initializing Database...',
// uploadProgress: 0,
// downloadProgress: 0,
// uploadMax: 0,
// downloadMax: 0,
// uploadCurrent: 0,
// downloadCurrent: 0,
// workingUpload: false,
// workingDownload: false,
// realmHost: this.realmHost,
// realmServer: `http://${this.realmHost}/`,
// realm: `realm://${this.realmHost}/~/sitnu`
// };
@observable statusText = 'Initializing Database...';
@observable uploadProgress = 0;
@observable downloadProgress = 0;
@observable uploadMax = 0;
@observable downloadMax = 0;
@observable uploadCurrent = 0;
@observable downloadCurrent = 0;
@observable workingUpload = false;
@observable workingDownload = false;
realmHost = '';
realmServer = `http://${this.realmHost}/`;
realm = `realm://${this.realmHost}/~/sitnu`;
componentDidMount() {
this.bootStrap().catch(console.error);
}
async bootStrap() {
let user;
if (this.props.token && this.props.provider) {
try {
user = await Realm.Sync.User.registerWithProvider(this.realmServer, {
provider: this.props.provider,
providerToken: this.props.token
});
} catch (e) {
return this.props.navigator.resetTo({
screen: 'io.LoginRealm',
title: 'Login into Realm',
passProps: {
error: e
}
});
}
}
if (this.props.username && this.props.password) {
try {
user = await new Promise((resolve, reject) => {
Realm.Sync.User.login(this.realmServer, this.props.username, this.props.password, (err, u) => {
if (err) return reject(err);
resolve(u);
});
});
} catch (e) {
return this.props.navigator.resetTo({
screen: 'io.LoginRealm',
title: 'Login into Realm',
passProps: {
error: e
}
});
}
}
let users = [];
for (let key in Realm.Sync.User.all) {
users.push(Realm.Sync.User.all[key]);
}
if (users.length !== 0 && !user) {
user = users[0];
}
if (!user) {
return this.props.navigator.resetTo({
screen: 'io.LoginRealm',
title: 'Login into Realm',
passProps: {
error: 'user is undefined or null'
}
});
}
let realm;
try {
realm = await new Promise((resolve, reject) => {
Realm.openAsync({
schema: Schema,
sync: {
user: user,
url: this.realm
}
}, (error, realm) => {
if (error) return reject(error);
resolve(realm);
}, this.downloadCallback.bind(this));
});
} catch (e) {
console.log("Why");
return requestAnimationFrame(() => {
this.props.navigator.resetTo({
screen: 'io.LoginRealm',
title: 'Login into Realm',
passProps: {
error: e
}
});
});
}
this.workingUpload = false;
this.workingDownload = false;
this.statusText = 'Finishing Database...';
Everything.setRealm(realm);
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');
if (typeof username === 'object' && typeof password === 'object' && typeof host === 'object' && typeof school === 'object' && typeof setup === 'object' && username.value && password.value && host.value && school.value && setup.value) {
Everything.setCredentials(username.value, password.value, host.value, school.value);
Untis.setSettings(username.value, password.value, host.value, school.value);
requestAnimationFrame(() => {
this.props.navigator.resetTo({
screen: 'io.Home',
animated: true,
title: 'Home'
});
});
} else {
requestAnimationFrame(() => {
this.props.navigator.resetTo({
screen: 'io.Login',
animated: true,
navigatorStyle: {
navBarHidden: true,
statusBarTextColorSchemeSingleScreen: 'dark'
}
});
});
}
}
downloadCallback = async (transferred, transferable) => {
this.workingDownload = true;
this.downloadMax = transferable;
this.downloadCurrent = transferred;
this.downloadProgress = percentage.from(transferred, transferable) / 100;
this.statusText = 'Sync Database';
};
render() {
return (
<View style={{
alignContent: "center",
alignItems: "center",
alignSelf: "center",
flex: 1,
justifyContent: "center"
}}>
<Text h5>{this.statusText ? <Text>{this.statusText}</Text> : null}</Text>
{this.workingUpload ? <View>
{/*<Progress.Bar progress={this.uploadProgress}/>*/}
<MKProgress style={{width: Dimensions.get('window').width - 40}} progress={this.uploadProgress}/>
<Text>Upload {this.uploadCurrent ?
<Text>{this.uploadCurrent}</Text> : null}/{this.uploadMax ?
<Text>{this.uploadMax}</Text> : null}</Text>
</View> : null}
{this.workingDownload ? <View style={{
alignContent: 'center',
alignItems: 'center',
alignSelf: 'center',
justifyContent: 'center'
}}>
{/*<Progress.Bar progress={this.downloadProgress}/>*/}
<MKProgress style={{width: Dimensions.get('window').width - 40}} progress={this.downloadProgress}/>
<Text>Download {this.downloadCurrent ?
<Text>{this.downloadCurrent}</Text> : null}/{this.downloadMax ?
<Text>{this.downloadMax}</Text> : null}</Text>
</View> : null}
</View>
);
}
}
export default Database;
也许这只是一些完全愚蠢的事情,我只是没有看到它,但我已经尝试了很多东西,但不知道该怎么做。
问候尼尔斯
最佳答案
我曾经遇到过类似的问题。这个问题来自 react-native 调试桥。尝试禁用 Debug模式。或者,如果它不起作用,请尝试生成并安装发布版本。
关于react-native - JS 线程似乎暂停了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46388226/
谁能帮我解决这个问题?我有一个 Tomcat 和简单的 JSF 应用程序:https://github.com/gooamoko/jsfbilling/ .当我在 Tomcat 上运行应用程序时,它运
我有两个这样的域类,第一个是 Manager : package com.mnm class Manager { String name; static hasMany = [ pro
当我运行以下代码时,打印输出似乎不正确。 void thread_Calc(int *pos) { printf("recieved %d\n", *pos); sig = -1; man
这个问题在这里已经有了答案: How to access a local variable from a different function using pointers? (10 个答案) 关闭
我编写了一个程序,其中列表构建器方法返回 IEnumerable of string,其中包括大量字符串(100 万个项目),我将其存储在 List of string 中,然后它将所有项目附加到 中
我正在尝试编写一个 IRC 类型的聊天客户端,它具有可以连接到服务器的客户端。我试图让它在本地 atm 上工作(使用 FIFOS 而不是套接字)。 我遇到了以下我似乎无法解决的问题: 接受新的客户端连
我的一个 cronjobs 每天发送一封电子邮件 35 6 * * * cd $EZPUBLISHROOT && $PHP runcronjobs.php -q 2>&1 我停止使用 cron sud
我使用 WPF 打印路径来处理在我们的应用程序中创建的大型图表。整个图表由视觉效果组成。 所谓的“DesignerPaginator”对图表进行分页(非常简单)。 从这一点来说,我做了以下三件事: -
我尝试在更新之前跟踪系统应用程序并使用: public static boolean isSystemApplication(Context ctx, IContent content) {
我在这里附上了一个查询分析结果,https://explain.depesz.com/s/x9BN 这是查询 EXPLAIN ANALYZE SELECT branche
我正在做一个 CXF(spring) 项目 (HUB)。部署后,我可以看到肥皂和休息服务列表,我通过两个地址打开它。一种是使用本地主机,第二种是使用我电脑的 ip。所以我得到了这些输出。 使用本地主机
这是一个 AnyHashable 不支持枚举转换的简单案例。 enum testEnum: String { case Test } let myObject: AnyHashable = t
我的主要目标是比较存储在数据库和 XLSX 文件中的数据。 为此,我按以下方式创建了两个列表: private class ProductList { public string produc
我从 CMake 3.6 更新到任何最新版本 (3.12.0-rc2),现在我的一个程序无法编译。 奇怪的是,错误消息显示了标准库本身中的 undefined symbol 。这是错误消息: Unde
我希望将我的自定义对话框动画化为从特定点出现,但我无法为对话框设置动画。 该对话框是一个基本的 RelativeLayout,设置为 extends Dialog 类中的布局。 正如这里的一些答案所建
我已经在这个论坛上调查过很多类似的问题,但似乎没有一个能解决我的问题。 我会在底部列出我在这个论坛上看到的一些问题页面,但让我先谈谈我对这个问题的看法。 我正在使用 codeigniter v 2.x
我正在尝试在 RHEL 7 上启动一个 docker-compose 项目作为 systemd 服务。这是我的 systemd 脚本 (/etc/systemd/system/wp.service):
这个问题已经有答案了: "Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key",
我正在尝试在 RHEL 7 上启动一个 docker-compose 项目作为 systemd 服务。这是我的 systemd 脚本 (/etc/systemd/system/wp.service):
此问题出现在my last question here之后。我想将每个按钮聚焦和失去焦点背景设置为主菜单(ContentPane 即 JPanel)下方的背景颜色,因此按钮看起来像选项卡。它在不同的环
我是一名优秀的程序员,十分优秀!