2017-07-28 102 views
0
import React, { Component } from 'react'; 
import { View, Text, StyleSheet, TouchableHighlight } from 'react-native'; 

class First extends Component { 
render() { 
    return (
     <View style = {styles.container}> 
      <Text> 
       Hello world! 
      </Text> 
     </View> 
    ); 
    } 
} 

const styles = StyleSheet.create ({ 
container: { 
    backgroundColor: 'yellow', 
    flex: 1 
} 
}); 


module.exports = First; 

此代碼填寫在項目的黃色畫面開始react-native init但顯示沒有在項目啓動時create-react-native-app。這是正常的嗎?陣營母語:Flex的行爲不同

編輯:這是從App.js中錯誤地從風格View調用的。

+0

「_but does not the same_」,它還有什麼作用? –

+0

@KhalilKhalaf它什麼也沒有顯示。 –

回答

0

它會幫助你

import React, { Component } from 'react'; 
import { View, Text, StyleSheet, TouchableHighlight } from 'react-  
native'; 

class First extends Component { 
render() { 
return (
    <View> 
     <Text style = {styles.container}> 
      Hello world! 
     </Text> 
    </View> 
    ); 
    } 
    } 

const styles = StyleSheet.create ({ 
container: { 
backgroundColor: 'yellow', 
flex: 1 
} 
}); 


module.exports = First; 
+0

返回相同的結果。 –

+0

使用顏色代替backgroundcolor –

0

我用你的代碼,並使用create-react-native-app創建應用程序,並顯示在頂部文本hello world!黃色底色離開

這裏,我不得不the-result-using-create-react-native-app

結果

也許你應該使用create-react-native-add命令創建另一個測試應用並查看結果

1

愚蠢的錯誤;我從App.js的主題View中調用這個組件。感謝您花時間幫忙,夥計們。

相關問題