我写了一个简单的React Native应用程序,它应该显示四个彩色矩形。应用程序可以正常运行,但是只显示一个空白的白屏。我将render函数的内容替换为文本,文本可以正常显示。出了什么问题?
以下是提供的代码:
index.android.js:
以下是提供的代码:
index.android.js:
import React, { Component } from 'react';
import { Text,
AppRegistry,
StyleSheet,
View
} from 'react-native';
import Mainscreen from './components/screens/mainscreen.js';
class styling extends Component {
render() {
return (
<View>
<Mainscreen />
</View>
);
}
}
AppRegistry.registerComponent('styling', () => styling);
Mainscreen.js:
import React,{Component} from 'react';
import {View, StyleSheet} from 'react-native';
export default class Mainscreen extends Component{
render(){
return (
<View style={styles.container}>
<View style={styles.smallContainer}>
<View style={styles.above}>
<View style={styles.leftAbove}></View>
<View style={styles.rightAbove}></View>
</View>
<View style={styles.bottom}>
<View style={styles.leftBottom}></View>
<View style={styles.rightBottom}></View>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container:{
flex:1,
backgroundColor: 'black',
flexDirection:'column'
},
above:{
flex:1,
flexDirection:'row',
marginTop: 10,
marginLeft: 10,
marginBottom: 10,
marginRight: 10
},
bottom:
{
flex:1,
flexDirection:'row',
marginTop: 10,
marginLeft: 10,
marginBottom: 10,
marginRight: 10
},
leftAbove:{
backgroundColor: 'green',
flex: 0.6,
},
rightAbove:{
backgroundColor: 'red',
flex: 0.4,
},
leftBottom:{
backgroundColor: 'blue',
flex: 0.4,
},
rightBottom:{
backgroundColor: 'yellow',
flex: 0.6,
},
smallContainer:{
flex:1,
padding: 10,
backgroundColor:'black'
}
});