building react web and react native apps with shared code … · building react web and react...

40
Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon Smith: @damondefault

Upload: others

Post on 30-May-2020

70 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Building React web and React Native apps with shared codeTyrone Trevorrow: @tyrone_mpoleeTim Sawtell: @saw083Damon Smith: @damondefault

Page 2: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Outline

1. Why Sportsbet would consider React and React Native

2. What React and React Native offers

3. Live Demo

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 2

Page 3: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

3

Page 4: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Our (old) teams

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 4

Page 5: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

We get things wrong before we get things right.

— Alistair Cockburn

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 5

Page 6: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Our teams

• We're now running scrum, have cross functional teams

• Features go out in lock-step

• 9 feature teams adding more features

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 6

Page 7: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Our front end apps

• 5 year old iOS app

• 4 year old mobile web site

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 7

Page 8: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Our customers

• Our customers use multiple online betting companies

• Our customers want more rewards, better prices and intuitive journeys

• Our product offerings grew, and so did the number of customers

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 8

Page 9: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Our apps are complex

• We solve complex problems in code, and we do that multiple times

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 9

Page 10: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

10

Page 11: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Important code

• Data models and application state

• APIs

• Unit tests

• Business Logic

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 11

Page 12: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

We saw an opportunity

Imagine if ...• The developers could write the

important code once, and style the views in their platform specific variants

12

Page 13: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Imagine if you could

maintainyour high standard forcustomer user experience

13

Page 14: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

14

Page 15: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Due Diligence

• We regularly evaluate new tech

• We apply our operating requirements (our people, our customers)

• Has to be worth it

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 15

Page 16: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

We built a prototype

• React and React Native code base

• Build an existing feature

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 16

Page 17: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

17

Page 18: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

ArchitectureSingle Repository

• Removes all psychological ownership barriers

• Easier to develop in lock-step

• No submodule, npm link pain

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 18

Page 19: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

ArchitectureModules

• Code is broken down into modules, almost like self contained apps

• Based on individual features, and each contain:

• Unit tests

• Platform-specific components

• Cross-platform components

• Business logic, APIs

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 19

Page 20: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

ArchitecturePackagers

• Use the packager for the platform

• Metro (React Native)

• Webpack (Web)

• Expect differences!

• Usually workarounds for everything

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 20

Page 21: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

ArchitecturePlatform specific components

• Should be the only place you do:

• import ... from "react-native", or

• import ... from "react-dom"

• Generally stateless. Functional. Limited business logic.

• Used primarily for layout, styling.

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 21

Page 22: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

ArchitectureContainer Components

• Allows us to "sandwich" platform independent components between platform-specific ones.

• Can be "smart", stateful, contain logic.

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 22

Page 23: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 23

Page 24: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 24

Page 25: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Platform SpecificWeb: Root

iOS: "navigator"

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 25

Page 26: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 26

Page 27: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Platform Independent

"Container"

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 27

Page 28: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

ContainerRoot [Native/Web Platform Specific]└─┬ Container [Cross Platform] └── MatchList [Native/Web Platform Specific]

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 28

Page 29: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Container• Container is cross platform

• Cannot import "react-native" or "react-dom"

• Cannot import platform specific components

• But it can have them passed to it!

• It can import other cross-platform components

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 29

Page 30: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Root...• Root is platform specific

• It can import other platform specific components

• It can import cross-platform components

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 30

Page 31: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

// root.jsx

import { MatchList } from "./web/match_list"import { Container } from "./common/container"

...<Container child={MatchList}>

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 31

Page 32: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 32

Page 33: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 33

Page 34: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Platform Specific

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 34

Page 35: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Platform Specific

• "react-native" vs "react-dom"

• <View> vs <div>

• <Text> vs <div>

• <Image> vs ...... <div>? Really?

• style={} vs plain old CSS

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 35

Page 36: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

We'd love to show you an example ...

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 36

Page 37: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Next steps: Showcase to CIO

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 37

Page 38: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

We trained our developers

• Step by step intro topics

• Coding exercises

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 38

Page 39: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Summary

• Remove duplication

• Build the best customer experience

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 39

Page 40: Building React web and React Native apps with shared code … · Building React web and React Native apps with shared code Tyrone Trevorrow: @tyrone_mpolee Tim Sawtell: @saw083 Damon

Contact Us

Tyrone Trevorrow: @tyrone_mpoleeTim Sawtell: @saw083Damon Smith: @damondefault

Try it yourself

• Our open source code:

https://github.com/sportsbet• The code demo you just saw:

https://github.com/sportsbet/just-the-tip

Tyrone Trevorrow. Tim Sawtell. Damon Smith. 40