待解決的問題
爲什麼class xxx {
getProfile = () => {
} 這麼寫是什麼語法?以及https://www.jianshu.com/p/dae84967ba92,爲什麼
數組的reduce方法
爲什麼這個函數叫做 Reducer 呢?因爲它可以作爲數組的reduce
方法的參數。請看下面的例子,一系列 Action 對象按照順序作爲一個數組。 不懂?
rn裏app.js “export default App” 在哪裏被import調用?
“每個組件中要用到 store,按之前的方法需要單獨引入Stroe.js”,但是講道理不會import一次執行一次createStore嗎?
export default appState / export const appState異同點
LoginScene裏this.setState({ errMsgVisible: true }) 跳轉頁面的瞬間state全部變回初始值,然後又變回現有值,bug待解決
LoginScene.tsx裏,propsl裏自帶navigation,對於navigation的interface定義要手動?
頁面跳轉但是數據沒跟上時會出現渲染瞬間的白屏,怎麼解決?
bug:無限滾動加載一次就卡頓
detail回到list,going/like數據不同步
涉及的知識點
無限滾動列表的實現:
比較了RN的FlatList和三方的RecyclerListView (https://www.tuicool.com/articles/6NnEjyA),
選擇先熟悉官方親兒子,況且三方可能有坑和隱藏bug。
onEndReachedThreshold傳入的是個頁面百分比
引入redux & redux saga
文件命名:
組件大寫,工具類大寫,其他駝峯
import { call, put, takeEvery } from 'redux-saga/effects' //一定要/effects,否則找不到
Store/State/Action
修改Store的唯一辦法 - Store dispatch 一個 action
store.dispatch({
type: 'ADD_TODO',
payload: 'Learn Redux'
});
Store收到一個Action後,通過Reducer來生成自己新的State。
Reducer接收兩個參數:原State和此Action
Reducer 函數裏面不能改變 State,必須返回一個全新的對象
------------------------------------------------
如何在組件裏使用store?
1、父組件傳入
2、自己引入store
3、更優雅可以使用react-redux (頂層引入<Provider>)
(https://juejin.im/post/5b755537e51d45661d27cdc3)
無限滾動
bug:listScene點擊放大鏡不能打開左側邊欄
debug:因爲調用組件屬性isOpen={}寫成了自己的searchOpen={}
------------------------------------------------
引入ts
=》install 相關包,並生成tsconfg.json
=>文件tsx後綴和ts後綴改寫,內容加上interface改寫
=>改寫tsconfig.json 的 lib 解決ts編譯成js報錯"lib":
["dom","es2016", "es2017"],去掉dom的lib
=>跑tsc,明明刪掉了其他文件只剩login測試頁面,但是其他頁面的js+js.map也在lib裏
=》刪掉lib,重啓,並嘗試直接expo start,居然直接能跑
(原因https://docs.expo.io/versions/latest/guides/typescript/,expo可以直接編譯ts)
=>因此,expo工具下不需要先編譯後打包。一些傳統項目需要js的可以先用tsc命令編譯出js。
=>即使有ts紅線,也可以跑,就像Word文檔有紅線不影響編輯
多語言問題:
使用三方package ‘react-native-i18n’,
即時改變語言不是直接 i18n.locale = ‘en'就可以的,因爲沒有監聽的邏輯,需要setState觸發render方法。
TouchableWithoutFeedback的坑:
svg可以撐起view的寬高,不能撐起TouchableWithoutFeedback的寬高
view可以撐起TouchableWithoutFeedback的寬高,svg不行
rn佈局記錄:
利用flex:n 可以做元素在主軸上的空間分配。
position:absolute 和pc端一樣脫離文檔流,放在dom流前面會因爲脫離文檔流而在z-index層級上被後面的元素覆蓋
頂部和底部固定:
<Parent> flex:1
<top1> height:100
(<top2> height:80)
<middle> flex:1, scrollView組件不需要
<foot1> height:80
(<foot2> height:100)
</Parent>
在該項目後臺中,delete和post請求一樣,需要帶body,即使爲空(JSON.stringify({})),get帶body則報錯
this.setState({activeTypeInd:typeInd});
setTimeout(()=>{
this.getEvents();
},0)
this.setState({activeTypeInd:typeInd});
console.log() //老值
setTimeout(()=>{
console.log() //新值
},0)
子元素在副軸上默認擴展適應,
但是如果手動設置width/height:100%的話,在父元素沒有指定寬度/高度的情況下反而爲0
Text的borderRadius無法框住background會漏出。View就和pc端一樣可以。
Date().getMonth(), 從0開始
同理,new Date(yyyy, mm, dd),其中mm傳12是次年一月,傳13是次年二月,以此類推
today = new Date();
now = this.today.getTime();
todayEnd = new Date(new Date(this.today.toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1).getTime();
tomorrowStart = this.todayEnd + 1;
tomorrowEnd = this.tomorrowStart + 24 * 60 * 60 * 1000 - 1;
weekEnd = this.todayEnd + (7 - (this.today.getDay())) * 24 * 60 * 60 * 1000;
monthEnd = new Date(this.today.getFullYear(), this.today.getMonth(), 1).getTime() - 1;
//總結:記住用法:toLocaleDateString()/getDay()/new Date()
計算屏幕寬高
const { width, height } = Dimensions.get('window');
多級子元素之間,層層emit後又下發的話考慮用redux抽出狀態來達到目的。
評論欄被輸入鍵盤彈上去:
position:'absolute',
//評論欄wrap
<View style={this.state.keyboardShow ?
[styles.container, { position: 'absolute', bottom: this.state.keyboardHeight }] : styles.container}>
//評論欄
</View>
componentDidMount() {
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', (e) => {
this.setState({
keyboardShow: true,
keyboardHeight: e.endCoordinates.height
})
});
this.keyboardWillHideListener = Keyboard.addListener('keyboardWillHide', (e) => {
this.setState({
keyboardShow: false,
keyboardHeight: 0
})
});
}
componentWillUnmount() {
this.keyboardDidShowListener.remove();
this.keyboardWillHideListener.remove();
}
ScrollView組件,不管橫縱向,都不能在組件本身的style裏出現justifyConent或alignItems,但是子元素無所謂。