24
CADEC 2018.01.24 | CALLISTAENTERPRISE.SE REACTJS RENDER ANYWHERE? STEPHEN WHITE

REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

CADEC 2018.01.24 | CALLISTAENTERPRISE.SE

REACTJS RENDER ANYWHERE?

STEPHEN WHITE

Page 2: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

CADEC APP

INSTALL - EXPO

Page 3: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

CODE

• https://github.com/callistaenterprise/cadec-2018-reactjs

Page 4: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

AGENDA

• Multiple platforms • Traditional methods • Learn once write anywhere! • Seperation of the dom - React Native • Shared code • Demo • Conclusions

Page 5: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

• Multiple apps for each platform!

MULTIPLE PLATFORMS

Android

IOS

WEB

APP

APP

APP

Page 6: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

TRADITIONAL APPROACH

• One app to rule them all!

Android

IOS

WEBAPP

• One code base! • One web team • Skip the app store! • Releases in realtime • Dev team costs

UIWebView/WKWebView

Page 7: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

WE WANT 60FPS!!

• One app to rule them all, not quite…

Android

IOS

WEBApp

• Slow • Unresponsive • Tech doesn’t reflect the

enormity of the device!

Page 8: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

CADEC APP

INSTALL - EXPO

Page 9: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

LEARN ONCE WRITE ANYWHERE

• What is react? - Its a declarative way of visualising the state of your application. - When the state changes the views update.

Android

IOS

WEB

?

React renderer

A Component

export default ({ title, title2, date }) => ( <HeaderContainer> <HeaderText>{title}</HeaderText> <HeaderUnderSub>{title2}</HeaderUnderSub> <HeaderUnderDate>{date}</HeaderUnderDate> </HeaderContainer>);

Page 10: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

• What is react? - Its a declarative way of visualising the state of your application. - When the state changes the views update.

LEARN ONCE WRITE ANYWHERE

Android

IOS

WEB

?

A Component

export default ({ title, title2, date }) => ( <HeaderContainer> <HeaderText>{title}</HeaderText> <HeaderUnderSub>{title2}</HeaderUnderSub> <HeaderUnderDate>{date}</HeaderUnderDate> </HeaderContainer>);

Renderers

REACT VR REACT HARDWARE REACT NATIVE REACT DOM REACT OSX REACT WINDOWS REACT BLESSED

Page 11: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

REACT NATIVE AND THE SEPARATION OF REACT-DOM

Page 12: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

WHAT WE WANT TO ACHIEVE

80 20

Page 13: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

WALMART ACHIEVED

95 5

Page 14: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

REACT NATIVE

Android

IOS

Page 15: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

SHARED CODE

Components

API

State

Utils

Tests

Styling

Backend

Page 16: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

SHARED CODE - REACT AND FRIENDS

Page 17: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

Native Web

APP.JS

export default compose( LoadFontsHoc, ReduxProviderHoc, ApolloProviderHoc(store))(App);

export default compose( ReduxProviderHoc, ApolloProviderHoc(store))(App);

Page 18: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

Native

STYLES

Web

export const HeaderText = styled.span`${styles.HeaderItemStyle};`;

export const HeaderText = styled.Text` ${styles.HeaderItemStyle}; color: #fff;`;

Shared

export const HeaderItemStyle = ` font-size: 35px; font-family: 'SparTakus'; font-style: normal;`;

Page 19: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

Native

COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS

Web

import React from "react";import { HeaderContainer, HeaderText, HeaderUnderSub, HeaderUnderDate} fromexport default ({ title, title2, date }) => ( <HeaderContainer> <HeaderText>{title}</HeaderText> <HeaderUnderSub>{title2}</HeaderUnderSub> <HeaderUnderDate>{date}</HeaderUnderDate> </HeaderContainer>);

import React from "react";import { HeaderContainer, HeaderBackground, HeaderText, HeaderUnderSub, HeaderUnderDate} fromexport default ({ title, title2, date }) => ( <HeaderContainer> <HeaderText>{title}</HeaderText> <HeaderUnderSub>{title2}</HeaderUnderSub> <HeaderUnderDate>{date}</HeaderUnderDate> </HeaderContainer>);

"cadec-2018-styles/native"; "cadec-2018-styles/web";

<HeaderBackground />

Page 20: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

THE DEMO

DEVELOPER EXPERIENCE

Page 21: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

PROS CONS

• Shared code base • Utilise your web skills • Amazing DX! • Live code updating • Modular and intuitive architecture • Huge Community

PROS CONS

• It’s not Swift • It’s not Java/Kotlin • Still need native experts • Great for business applications but if

you need that bespoke native feeling .. • Startup performance

Page 22: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

CONCLUSIONS

UTILISE YOUR WEB SKILLS

CUT COSTS

GIVE THE KIDS 60FPS

DEVELOPER EXPERIENCE

Page 23: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

OTHER REACT RENDERERS

• React Hardware - http://iamdustan.com/react-hardware/ • React VR - https://facebook.github.io/react-vr/ • React Native Windows - https://github.com/Microsoft/react-native-windows • React Native OSX - https://github.com/ptmt/react-native-macos • React Native - https://facebook.github.io/react-native/ • React Dom - https://reactjs.org

Page 24: REACTJS RENDER ANYWHERE? - Callista Enterprise · Native COMPONENTS - LEARN ONCE WRITE ANYWHERE - HEADER.JS Web import React from "react"; import { HeaderContainer, HeaderText, HeaderUnderSub,

THE DEMO - FILE STRUCTURE - MONO REPO

• Cadec-2018-reactjs - API - Backend - Native - State - Styles - Utils - Web