Slide 1

Slide 1 text

React Native, SVG, and D3 hswolff @hswolff

Slide 2

Slide 2 text

Harry Wolff Senior UI Engineer @ MongoDB.com Blog @ hswolff.com Twitter @ hswolff GitHub @ hswolff

Slide 3

Slide 3 text

What do I know about React Native?

Slide 4

Slide 4 text

Chartbeat iOS http://blog.chartbeat.com/2016/04/07/say-hello-to-the-all-new-chartbeat-ios-app/

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

React Native D3JS D3JS and React Native Project

Slide 7

Slide 7 text

Exercise

Slide 8

Slide 8 text

Exercise 1 Let’s install some prerequisites. https://facebook.github.io/react-native/docs/ getting-started.html Everything up to “Testing your React Native Installation” section.

Slide 9

Slide 9 text

What is React Native?

Slide 10

Slide 10 text

A framework for building native apps with React

Slide 11

Slide 11 text

React Native is built on top of React

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

How does this work?

Slide 17

Slide 17 text

React Native …creates a bridge between JavaScript and Native Code (iOS / Android) …and handles passing information between the two environments More details: http://tadeuzagallo.com/ blog/react-native-bridge/

Slide 18

Slide 18 text

How is React Native different than React?

Slide 19

Slide 19 text

JavaScript Environment

Slide 20

Slide 20 text

No DOM

Slide 21

Slide 21 text

React Native Packager https://github.com/facebook/react- native/tree/master/packager

Slide 22

Slide 22 text

npm friendly

Slide 23

Slide 23 text

Exercise

Slide 24

Slide 24 text

Exercise 1 1. You should have node, watchman, and either Xcode or Android Studio installed. 2. Install React Native CLI: npm install -g react- native-cli 3. react-native init ReactNativeAndD3Workshop 4. cd ReactNativeAndD3Workshop/ 5. react-native run-ios (or react-native run-android)

Slide 25

Slide 25 text

Exercise 1

Slide 26

Slide 26 text

What is SVG?

Slide 27

Slide 27 text

SVG XML-based vector image format

Slide 28

Slide 28 text

SVG • XML: markup language • Human and machine readable • Vector image: use of polygons to represent images • Can be resized without losing quality

Slide 29

Slide 29 text

SVG Elements • Root element: SVG • Creates an SVG fragment, own viewport and coordinate system • Graphic elements: , , , , , , , , , ,

Slide 30

Slide 30 text

Exercise

Slide 31

Slide 31 text

Exercise 2 https://codepen.io/hswolff/pen/ZLpgzy

Slide 32

Slide 32 text

SVG https://developer.mozilla.org/en-US/docs/Web/SVG/ Tutorial/Paths “Paths create complex shapes by combining multiple straight lines or curved lines” “The shape of a path element is defined by one attribute: d.”

Slide 33

Slide 33 text

SVG Create graphics using line commands Move to x 10, y 10 Horizontal line of 90 Vertical line of 90 Horizontal line of 10 Line to x 10, y 10

Slide 34

Slide 34 text

SVG

Slide 35

Slide 35 text

What is D3JS?

Slide 36

Slide 36 text

“a JavaScript library for manipulating documents based on data” https://d3js.org/

Slide 37

Slide 37 text

“D3 helps you bring data to life using HTML, SVG, and CSS.” https://d3js.org/

Slide 38

Slide 38 text

https://d3js.org/

Slide 39

Slide 39 text

D3 4.0 Now Modular

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

d3-scale https://github.com/d3/d3-scale “Continuous scales map a continuous, quantitative input domain to a continuous output range.” Continuous Scales “Given a value from the domain, returns the corresponding value from the range.”

Slide 43

Slide 43 text

d3-scale https://github.com/d3/d3-scale

Slide 44

Slide 44 text

d3-scale https://github.com/d3/d3-scale “Time scales are a variant of linear scales that have a temporal domain: domain values are coerced to dates rather than numbers" Time Scales

Slide 45

Slide 45 text

d3-scale https://github.com/d3/d3-scale

Slide 46

Slide 46 text

d3-shape https://github.com/d3/d3-shape

Slide 47

Slide 47 text

d3-shape https://github.com/d3/d3-shape “line generator can then be used to compute the d attribute of an SVG path element”

Slide 48

Slide 48 text

d3-shape https://github.com/d3/d3-shape

Slide 49

Slide 49 text

d3-shape https://github.com/d3/d3-shape

Slide 50

Slide 50 text

Exercise

Slide 51

Slide 51 text

Exercise 3 https://codepen.io/hswolff/pen/qRaGOE

Slide 52

Slide 52 text

Exercise 3 Answer https://codepen.io/hswolff/pen/egdqbL

Slide 53

Slide 53 text

How does D3JS work with React Native?

Slide 54

Slide 54 text

ART https://github.com/sebmarkbage/art “ART is a retained mode vector drawing API”

Slide 55

Slide 55 text

ART https://github.com/sebmarkbage/art

Slide 56

Slide 56 text

ART https://github.com/sebmarkbage/art

Slide 57

Slide 57 text

React ART https://github.com/reactjs/react-art “React ART is a JavaScript library for drawing vector graphics using React.” “It provides declarative and reactive bindings to the ART library.”

Slide 58

Slide 58 text

React ART https://github.com/reactjs/react-art

Slide 59

Slide 59 text

React Native ART https://github.com/facebook/react-native/tree/master/

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

Exercise

Slide 62

Slide 62 text

Exercise 4 Let’s get React Native ART working!

Slide 63

Slide 63 text

Link ART https://facebook.github.io/react-native/docs/linking- libraries-ios.html#manual-linking

Slide 64

Slide 64 text

Exercise 4 Link React Native ART: http://facebook.github.io/react- native/docs/linking-libraries-ios.html $ open node_modules/react-native/Libraries/ART $ react-native run-ios

Slide 65

Slide 65 text

Exercise 4 Use the React Native ART Component

Slide 66

Slide 66 text

Exercise 4

Slide 67

Slide 67 text

Exercise 4

Slide 68

Slide 68 text

Exercise 4

Slide 69

Slide 69 text

Project

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

index.ios.js js/ Page.js Graph.js Part 1: App structure

Slide 73

Slide 73 text

index.ios.js js/ Page.js Graph.js fixtures.js graph-utils.js Part 2: Graph

Slide 74

Slide 74 text

index.ios.js js/ Page.js Graph.js fixtures.js graph-utils.js Part 3: X Axis

Slide 75

Slide 75 text

index.ios.js js/ Page.js Graph.js fixtures.js graph-utils.js Part 4: Y Axis

Slide 76

Slide 76 text

index.ios.js js/ Page.js Graph.js fixtures.js graph-utils.js ControlButton.js Part 5: Buttons

Slide 77

Slide 77 text

index.ios.js js/ Page.js Graph.js fixtures.js graph-utils.js ControlButton.js Part 6: Animate!

Slide 78

Slide 78 text

Full featured app

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

Open Sourced https://github.com/hswolff/ BetterWeather

Slide 81

Slide 81 text

Resources https://speakerdeck.com/hswolff/react-native- and-d3js https://d3js.org/ http://hswolff.com/blog/react-native-art-and-d3/ https://github.com/hswolff/BetterWeather

Slide 82

Slide 82 text

React Native, SVG, and D3 hswolff @hswolff https://speakerdeck.com/hswolff/react-native-and-d3js