2. what is rn? 6. bloomberg toolset 3. pros/cons 7...

27
Building with React Native Simon Ayzman Mobile Apps Developer @ Bloomberg

Upload: lamkhuong

Post on 07-Feb-2018

215 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Building withReact Native

Simon AyzmanMobile Apps Developer @ Bloomberg

Page 2: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Run-Down

1. Introductions

2. What is RN?

3. Pros/Cons

4. Basic Principles

5. DEMO!

5. Advanced Usage

6. Bloomberg Toolset

7. Awesome Links!

8. Credits

9. Fin!

Page 3: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Introductions

● Mobile App Developer @ Bloomberg

● hackNY Fellow 2015 & Mentor 2016/2017

● CS Adjunct Lecturer at Hunter College (CUNY)

● Long-time dancer in ballet, ballroom, & modern

● Beginner martial artist & improviser

Page 4: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

What is React Native?

“An open source, cross-platform framework for building native mobile apps with JavaScript and React using declarative components.”

-- Facebook’s React Native Documentation

Page 5: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

React Native Framework

Page 6: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Pros

● Multi-platform with native wrappings

● Vibrant open source, developer community

● Faster development time, day-to-day & over time

● Declarative flows aid code comprehension

● Great debugging tools for logic and rendering

Page 7: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Cons

● Technically, still in beta

● Native code needs native knowledge

● Javascript (and its ~wonderful~ ecosystem)

● Minor platform divergences

Page 8: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Basic Principles● Components

○ Props vs. State

■ State represents internal component data

■ Props represent data passed from parent

○ Lifecycle

● Styling

○ Stylesheets are CSS-like; Flexbox support

Page 9: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Stylingimport { StyleSheet } from ‘react-native’;

const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', }, headerView: { marginTop: 15, borderWidth: 10, borderColor: ‘red’, }, headerText: { color: ‘#111111’, fontSize: 65, fontWeight: 'bold', },});

Page 10: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Componentsclass AwesomeComponent extends Component { render() { return ( <View style={styles.container}> <Image source={{ uri: ‘www.coolimages.com/123456’ }} style={styles.header} /> <Text style={styles.welcome}> Welcome to React Native! </Text> <Text style={styles.instructions}> To get started, edit your index.js file. </Text> </View> ); }}

Page 11: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Component Stateclass AwesomeComponent extends Component { constructor() { super(); this.state = { isLoading: false }; }

fetchData() { this.setState({ isLoading: true }); fetch(URL) .then(res => this.setState({ isLoading: false })); }

render() { const { isLoading } = this.state; const loadingDependentText = isLoading ? ‘Hi’ : ‘Bye’; return <Text>{loadingDependentText}</Text> }}

Page 12: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Component Propsclass AwesomeComponent extends Component { static propTypes = { data: PropTypes.arrayOf(PropTypes.number).isRequired, shouldShowData: PropTypes.bool, };

static defaultProps = { shouldShowData: true, };

render() { const { data, shouldShowData } = this.props; if (!shouldShowData) { return null; } const elements = transformDataIntoElements(data); return <View>{elements}</View> }}

Page 13: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Component Lifecycleclass AwesomeComponent extends Component { componentDidMount() { // Lifecycle this.fetchStuffFromTheInterwebs() }

componentWillReceiveProps(nextProps) { // Lifecycle this.doOtherStuffWithProps(this.props, nextProps); }

fetchStuffFromTheInterwebs() { fetch(‘www.geegle.com?q=c001+stUffZ’) .then((response) => doStuff(response)) .catch((error) => console.error(“ERROR”)) } render() { … }}

Page 14: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

DEMO!

Page 15: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

● node (since we’re using Javascript)

● yarn (an alternative to npm)

● create-react-native-app (as global npm module)

● Expo app on your smartphone

Installation Requirements

Page 16: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

● Try building it yourself:

● But for a guided experience:

Startup Requirements

$ create-react-native-app MIT-IPHY$ cd MIT-IPHY$ yarn start

$ git clone https://github.com/simonayzman/MIT-IPHY.git$ cd MIT-IPHY$ yarn install$ git checkout stage0$ yarn start

Page 17: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Open Expo app, scan the QR code output from

the npm start script, and watch the app come to

life...

...a bit anti-climactic, I know. Try changing

the text in App.js yourself! Reload! Voila!

Quick Run

Page 18: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

● start/stage0 to stage1

○ Added an extra line of text to the screen!

● stage1 to stage2

○ Created a simple HomeFeed stub component

● stage2 to stage3

○ Added a list of stub “cells” representing gifs

Demo Progression (I)

Page 19: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

● stage3 to stage4

○ Added helpers and created directory structure

○ Added header, footer, and multiple columns

● stage4 to stage5

○ Add giphy API client to app

○ Added fetch related state to HomeFeed

Demo Progression (II)

Page 20: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

● stage5 to stage6

○ Refactored gif list into separate component

● stage6 to stage7

○ Added data & limit props to GifList

● stage7 to stage8

○ Added MIT gifs toggle to HomeFeed

Demo Progression (III)

Page 21: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

● stage8 to stage9

○ Added new app images

○ Updated gif list layout and individual gif styling

○ Added automatic layout animations

● stage9 to stage10/finish

○ Added sharing functionality on gif tap

Demo Progression (IV)

Page 22: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Advanced Usage

● Redux, an application state management system

● Navigation, a must for most modern apps

● Styling frameworks, for simpler view styling

● Native modules, for when the JS is not enough

● React Native API galore!

Page 23: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Bloomberg Toolset (I)

● Data management

○ redux-thunk, side effects for simple cases

○ redux-saga, side effects with robustness

● Navigation

○ react-navigation

Page 24: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Bloomberg Toolset (II)

● Styling

○ styled-components, so easy with props!

● Testing

○ storybook, easy to test component variations!

○ jest, ok with testing business logic

Page 25: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Awesome Links

● Official React Native Documentation

● Chain React 2017 Conference Videos

● awesome-react-native GitHub Repo

● Rewriting a Large Hybrid App with React Native

● Ignite React Native App Boilerplate Generator

● MIT-IPHY Expo & Codebase

Page 26: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

Credits

● React Native by Artyom Trityak

● A Tour of React Native by Tadeu Zagallo

● Intro to React Native by Jay Garcia

● React Native by Varun Vachhar

● React Native Introduction by Kobkrit Viriyayudhakorn

Page 27: 2. What is RN? 6. Bloomberg Toolset 3. Pros/Cons 7 ...webdevelopment.mit.edu/2018/pages/lectures/WEBday9_reactnative.pdf · Building with React Native Simon Ayzman Mobile Apps Developer

(Thank you!)

FIN