1 of 49

Go from zero to hero:

Be cross-platform devs with React Native

ARISA FUKUZAKI

DevRel Engineer at Storyblok

2 of 49

3 takeaways from my talk

@arisa_dev

Cross-platform dev potential

Ecosystem in cross-platform dev technologies

React Native examples

3 of 49

Notes ⚠️

@arisa_dev

This talk content is for cross-platform & React Native beginners

The purpose: Aim to show more frontend technology possibilities

Mainly showing webs & mobile OS examples

4 of 49

Cross-platform development

5 of 49

A way to build apps that are compatible with multiple devices/operating systems.

6 of 49

You can reuse 50-80% of your code

7 of 49

A cross-platform app like Discord has

74 million downloads

8 of 49

Comparison with native apps

@arisa_dev

4.9 billion downloads

5.2 billion downloads

281 million downloads

9 of 49

Now, we know

10 of 49

Cross-platform development has quite good numbers and facts.

11 of 49

But, there are many frameworks for cross-platform technologies

12 of 49

You can’t just learn all in one day.

13 of 49

But if you know JavaScript & React,

you already have more than fundamental💪

14 of 49

Learning cost comparison with native app technologies

Learn once

Learn twice

15 of 49

Let’s talk about some cross-platform ecosystem

16 of 49

JavaScript-base

Ships with some pre-built

Ships with some pre-built

Ships with loads of pre-built

Partially adaptive components

Mostly adaptive components

Fully adaptive components

17 of 49

JavaScript-base

Ships with some pre-built

Ships with some pre-built

Ships with loads of pre-built

Partially adaptive components

Mostly adaptive components

Fully adaptive components

18 of 49

JavaScript-base

Ships with some pre-built

Ships with some pre-built

Ships with loads of pre-built

Partially adaptive components

Mostly adaptive components

Fully adaptive components

19 of 49

Choose the best option depends on your cases.

20 of 49

Moving on to fun part: Code examples

21 of 49

2 examples to see

@arisa_dev

React Native stand-alone case

With CMS

22 of 49

React Native Stand-alone Example

23 of 49

Snack

Preview options

Physical devices (Expo Go)

Emulators (Android Studio, Xcode)

@arisa_dev

24 of 49

25 of 49

26 of 49

Use built-in Core Components

@arisa_dev

Others (i.e. StatusBar, etc)

27 of 49

A container to support layout with flexbox, styles & touch handling

<View />

@arisa_dev

import { StatusBar } from 'expo-status-bar';

import { StyleSheet, View, Image } from 'react-native';

//...

export default function App() {

return (

<View style={styles.container}>

<View style={styles.imageContainer}>

<Image />

</View>

<StatusBar style="auto" />

</View>

)

}

//...

App.js

28 of 49

React image component including images from local disc (camera roll)

<Image />

@arisa_dev

import { StatusBar } from 'expo-status-bar';

import { StyleSheet, View, Image } from 'react-native';

//...

export default function App() {

return (

<View style={styles.container}>

<View style={styles.imageContainer}>

<Image

source={PlaceholderImage}

style={styles.image}

/>

</View>

<StatusBar style="auto" />

</View>

)

}

//...

App.js

29 of 49

Similar to CSS StyleSheets

StyleSheet

@arisa_dev

import { StatusBar } from 'expo-status-bar';

import { StyleSheet, View, Image } from 'react-native';

//...

export default function App() {

return (

<View style={styles.container}>

//...

</View>

)

}

const styles = StyleSheet.create({

container: {

flex: 1,

backgroundColor: '#fff',

alignItems: 'center',

},

});

App.js

30 of 49

Alternative of Button. It detects various touch events (single touch, long press, etc)

<Pressable />

@arisa_dev

import { View, Pressable } from 'react-native';

export default function Button({ onPress }) {

return (

<View>

<Pressable

onPress={() => alert('You pressed a

button')}

>

</Pressable>

</View>

);

}

Button.js

App.js

<View>

<Button label="Choose a photo" />

<Button label="Use this photo" />

</View>

31 of 49

32 of 49

3rd party lib API example

@arisa_dev

33 of 49

34 of 49

Workflow

@arisa_dev

2. Save files at user’s media lib

1. Check/request permissions to access media lib

3. Screenshot the view & return an image

35 of 49

@arisa_dev

@storyblok

import * as MediaLibrary from 'expo-media-library';

const [permissionResponse, requestPermission] = MediaLibrary.usePermissions();

permissionResponse === null ? requestPermission() : null

36 of 49

Workflow

@arisa_dev

2. Save files at user’s media lib

1. Check/request permissions to access media lib

3. Screenshot the view & return an image

37 of 49

@arisa_dev

@storyblok

import * as MediaLibrary from 'expo-media-library';

await MediaLibrary.saveToLibraryAsync(localUri);

localUri ? alert("Saved!") : null

38 of 49

Workflow

@arisa_dev

2. Save files at user’s media lib

1. Check/request permissions to access media lib

3. Screenshot the view & return an image

39 of 49

@arisa_dev

@storyblok

import { captureRef } from 'react-native-view-shot';

import { useRef } from 'react';

const localUri = await captureRef(useRef(), {

height: 440,

quality: 1,

});

40 of 49

Now, remember what you saw.

41 of 49

Component-based approach

@arisa_dev

Advanced-app-ready APIs

Syntax is almost the same

42 of 49

React Native & CMS Example

43 of 49

So far, you need to help editing content 😱

44 of 49

You don’t need to do that if you serve content from CMS👍

45 of 49

CMS will serve content across different devices & OS

46 of 49

47 of 49

Logic behind

@arisa_dev

Get access token (CMS → code)

Render dynamic components

Wrap with editable components

Initialize API from CMS

48 of 49

Summary

  • Know built-in APIs → Shortcut to master cross-platform technologies
  • You can build scalable & easy-to-maintain apps

@arisa_dev

49 of 49

Sticker Smash app

https://github.com/schabibi1/StickerSmash

Expo Sticker Smash app tutorial

https://docs.expo.dev/tutorial/introduction/

React Native & headless CMS app

https://github.com/storyblok/storyblok-react-native-starter