Slide 1

Slide 1 text

ComponentKit and React Native Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 1

Slide 2

Slide 2 text

What is it about? » React.js, ComponentKit, React native » Native vs Javascript » UI, do you speak it? Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 2

Slide 3

Slide 3 text

Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 3

Slide 4

Slide 4 text

React.js Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 4

Slide 5

Slide 5 text

React.js Simple “Simply express how your app should look at any given point in time, and React will automatically manage all UI updates when your underlying data changes.” Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 5

Slide 6

Slide 6 text

React.js Declarative “When the data changes, React conceptually hits the "refresh" button, and knows to only update the changed parts.” Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 6

Slide 7

Slide 7 text

React.js Implementation » Just the UI » Virtual DOM* » Data Flow Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 7

Slide 8

Slide 8 text

Few months later... Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 8

Slide 9

Slide 9 text

Awesome! It works! Let's do it Native Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 9

Slide 10

Slide 10 text

UIWebView? Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 10

Slide 11

Slide 11 text

UIWebView? Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 11

Slide 12

Slide 12 text

PhoneGap + React.js Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 12

Slide 13

Slide 13 text

Native vs Javascript Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 13

Slide 14

Slide 14 text

(HTML + JS) vs (UIKit + ObjC) Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 14

Slide 15

Slide 15 text

Screw IT! Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 15

Slide 16

Slide 16 text

Let's do it native! Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 16

Slide 17

Slide 17 text

Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 17

Slide 18

Slide 18 text

ComponentKit Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 18

Slide 19

Slide 19 text

ComponentKit » UIKit » Components » One-Way DataFlow » ObjectiveC++ Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 19

Slide 20

Slide 20 text

Write once, run everywhere Java, Sun Microsystems Learn once, use everywhere React, Facebook Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 20

Slide 21

Slide 21 text

React.js var HelloMessage = React.createClass({ render: function() { return
Hello {this.props.name}
; } }); React.render( , document.getElementById('container') ); Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 21

Slide 22

Slide 22 text

ComponentKit @implementation HelloMessageComponent + (instancetype)newWithName:(NSString*)name { return [super newWithComponent: [CKLabelComponent newWithLabelAttributes:{ .string = [NSString stringWithFormat:@"Hello %@", @name], } viewAttributes:{} ]; } @end Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 22

Slide 23

Slide 23 text

Declarative vs Imperative Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 23

Slide 24

Slide 24 text

Declarative Write what result do you want Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 24

Slide 25

Slide 25 text

Imperative Write how to get the result Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 25

Slide 26

Slide 26 text

A bit complex example declarative + (instancetype)newWithStory:(FBStory *)story { return [super newWithComponent: [FBStackLayoutComponent newWithView:{} size:{} style:{.alignItems = FBStackLayoutAlignItemsStretch} children:{ {[FBHeaderComponent newWithStory:story]}, {[FBMessageComponent newWithStory:story]}, {[FBAttachmentComponent newWithStory:story]}, {[FBLikeBarComponent newWithStory:story]}, }]]; } Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 26

Slide 27

Slide 27 text

A bit complex example imperative @implementation FBStoryView { FBHeaderView *_headerView; FBMessageView *_messageView; FBAttachmentView *_attachmentView; FBLikeBarView *_likeBarView; } - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { _headerView = [[FBHeaderView alloc] init]; _messageView = [[FBMessageView alloc] init]; _attachmentView = [[FBAttachmentView alloc] init]; _likeBarView = [[FBLikeBarView alloc] init]; [self addSubview:_headerView]; [self addSubview:_messageView]; [self addSubview:_attachmentView]; [self addSubview:_likeBarView]; } return self; } - (CGSize)sizeThatFits:(CGSize)size { return CGSizeMake(size.width, [_headerView sizeThatFits:CGSizeMake(size.width, CGFLOAT_MAX)].height + [_messageView sizeThatFits:CGSizeMake(size.width, CGFLOAT_MAX)].height + [_attachmentView sizeThatFits:CGSizeMake(size.width, CGFLOAT_MAX)].height + [_likeBarView sizeThatFits:CGSizeMake(size.width, CGFLOAT_MAX)].height); } - (void)layoutSubviews { CGFloat width = [self bounds].size.width; CGFloat y = 0; CGFloat headerHeight = [_headerView sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)].height; [_headerView setFrame:CGRectMake(0, y, width, headerHeight)]; y += headerHeight; CGFloat messageHeight = [_messageView sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)].height; [_messageView setFrame:CGRectMake(0, y, width, messageHeight)]; y += messageHeight; CGFloat attachmentHeight = [_attachmentView sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)].height; [_attachmentView setFrame:CGRectMake(0, y, width, attachmentHeight)]; y += attachmentHeight; CGFloat likeBarHeight = [_likeBarView sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)].height; [_likeBarView setFrame:CGRectMake(0, y, width, likeBarHeight)]; y += likeBarHeight; } Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 27

