react native - unleash the power of your device

41
React Native Unleash the power of react in your device AMSTERDAM 11-12 MAY 2016 This work is licensed under a Creative Commons Attribution 4.0 International License

Upload: eduard-tomas

Post on 13-Apr-2017

346 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: React native - Unleash the power of your device

React NativeUnleash the power of react in your device

AMSTERDAM 11-12 MAY 2016

This work is licensed under a Creative Commons Attribution 4.0 International License

Page 2: React native - Unleash the power of your device

HELLO!

I am Eduard Tomàs You can find me at @eiximenis

I work @ PlainConcepts http://www.plainconcepts.com

Page 3: React native - Unleash the power of your device

What is React Native?And what makes it different?

Page 4: React native - Unleash the power of your device

That have native UI

React Native is a library to build mobile apps Using JavaScript

and the same workflow and tools that we use to build web applications

Page 5: React native - Unleash the power of your device

What makes React Native fresh and powerful is…

But these are’nt the most important things…

Page 6: React native - Unleash the power of your device

React Native brings the “React way” to mobile development

Page 7: React native - Unleash the power of your device

“Thinking in React”

Page 8: React native - Unleash the power of your device

Only componentsSingle source of

truthOne direction data flow

Page 9: React native - Unleash the power of your device

Reusable Stateless ComponentsAvoiding state in your components not only make them reusable… also can save your life!

State should be stored in a single point.Components should have only “read acces” to this stateComponents should expose an API to change its behavior

Page 10: React native - Unleash the power of your device

React Native architecture

Page 11: React native - Unleash the power of your device

Not a “write once” solutionAt least not yet!

JavaScript code can be shared with iOS and Android applications

UI code (React components) is not totally reusable.

Most components are shared between platforms but some does’nt

This is improving

Page 12: React native - Unleash the power of your device

UI is fully nativeVirtual DOM generated by components is translated to real native UI components.

A react native button is really a UIButton or a android.widget.Button

Page 13: React native - Unleash the power of your device

And about JavaScript…JavaScript is bundled in the application package

JavaScript is executed using JavaScript Core (part of WebKit project)

JavaScript runs in an Asynchronous way…… with native methods calls batched…… exchanging serializable messages (not sharing mutable data)

Page 14: React native - Unleash the power of your device

What about styling?React Native contains a custom implementation of CSS

Based on JavaScript objects (no CSS files exist)

Page 15: React native - Unleash the power of your device
Page 16: React native - Unleash the power of your device

What about layouts?Layout in Android and iOS differs a lot

React Native relies on its own layout system

Basic implementation of CSS flexbox standard

Page 17: React native - Unleash the power of your device

“Functional” UI

Page 18: React native - Unleash the power of your device

f is a pure function

A pure function is a function with no side effects

𝑈𝐼= 𝑓 (𝑑𝑎𝑡𝑎 )

Page 19: React native - Unleash the power of your device
Page 20: React native - Unleash the power of your device

𝑈𝐼= 𝑓 (𝑐𝑜𝑢𝑛𝑡 )

Page 21: React native - Unleash the power of your device
Page 22: React native - Unleash the power of your device
Page 23: React native - Unleash the power of your device
Page 24: React native - Unleash the power of your device

Previous code was from a web project. In mobile <div> and <span> mean nothing but same principles apply.

Only component names change

From web to mobile

Page 25: React native - Unleash the power of your device
Page 26: React native - Unleash the power of your device

Updating the stateState should be on a single place, usually in the “top most” component

Page 27: React native - Unleash the power of your device
Page 28: React native - Unleash the power of your device

CounterPage

TopMost component holding state

Receives events from Counter component and updates its own state

Counter

Stateless component

Have “read only” view of data in their props

Communicates via events

One direction data flow

Page 29: React native - Unleash the power of your device

WANT BIG IMPACT?

USE BIG IMAGE.

Time to code…

Page 30: React native - Unleash the power of your device

The “mobile workflow”Code somethingCompileDeploy on emulatorDo some changesCompile againDeploy againAnd again, and again…

Page 31: React native - Unleash the power of your device

The “React Native Workflow”Code somethingDeploy on emulatorDo some changesRefresh on emulatorNever deploy againJust change code and refresh

Page 32: React native - Unleash the power of your device

The debugging experienceDebugging code is performed through Chrome

As any web application

Page 33: React native - Unleash the power of your device

Navigation

React Native offers one top most component (Navigator) to handle application navigation

Offers an API similar to the HTML5 PushState.

Each scene (screen) is a top react component

Page 34: React native - Unleash the power of your device

WANT BIG IMPACT?

USE BIG IMAGE.

Show me in action!

Page 35: React native - Unleash the power of your device

React Native APIsReact Native come with a lot of APIs to do basic stuff

Most of these APIs exists for both Android and iOS

Page 36: React native - Unleash the power of your device

AppState: manages the application state and notifies changes

AsyncStorage: Persistent key/value storage

CameraRoll: Provides access to local camera roll or gallery

Vibration: Access to the underlying vibration API

fetch: API for performing HTTP Requests. Mimics the same API available in some browsers (i. e. Chrome)

GeoLocation: API for accessing the geo location data. Mimics the same HTML5 API.

Page 37: React native - Unleash the power of your device

Q: Can I interoperate with native code?Yes, you can create a native module using ObjC (for iOS) or Java (for Android)

A native module is a class

For iOS must to conform the RCTBridgeModule protocol

For Anrdoid must extend ReactContextBaseJavaModule class

Page 38: React native - Unleash the power of your device

Q: Can I use native UI controls?Yes, you can expose native UI controls to JavaScript

You can bridge native properties to/from JavaScript code

Can dispatch events from the UI control to JavaScript code

Page 39: React native - Unleash the power of your device

Any questions?You can find me at @eiximenis or contact me using [email protected]

Page 40: React native - Unleash the power of your device

Thanks!

Page 41: React native - Unleash the power of your device

[email protected] Josep Tarradellas, 10, 6º 1ª 08029 Barcelona, España+34 93 3607 114

Barcelona