Things you should know about React Native - Community · Things you should know about React Native...

28
Things you should know about React Native Neo @ JSConf China 2017

Transcript of Things you should know about React Native - Community · Things you should know about React Native...

Page 1: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Things you should know about React Native

Neo @ JSConf China 2017

Page 2: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

About Me

• Neo, frontend developer@autodesk

• Email: [email protected]

• Github: https://github.com/nihgwu

• Backend / Frontend / App

• Ionic -> React Native

Page 3: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

whosyourdaddy

Page 4: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

I’m your father

Page 5: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

A Brief History

• Mar 27, 2015 - Initial public release

• Sep 15, 2015 - React Native for Android

react-native ionic-native

Page 6: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Props & Cons

• Hot patch / Hot update

• Bring modern web techniques to mobile

• Cross platforms

Page 7: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Props & Cons

• Breaking changes (0.26 / 0.29 / 0.40 / 0.47)

• Docs

• Navigation

Page 8: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Keep Improving

• Android performance

• Nodes

• FlatList / SectionList

• yoga, metro-bundler

• Road map, Monthly meeting

Page 9: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Native Animation

Page 10: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Animation in real world

Navigation Parallax Game

Page 11: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

requestAnimationFrame + setState1. componentWillMount: function() {2. this._current = 1;3. },4. componentDidMount: function() {5. this.animate(null, this.nextAnimation)6. },7. nextAnimation: function() {8. this._current += 1;9. if (this._current >= BatmanLogoPaths.length) return;10.11. this.setState({12. transition: Morph.Tween(BatmanLogoPaths[this._current -

1], BatmanLogoPaths[this._current])13. }, () => this.animate(null, this.nextAnimation))14. },15. animate: function(start, cb) {16. requestAnimationFrame((timestamp) => {17. if (!start) start = timestamp;18. var delta = (timestamp - start) / 1000;19.20. if (delta > 1) return cb();21.22. this.state.transition.tween(delta);23. this.setState(this.state);24. this.animate(start, cb);25. })26. },

http://browniefed.com/blog/react-native-morphing-svg-paths-with-react-art/

Page 12: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Animated

this.state.opacity.setValue(0) Animated.timing(this.state.opacity, { toValue, duration: 1000, }).start()

requestAnimation + setNativeProps

Page 13: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Native Animated

this.state.opacity.setValue(0) Animated.timing(this.state.opacity, { toValue, duration: 1000, }).start()

requestAnimation + setNativeProps

Page 14: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

useNativeDriver: true

this.state.opacity.setValue(0) Animated.timing(this.state.opacity, { toValue, duration: 1000, useNativeDriver: true, }).start()

this.state.opacity.setValue(0) Animated.timing(this.state.opacity, { toValue, duration: 1000, }).start()

onScroll={Animated.event( [{ nativeEvent: { contentOffset: { y: this.state.scrollY } } }], { useNativeDriver: true } )}

onScroll={Animated.event( [{ nativeEvent: { contentOffset: { y: this.state.scrollY } } }] )}

https://facebook.github.io/react-native/blog/2017/02/14/using-native-driver-for-animated.html

Page 15: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Any differences?

Page 16: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Limitations

• Only support transform, opacity

• flexbox, position properties

Page 17: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Recipes

• layout -> transform

• LayoutAnimation

• runAfterInteractions

Page 18: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

“Use Native Animated everywhere possible”

Page 19: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Navigation

• Navigator / react-native-custom-components

• NavigationExperimental

• react-navigation 747 issues, 64 prs)

• react-native-flux-router

• native-navigation

• react-native-navigation

Page 20: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Debug

• Chrome Dev Tools

• React Dev Tools

• React Native Debugger

Page 21: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me
Page 22: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Network Inspectorif (__DEV__) { global.XMLHttpRequest = global.originalXMLHttpRequest ? global.originalXMLHttpRequest : global.XMLHttpRequest global.FormData = global.originalFormData ? global.originalFormData : global.FormData }

Page 23: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Visual Testing

https://github.com/wix/detox

Page 24: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

State Management

• Built-in state

• Redux

• Mobx

• Mobx State Tree

• dva

Page 25: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Tips

• Always use the latest version

• Don’t use any ui frameworks

• F8app is not for beginners

Page 26: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Open source Apps

• Guoqi https://github.com/yuche/gouqi

• Psnine https://github.com/smallpath/psnine

• iShiWuPai https://github.com/ljunb/react-native-iShiWuPai

Page 27: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Resources

• Official site

• Source code

• JS.Coach

• Awesome list

Page 28: Things you should know about React Native - Community · Things you should know about React Native Neo @ JSConf China 2017. About Me

Thanks