Slide 28

Slide 28 text

A bit complex example imperative Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 28

Slide 29

Slide 29 text

Immutability One does not simply mutate component Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 29

Slide 30

Slide 30 text

StateLess* Components tend to be stateless Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 30

Slide 31

Slide 31 text

Virtual "DOM" in ComponentKit How to render all stuff that user written Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 31

Slide 32

Slide 32 text

Component tree -> (Magic) -> UIKit tree Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 32

Slide 33

Slide 33 text

Component is not an UIView Not Every Component backed up with UIView Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 33

Slide 34

Slide 34 text

ComponentKit Layout Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 34

Slide 35

Slide 35 text

Autolayout ? Manual Layout? Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 35

Slide 36

Slide 36 text

Autolayout ? Manual Layout? FlexBox* Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 36

Slide 37

Slide 37 text

ComponentKit is awesome Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 37

Slide 38

Slide 38 text

ComponentKit downsides Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 38

Slide 39

Slide 39 text

ComponentKit downsides » Native (I cannot write for Android) » I need to compile it each time I change something » I cannot share the code Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 39

Slide 40

Slide 40 text

Let's back to Javascript Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 40

Slide 41

Slide 41 text

Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 41

Slide 42

Slide 42 text

React Native Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 42

Slide 43

Slide 43 text

Oh, I know! Javascript + HTML again? Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 43

Slide 44

Slide 44 text

React Native Native Code Bridge Javascript Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 44

Slide 45

Slide 45 text

React Native Native Code Bridge Javascript Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 45

Slide 46

Slide 46 text

React Native Native Code Bridge Javascript Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 46

Slide 47

Slide 47 text

React Native Native Code Bridge Javascript Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 47

Slide 48

Slide 48 text

Nah, It cannot be fast! Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 48

Slide 49

Slide 49 text

Nah, It cannot be fast! It cannot run faster that native Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 49

Slide 50

Slide 50 text

Nah, It renders in UIWebView It's slow! Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 50

Slide 51

Slide 51 text

Nah, It renders in UIWebView It's slow! It uses UIKit for rendering Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 51

Slide 52

Slide 52 text

Nah, I know Native -> JS communication is one-threaded and synchronous Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 52

Slide 53

Slide 53 text

Nah, I know Native -> JS communication is one-threaded and synchronous React Native uses calls batching React Native is fully asynchronous Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 53

Slide 54

Slide 54 text

Nah, I know that... Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 54

Slide 55

Slide 55 text

Stop it! Decide for yourself React Native Playground iOS App Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 55

Slide 56

Slide 56 text

React Native Playground iOS App Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 56

Slide 57

Slide 57 text

React Native Template Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 57

Slide 58

Slide 58 text

React Native Development Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 58

Slide 59

Slide 59 text

React Native Development » Live Reload » Debugging Javascript in Browers » FPS Monitor (Javscrip and UI) » Inspect UI Elements (UIView deubgging) » Profiling » Modules Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 59

Slide 60

Slide 60 text

Ok, I get it What is there any cons? Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 60

Slide 61

Slide 61 text

React Native » Animations » Native Components » Complex gesture recognizers » Extensive computations » new Paradigm Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 61

Slide 62

Slide 62 text

Where to start from? Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 62

Slide 63

Slide 63 text

Where to start from? » M(V)VM » React.js » ComponentKit » React Native Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 63

Slide 64

Slide 64 text

So can Javascript be fast? Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 64

Slide 65

Slide 65 text

So can Javascript be fast? It can be fast enough :) Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 65

Slide 66

Slide 66 text

Links » https://code.facebook.com/posts/1014532261909640/ react-native-bringing-modern-web-techniques-to- mobile/ » http://www.reactnative.com/ » https://developer.mozilla.org/en-US/docs/Web/ Guide/CSS/Flexible_boxes » http://www.objc.io/issues/22-scale/facebook/ » https://code.facebook.com/posts/1014532261909640/ Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 66

Slide 67

Slide 67 text

Links » https://speakerdeck.com/frantic/react-native- under-the-hood » http://www.objc.io/issues/22-scale/facebook/ Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 67

Slide 68

Slide 68 text

Component Kit and React Native by Paul Taykalo, Stanfy Paul Taykalo, ComponentKit and React Native, Stanfy, 2015 68