創(chuàng)建項目
命令:cd xxxx 目錄
react-native init 工程名字
用webstrom打開
知識點記錄:
- 當屬性為一個組價類型的時候官脓,如果在使用次組件的時候如果沒有這個屬性值,則會報錯卑笨,這時候需要為其制定類型PropTypes.element,加入有個navBtn屬性:
static propTypes = {
rightBtn: PropTypes.element,
}
- 在使用Navigator的時候新版的RN會報錯:
ExceptionsManager.js:63 Navigator is deprecated and has been removed
from this package. It can now be installed and imported from `react-native-
deprecated-custom-components` instead of `react-native`. Learn about
alternative navigation solutions at http://facebook.github.io/react-
native/docs/navigation.html
- 如果按照他的解決方案導入‘react-native-
deprecated-custom-component’后任然會報錯- 使用新的Navigator 芭商, 參考地址:https://reactnavigation.org/docs/intro/
,http://blog.csdn.net/u013147860/article/details/68926816
- 發(fā)現(xiàn)一個很奇怪的現(xiàn)象當我使用Navigation的時候近迁,無論是使用navigator進行跳轉:
const {navigate} = this.props.navigation;
return <View style={styls.container}>
<NavigationBar title={'我的'}/>
<Text onPress={() => navigate('CustomKey',{name:'自定義標簽'})}>自定義標簽</Text>
</View>
還是取值navigator從上一個頁面跳轉過來的值的時候:
const {params} = this.props.navigation.state;
return <View style={styls.container}>
<NavigationBar title={'自定義標簽'}/>
<Text>{params.name}</Text>
</View>
都必須是這種寫法鉴竭,如果是這種將取不到值的:
return <View style={styls.container}>
<NavigationBar title={'自定義標簽'}/>
<Text>{this.props.navigation.state.name}</Text>
</View>
Navigation返回的話用navigation.goBack(null);方法
當我們放置了視圖而沒有看到相應的效果的時候瑰步,往往是視圖沒有設置相應的寬高璧眠,或者fex:1
當一個回調函數(shù)不需要傳參數(shù)的時候可以直接把函數(shù)名賦值給回調屬性,如果需要傳遞參數(shù)的話袁滥,就需要函數(shù)后面帶有括號灾螃,這樣的話就變成調用函數(shù)了,這時候需要箭頭函數(shù)來包裹
Object.keys(arr) 會返回數(shù)組包含數(shù)組所有的下標值嵌赠,或者一個對象的所有的屬性
在render()函數(shù)的return 中 返回的組件一定要和return在同一行熄赡,否則沒有效果。
forceUpdate()強制重新渲染
資料
https://github.com/expo/react-native-tab-navigator
npm install react-native-tab-navigator --save
http://blog.csdn.net/jing85432373/article/details/54342756
npm install --save react-navigation
復選框react-native-check-box
https://github.com/crazycodeboy/react-native-check-box
npm i react-native-check-box --save(兩個橫杠初家,我的mac電腦,不要復制我的)
npm install react-native-vector-icons --savetabView控件
npm install react-native-scrollable-tab-view --saveToast:
npm i react-native-easy-toast --save
import Toast, {DURATION} from 'react-native-easy-toast'
https://github.com/crazycodeboy/react-native-easy-toast可排序的listview
npm install react-native-sortable-listview --save
https://github.com/deanmcpherson/react-native-sortable-listview
github開放api
https://api.github.com/search/repositories?q=${key}&sort=stars獲取github Trending的列表的項目:
https://github.com/crazycodeboy/GitHubTrending解決啟動頁空白頁的問題
react-native-splash-screen*
碰到的問題:
我在mac上前一天蓋上蓋子后陌知,react的服務掛起了掖肋,第二天在引用項目的時候回報錯:找不到這個模塊,但是明明有啊沿盅,點進去還是也有代碼聯(lián)想叭依!!關掉重啟就好了窖铡。