1.創(chuàng)建ReactNative工程
cd 項(xiàng)目目錄
react-native init ReactDemo
cd ReactDemo
react-native run-ios
2.ReactNative初始化代碼
// 1.加載React,Componet組件
import React,{compoent} from 'react'
// 2.加載原生組件
import
{
AppRegistry,
StyleSheet,
View,
Text
}
from 'react-native'
// 3.自定義組件,作為程序入口組件
export default class ReactDemo extends Component {
// 當(dāng)加載組件的時候,就會調(diào)用render方法,去渲染組件
render(){
return (
<View style={styles.mainStyle}>
</View>
)
}
}
// 4.創(chuàng)建樣式表
// 傳入一個樣式對象,根據(jù)樣式對象中的描述,創(chuàng)建樣式表
var styles = Stylesheet.create({
mainStyle:{
flex:1,
backgroundColor:'red'
}
})
// 5.注冊組件,程序入口
// 第一個參數(shù):注冊模塊名稱
// 第二個參數(shù):函數(shù), 此函數(shù)返回組件類名, 程序啟動就會自動去加載這個組件
AppRegistry.registerComponent('ReactDemo',()=>ReactDemo)
3. {} () 使用場景
3.1.{}
- 表達(dá)式
style={styles.mainStyle}
- 變量
var str = 'hello'
<Text>{str}</Text>
- 對象和字典
<View style={{flex:1}}></View>
3.2.()
- 創(chuàng)建組件<View></View>用()
render(){ return ( <View style={styles.mainStyle}> </View> ) }
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。