react native redux_sharing

58
REACT NATIVE / REDUX 簡單 不簡單 SAM LEE

Upload: sam-lee

Post on 11-Apr-2017

131 views

Category:

Software


0 download

TRANSCRIPT

Page 1: React native redux_sharing

REACT NATIVE / REDUX 簡單 也 不簡單

SAM LEE

Page 2: React native redux_sharing

Sam Lee : FED : /

Page 3: React native redux_sharing

react-native init AwesomeProject

Page 4: React native redux_sharing

React 是什麼?

Page 5: React native redux_sharing

React JS

VDOMWEB

COMPONENT

Page 6: React native redux_sharing

React Native 又是什麼?

Page 7: React native redux_sharing

React Native

VDOM NATIVEOBJECT

iOSAndroid

WindowsTizen

OSXQT

VR

Page 8: React native redux_sharing

React Native 的原理是?

Page 9: React native redux_sharing

!!!!!!!

Page 10: React native redux_sharing

ReactJS

NativeFunction

JavascriptCore

Javascript Bridge

RCTBridge

Obj-C bridge

Page 11: React native redux_sharing

- 2015/10 - React Native v0.11 ( Support Android)

- 2016/04 in Facebook F8 conference , Microsoft and Samsung have committed to bringing React Native to Windows 10 and Tizen

- 2016/10/06 React VR announcement!

- 2016/10/ React Native v0.35 2 1 release

Page 12: React native redux_sharing

什麼是 Redux ?

Page 13: React native redux_sharing
Page 14: React native redux_sharing

Object: Action: Object:

State: State:

Page 15: React native redux_sharing
Page 16: React native redux_sharing

React Native Redux

+

Page 17: React native redux_sharing

Mobile 常⾒的 UI 結構

Page 18: React native redux_sharing

Redux Provider

Navigator

AUTH NAVIGATOR

MAIN Navigator

SUB NAVIGATOR

SUB NAVIGATOR

SUB NAVIGATOR

Page 19: React native redux_sharing

NAVIGATOR MAIN VIEW

SUB NAVIGATOR

COMPONENT

基本架構

Page 20: React native redux_sharing

Redux 很⽅便

但不能濫⽤ Connect

Page 21: React native redux_sharing

NAVIGATOR MAIN VIEW

SUB NAVIGATOR

COMPONENTConnect with Store Connect with Store

Connect with Store

Connect with Store

資料的傳遞

Page 22: React native redux_sharing

NAVIGATOR MAIN VIEW

SUB NAVIGATOR

COMPONENTConnect with Store Connect with Store

Connect with Store

Connect with Store

Update Update

Update

Update

Dispatch Action

Dispatch Action

Dispatch ActionDispatch Action

資料的傳遞

Page 23: React native redux_sharing

NAVIGATOR MAIN VIEW

SUB NAVIGATOR

COMPONENTConnect with Store

props

propsConnect with Store

Update UpdateDispatch Action

資料的傳遞

Dispatch Action

Update

Update

Page 24: React native redux_sharing

專案最後都會搞⼤, 如果⼀開始⼿法單純, 將來還有機會控制, 反之, 則必然悲劇收場 .

By Jeremy Lu

Page 25: React native redux_sharing

在 React Native經過, 路過, 也不會錯過的

Page 26: React native redux_sharing

不必要的 Render

Page 27: React native redux_sharing

我好像...舉不起來

Page 28: React native redux_sharing

看似 ! 簡單的動作....

Page 29: React native redux_sharing
Page 30: React native redux_sharing

!! ( )

Page 31: React native redux_sharing

從 Code 來看就是這樣⼦

Page 32: React native redux_sharing

ShouldComponentUpdate ShouldComponentUpdate ShouldComponentUpdate

很重要 !!!

Page 33: React native redux_sharing

Deep equal or

Immutable

Page 34: React native redux_sharing

STORE

VIEW

State

Deep Equal:

1. Store 發⽣變化

2. State change

3. Connect 的 Component 觸發 ReRender

4. Deep Equal 判斷 State 內容是否相同

5.⼀樣就不更新 (ShouldComponentUpdate false)

Page 35: React native redux_sharing

STORE

VIEW

State

Immutable:

1. Store 發⽣變化

2. State change

3. Connect 的 Component 觸發 Refresh

4.利⽤ === 判斷指標是否相同

5.⼀樣就不更新 (ShouldComponentUpdate false)

Page 36: React native redux_sharing

簡單來說

Deep Equal ⽤的是⼤腦

Page 37: React native redux_sharing

Immutable ⽤的是

直覺

Page 38: React native redux_sharing

ListView

Page 39: React native redux_sharing

我...拿不動了

Page 40: React native redux_sharing
Page 41: React native redux_sharing

問題點:

ListView 的實現⽅式

- React Native - Scroll View

- Native - Table View

Page 42: React native redux_sharing

不同點:

- React Native - Scroll View (不會回收 ! 不會! 不會 !)

- Native - Table View (⾃動回收機制)

Page 43: React native redux_sharing

78分 不能再低了

Page 44: React native redux_sharing

解法:

⾯對它, 回收它

Page 45: React native redux_sharing

ListView

空⼼VIEW

有內涵的VIEW

空⼼VIEW

有內涵的VIEW

有內涵的VIEW

可視範圍 範圍外範圍外

Page 46: React native redux_sharing

https://github.com/sghiassy/react-native-sglistview

Page 47: React native redux_sharing

Navigator

Page 48: React native redux_sharing

Navigator的原理是Stack!Stack!Stack!

Page 49: React native redux_sharing

注意 Navigator Stack 的狀態

Page 50: React native redux_sharing

⼀直 Push View 就會⼀直變多直到無法控制

(此時如果加上 Store data update)就 GG 了

87分

不能再⾼

Page 51: React native redux_sharing

管理好 Stack

1. Main View 間的跳轉 直接切換

2. Main View -> Sub View 使⽤ Push

3. 轉/跳回 Root Page 時 清空 Stack

Page 52: React native redux_sharing

React Native更新太快!! (好? 壞?)

Page 53: React native redux_sharing

DEMO啦

Page 54: React native redux_sharing

React NativeZ > B

Page 55: React native redux_sharing

React Native Z > B

1.不⽤怕沒有 Solution (上⾯⼀群神⼈在幫你)

2.更新很快, 這次沒有的 Feature 下次可能就有了

3.刻 UI 不⽤等 !!! (省太多時間了)

4.⼀套 Code 同時開發 2 個平台 (Reuse rate ⾼達 80%)

5. 80%的問題都是 1個 solution for 2 個平台(當然 bug 也是⼀次 2 個平台...)

Page 56: React native redux_sharing

當然最⼤的 Z 是....

Page 57: React native redux_sharing

FED is not only for WEB, but also for ALL TERMINALS !!!

Page 58: React native redux_sharing

發問吧! 我可以休息了