[英]React Native shows blank screen on phone
after searching for hours I am finally completly lost. 经过几个小时的搜寻,我终于完全迷失了。 I tried to build a simple Dictionary app following an outdated tutorial ( https://code.tutsplus.com/tutorials/creating-a-dictionary-app-using-react-native-for-android--cms-24969 ) for react native.
我试图按照过时的教程( https://code.tutsplus.com/tutorials/creating-a-dictionary-app-using-react-native-for-android--cms-24969 )构建一个简单的Dictionary应用程序当地人。 The standard app after I run "react-native init" works fine on my phone.
我运行“ react-native init”后的标准应用程序可以在手机上正常工作。 However my code just shows a blank screen without any errors.
但是我的代码只是显示一个空白屏幕而没有任何错误。 Below I posted the code, which I used to replace everthing in index.adroid.js.
在下面,我发布了代码,该代码用来替换index.adroid.js中的所有内容。 I would really appreciate it, if you could help me here.
如果您能在这里帮助我,我将不胜感激。 Thanks in advance!
提前致谢!
import React, {Component} from 'react';
import {
AppRegistry,
Text,
View,
TextInput,
StyleSheet,
} from 'react-native';
var english_german = require('./english_german.json');
class Dictionary extends Component {
constructor(props) {
super(props);
this.state = {
input: '',
output: ''
};
}
render() {
return(
<View style={styles.parent}>
<Text>
Type something in English:
</Text>
<TextInput
// style= {{height: 40}}
// placeholder="Type here to translate!"
onChangeText={(text) => this._onTextInputChangeText(text)}
value={this.state.input}
onSubmitEditing={ this.showTranslation().bind(this)} />
<Text style = {styles.germanLabel}>
German translation:
</Text>
<Text style = {styles.germanWord}>
{this.state.output}
</Text>
</View>
);
}
_onTextInputChangeText(text) {
//alert(text);
this.setState({
input : text
})
}
showTranslation() {
var translation = this.state.input in english_german ? english_german[this.state.input] : "Not found";
this.setState({
output: translation
});
}
}
const styles = StyleSheet.create({
// For the container View
parent: {
padding: 16
},
// For the Text label
germanLabel: {
marginTop: 20,
fontWeight: 'bold'
},
// For the Text translation
germanWord: {
marginTop: 15,
fontSize: 30,
fontStyle: 'italic'
}
});
AppRegistry.registerComponent('Dictionary', () => Dictionary);
Thank you guys! 感谢大伙们!
I didn't get the error most of the time, but the syntax error at onSubmitEditing
was the problem. 我大多数时候都没有收到错误,但是
onSubmitEditing
的语法错误是问题所在。 For some reason it didn't work (show anything) when I uncommented the whole TextInput
. 由于某种原因,当我取消注释整个
TextInput
时,它不起作用(显示任何内容)。 Anyway the fix of Michael Cheng to onSubmitEditing={ this.showTranslation.bind(this)}
worked. 无论如何,Michael Cheng修复
onSubmitEditing={ this.showTranslation.bind(this)}
工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.