4色の四角形を表示する単純なReactネイティブアプリを作成しました。アプリは正常に動作しますが、アプリは空の白い画面しか表示していません。レンダリング機能の内容をテキストだけに置き換えました。これは正しく表示されています。何がうまくいかないのですか?空白の画面が表示されます - ネイティブに反応します
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'
}
});
なぜインポートステートメントで ".js"を使用していますか?また、ファイル名がMainScreen.jsの場合(ファイル名が大文字Mであると仮定して)、import文は次のようになります。import Mainscreen from './components/screens/Mainscreen';また、私はあなたがインポートしているファイルへのパスが正しいと仮定しています。 –
はい正しいパスを使用しています。 mainscreen.jsのMainscreenクラス。私は全体の "ビュー"をテキストで置き換えようとしましたが、それは正しく表示されます。問題は、ネストされたViews自体にあります。 @Ankit Aggarwal –
スタイリングに問題があります。 flex:1を次から削除: "container"、 "smallContainer"、 "above"、 "bottom"スタイル。また、「上」と「下」のスタイルにいくらかの高さを与えます。それは動作します。理由を見つけることを試みる –