Slide 1

Slide 1 text

React Native Midgame

Slide 2

Slide 2 text

!

Slide 3

Slide 3 text

Radoslav Stankov @rstankov rstankov.com

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

" Side project

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

- implement a mobile app # - one developer (me) $ - support iOS % / Android & - ship it as fast as possible '

Slide 10

Slide 10 text

Going native (swift/kotlin) wasn't an option

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

( backed by Google ) uses Dart * cross platform + compiles to native machine code , custom components - battery included

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

. backed by Facebook / uses Javascript (or TypeScript) 0 uses React 1 cross platform 2 minimal 3 native and JS bridge 4 native components

Slide 18

Slide 18 text

React Native in 2019 was 5 React Native in 2021 was 6 React Native in 2022 was 7 React Native in 2023 still is 7

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

React Native is fast enough has a rich ecosystem Flutter is faster has more batteries included I have done 3 React Native apps previously I know React/TypeScript/GraphQL extremely well I don't know Dart I don't know Flutter

Slide 21

Slide 21 text

source: https://refactoring.fm/p/how-to-choose-technology

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Expo in 2020 was ... 8 Expo in 2020 was ... 9 Expo in 2022 was ... 7 Expo in 2023 is ...:

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

# Tech Stack

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

Architecture

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

0 Make common operations easy 4 Static type-safety 1 Isolate dependencies + Extensibility and reusability

Slide 34

Slide 34 text

0 Make common operations easy 4 Static type-safety 1 Isolate dependencies + Extensibility and reusability

Slide 35

Slide 35 text

2 1 3 Support Components Screens

Slide 36

Slide 36 text

Support Components Screens

Slide 37

Slide 37 text

1) Support 2) Components 3) Screens

Slide 38

Slide 38 text

▾ src/ ▸ components/ ▸ hooks/ ▸ screens/ ▸ styles/ ▸ translations/ ▸ types/ ▸ utils/ config.ts routes.ts app.json App.tsx

Slide 39

Slide 39 text

▾ src/ ▸ components/ ▸ hooks/ ▸ screens/ ▸ styles/ ▸ translations/ ▸ types/ ▸ utils/ config.ts routes.ts app.json App.tsx 1 Support Components Pages 2 3

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

3 Screens

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

▾ src/ ▸ components/ ▸ hooks/ ▸ screens/ ▸ styles/ ▸ translations/ ▸ types/ ▸ utils/ config.ts routes.ts app.json App.tsx

Slide 44

Slide 44 text

▾ src/ ▸ components/ ▸ hooks/ ▸ screens/ ▸ styles/ ▸ translations/ ▸ types/ ▸ utils/ config.ts routes.ts app.json App.tsx

Slide 45

Slide 45 text

{ "expo": { "name": "Angry Building", "version": "1.48.0", "orientation": "portrait", "icon": "./assets/icon.png", "splash": { "image": "./assets/splash.png", "resizeMode": "contain", "backgroundColor": "#252629" } }, // ... }

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

▾ src/ ▸ components/ ▸ hooks/ ▸ screens/ ▸ styles/ ▸ translations/ ▸ types/ ▸ utils/ config.ts routes.ts app.json App.tsx

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

@react-navigation/native

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

... I still don't use it, because it was released fairly recently ; ... however the way the app is setup, transition should be easy <

Slide 53

Slide 53 text

Overlay

Slide 54

Slide 54 text

Overlay Tab Navigation

Slide 55

Slide 55 text

Overlay Tab Navigation Stack Navigation Title

Slide 56

Slide 56 text

Overlay Tab Navigation Stack Navigation Title Screen

Slide 57

Slide 57 text

▾ src/ ▸ components/ ▸ hooks/ ▸ screens/ ▸ styles/ ▸ translations/ ▸ types/ ▸ utils/ config.ts routes.ts app.json App.tsx

Slide 58

Slide 58 text

import screens from 'src/screens'; import { NavigationContainer } from '@react-navigation/native'; import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; import { createStackNavigator } from '@react-navigation/stack'; Sentry.init(); const RootStack = createStackNavigator(); export default function App() { return (

Slide 59

Slide 59 text

export default function App() { return ( ); }

Slide 60

Slide 60 text

const Tab = createBottomTabNavigator(); function TabsScreen() { return (

Slide 61

Slide 61 text

/> ); }

Slide 62

Slide 62 text

const ScreenStack = createStackNavigator(); function Screen(props) { const initialRoute = props.route.params.initialRoute; return ( ); }

Slide 63

Slide 63 text

▾ src/ ▸ components/ ▸ hooks/ ▸ screens/ ▸ styles/ ▸ translations/ ▸ types/ ▸ utils/ config.ts routes.ts app.json App.tsx

Slide 64

Slide 64 text

import apartment from './apartment'; import home from './home'; // ... export default { apartment, home, // ... };

Slide 65

Slide 65 text

Screen States Layout

Slide 66

Slide 66 text

Loading State Screen States Layout

Slide 67

Slide 67 text

Loading State Error State Screen States Layout

Slide 68

Slide 68 text

Loading State Not Found Error Server Error Authorization Error Authentication Error Error State Screen States Layout

Slide 69

Slide 69 text

Loading State Not Found Error Server Error Authorization Error Authentication Error Error State Loaded State Screen States Layout

Slide 70

Slide 70 text

Loading State Not Found Error Server Error Authorization Error Authentication Error Error State Loaded State render Screen States Layout

Slide 71

Slide 71 text

interface IOptions { name: string; query?: DocumentNode; queryVariables?: object | ((params: P) => object); queryRefreshOnShow?: boolean; component: IComponent; type?: keyof typeof layouts; headerTitle?: ITranslation; background: IBackground; } interface IScreen { name: string; options: StackNavigationOptions; component: any; } export default function createScreen(options: IOptions): IScreen // ... }

Slide 72

Slide 72 text

screens/[name]/index.ts (createScreen) -> screens/index.ts -> app.ts

Slide 73

Slide 73 text

export default createScreen({ name: 'home', type: 'plain', query: QUERY, background: 'black', component({ data, fetchMore, refetch }) { usePushNotificationsRegister(); usePushNotificationHandle(data.viewer); return ( ); }, });

Slide 74

Slide 74 text

▾ src/ ▾ screens/ ▾ home/ ▸ Status/ background.png BuildingApartmentsList.tsx Header.tsx index.tsx Query.ts SelectEntrancePicker.tsx

Slide 75

Slide 75 text

http://graphql.org/

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

graphql-codegen --config codegen.yml

Slide 78

Slide 78 text

components/ApartmentStatus/Fragment.tsx import { gql } from '@apollo/client'; export default gql` fragment IApartmentStatusFragment on Apartment { id number name overdueAmount } `;

Slide 79

Slide 79 text

types/grahpql.ts export type IApartmentStatusFragment = { __typename: 'Apartment'; id: string; number?: string | null; name?: string | null; overdueAmount: number; };

Slide 80

Slide 80 text

import { IApartmentStatusFragment } from '~/types/graphql';

Slide 81

Slide 81 text

import { gql } from '@apollo/client'; import IHomeScreenStatusFragment from './Status/Fragment'; import IApartmentStatusFragment from 'src/components/ApartmentStatus/Fragment'; export default gql` query IHomeScreen($cursor: String) { building { id name apartments(first: 100, after: $cursor) { nodes { id name floor isViewerSelected ...IApartmentStatusFragment } pageInfo { hasNextPage endCursor } } ...IHomeScreenStatusFragment } } ${IHomeScreenStatusFragment} ${IApartmentStatusFragment} `; screens/home/Query.ts

Slide 82

Slide 82 text

Screen Component Component Component Component Component Component

Slide 83

Slide 83 text

Query Fragment Fragment Fragment Fragment Fragment Fragment

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

▾ src/ ▸ components/ ▸ hooks/ ▸ screens/ ▸ styles/ ▸ translations/ ▸ types/ ▸ utils/ config.ts routes.ts app.json App.tsx

Slide 86

Slide 86 text

import routes from '~/routes'; 
 routes.back; routes.home; routes.bulletinBoardPostUpdate(post);

Slide 87

Slide 87 text

Slide 88

Slide 88 text

import { useNavigation } from '@react-navigation/native'; import screens from 'src/screens'; type IScreenName = keyof typeof screens; export type IRoute = | { transition: 'goBack' } | { screen: IScreenName; params?: IParams; root?: boolean } | { screen: 'buildingTab' | 'apartmentTab' | 'cashReserveTab' | 'issuesTab'; params?: IParams; root: true; }; const routes = { back: { transition: 'goBack' } as IRoute, home: { root: true, screen: 'buildingTab' } as IRoute, // ... bulletinBoardPostUpdate(post: { id: string }) { return { screen: 'bulletinBoardPostUpdate', params: { post }, } as IRoute; }, };

Slide 89

Slide 89 text

import { useNavigation } from '@react-navigation/native'; import screens from 'src/screens'; type IScreenName = keyof typeof screens; export type IRoute = | { transition: 'goBack' } | { screen: IScreenName; params?: IParams; root?: boolean } | { screen: 'buildingTab' | 'apartmentTab' | 'cashReserveTab' | 'issuesTab'; params?: IParams; root: true; }; const routes = { back: { transition: 'goBack' } as IRoute, home: { root: true, screen: 'buildingTab' } as IRoute, // ... bulletinBoardPostUpdate(post: { id: string }) { return { screen: 'bulletinBoardPostUpdate', params: { post }, } as IRoute; }, };

Slide 90

Slide 90 text

import { useNavigation } from '@react-navigation/native'; import screens from 'src/screens'; type IScreenName = keyof typeof screens; export type IRoute = | { transition: 'goBack' } | { screen: IScreenName; params?: IParams; root?: boolean } | { screen: 'buildingTab' | 'apartmentTab' | 'cashReserveTab' | 'issuesTab'; params?: IParams; root: true; }; const routes = { back: { transition: 'goBack' } as IRoute, home: { root: true, screen: 'buildingTab' } as IRoute, // ... bulletinBoardPostUpdate(post: { id: string }) { return { screen: 'bulletinBoardPostUpdate', params: { post }, } as IRoute; }, };

Slide 91

Slide 91 text

import { useNavigation } from '@react-navigation/native'; import screens from 'src/screens'; type IScreenName = keyof typeof screens; export type IRoute = | { transition: 'goBack' } | { screen: IScreenName; params?: IParams; root?: boolean } | { screen: 'buildingTab' | 'apartmentTab' | 'cashReserveTab' | 'issuesTab'; params?: IParams; root: true; }; const routes = { back: { transition: 'goBack' } as IRoute, home: { root: true, screen: 'buildingTab' } as IRoute, // ... bulletinBoardPostUpdate(post: { id: string }) { return { screen: 'bulletinBoardPostUpdate', params: { post }, } as IRoute; }, };

Slide 92

Slide 92 text

| { screen: IScreenName; params?: IParams; root?: boolean } | { screen: 'buildingTab' | 'apartmentTab' | 'cashReserveTab' | 'issuesTab'; params?: IParams; root: true; }; const routes = { back: { transition: 'goBack' } as IRoute, home: { root: true, screen: 'buildingTab' } as IRoute, // ... bulletinBoardPostUpdate(post: { id: string }) { return { screen: 'bulletinBoardPostUpdate', params: { post }, } as IRoute; }, }; export default routes; export interface INavigation { navigate: (screen: string, params?: IParams) => void; goBack: VoidFunction; }

Slide 93

Slide 93 text

| { screen: IScreenName; params?: IParams; root?: boolean } | { screen: 'buildingTab' | 'apartmentTab' | 'cashReserveTab' | 'issuesTab'; params?: IParams; root: true; }; const routes = { back: { transition: 'goBack' } as IRoute, home: { root: true, screen: 'buildingTab' } as IRoute, // ... bulletinBoardPostUpdate(post: { id: string }) { return { screen: 'bulletinBoardPostUpdate', params: { post }, } as IRoute; }, }; export default routes; export interface INavigation { navigate: (screen: string, params?: IParams) => void; goBack: VoidFunction; }

Slide 94

Slide 94 text

import { useNavigation } from '@react-navigation/native'; import screens from 'src/screens'; type IScreenName = keyof typeof screens; export type IRoute = | { transition: 'goBack' } | { screen: IScreenName; params?: IParams; root?: boolean } | { screen: 'buildingTab' | 'apartmentTab' | 'cashReserveTab' | 'issuesTab'; params?: IParams; root: true; }; const routes = { back: { transition: 'goBack' } as IRoute, home: { root: true, screen: 'buildingTab' } as IRoute, // ... bulletinBoardPostUpdate(post: { id: string }) { return { screen: 'bulletinBoardPostUpdate', params: { post }, } as IRoute; }, };

Slide 95

Slide 95 text

export interface INavigation { navigate: (screen: string, params?: IParams) => void; goBack: VoidFunction; } export function navigate(navigation: INavigation, to: IRoute) { if ('transition' in to) { navigation.goBack(); } else if (to.root) { navigation.navigate('Main', to); } else { navigation.navigate(to.screen, to.params); } } export function useNavigate() { const navigation: any = useNavigation(); const fn = React.useCallback( (to: IRoute) => { navigate(navigation, to); }, [navigation], ); return fn; }

Slide 96

Slide 96 text

import routes, { useNavigate } from '~/routes'; export function MyComponent() { const navigate = useNavigate(); const onPress = () => { navigate(routes.home); } return ( Visit product ); }

Slide 97

Slide 97 text

2 Components

Slide 98

Slide 98 text

▾ src/ ▸ components/ ▸ hooks/ ▸ screens/ ▸ styles/ ▸ translations/ ▸ types/ ▸ utils/ config.ts routes.ts app.json App.tsx

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

If component is used in more than 1 screens then goes to src/components

Slide 101

Slide 101 text

= generic components > domain components

Slide 102

Slide 102 text

[Domain][Name][Type]

Slide 103

Slide 103 text

? Component as directory components/ PublicComponent/ PrivateSubComponent/ Fragment.ts Mutation.ts index.ts styles.ts utils.ts

Slide 104

Slide 104 text

? Component as directory components/ PublicComponent/ PrivateSubComponent/ Fragment.ts Mutation.ts index.ts styles.ts utils.ts

Slide 105

Slide 105 text

Text

Slide 106

Slide 106 text

Slide 107

Slide 107 text

Slide 108

Slide 108 text

Slide 109

Slide 109 text

Slide 110

Slide 110 text

Slide 111

Slide 111 text

No content

Slide 112

Slide 112 text

{...} {...}

Slide 113

Slide 113 text

{...} {...}

Slide 114

Slide 114 text

1 Support

Slide 115

Slide 115 text

No content

Slide 116

Slide 116 text

▾ src/ ▸ components/ ▸ hooks/ ▸ screens/ ▸ styles/ ▸ translations/ ▸ types/ ▸ utils/ config.ts routes.ts app.json App.tsx

Slide 117

Slide 117 text

▾ src/ ▸ components/ ▸ hooks/ ▸ screens/ ▸ styles/ ▸ translations/ ▸ types/ ▸ utils/ config.ts routes.ts app.json App.tsx

Slide 118

Slide 118 text

▾ src/ ▸ components/ ▸ hooks/ ▸ screens/ ▸ styles/ ▸ translations/ ▸ types/ ▸ utils/ config.ts routes.ts app.json App.tsx

Slide 119

Slide 119 text

import { format } from 'date-fns'; export function formatDateTime(date: string) { return format(date, 'H:mm A · MMM D, YYYY'); } utils/date.ts

Slide 120

Slide 120 text

moment date.ts Component Page

Slide 121

Slide 121 text

date.ts Component Page date-fns

Slide 122

Slide 122 text

utils/ external/ Intercom/ OneSignal/ Segment/ Sentry/

Slide 123

Slide 123 text

▾ src/ ▸ components/ ▸ hooks/ ▸ screens/ ▸ styles/ ▸ translations/ ▸ types/ ▸ utils/ config.ts routes.ts app.json App.tsx

Slide 124

Slide 124 text

useGraphQLFragment() useViewier() useIsLoggedIn()

Slide 125

Slide 125 text

▾ src/ ▸ components/ ▸ hooks/ ▸ screens/ ▸ styles/ ▸ translations/ ▸ types/ ▸ utils/ config.ts routes.ts app.json App.tsx

Slide 126

Slide 126 text

@ A B

Slide 127

Slide 127 text

i18next

Slide 128

Slide 128 text

▾ src/ ▾ translations/ bg.json en.json es.json index.ts

Slide 129

Slide 129 text

import i18n from 'i18next'; import captureError from 'src/utils/captureError'; import { isProduction } from 'src/config'; import bg from './bg.json'; import en from './en.json'; import es from './es.json'; // NOTE(rstankov): Documentation https://www.i18next.com/overview/configuration-optio i18n.init({ resources: { bg: { translation: bg, }, en: { translation: en, }, es: { translation: es, }, }, lng: 'bg', saveMissing: true, missingKeyHandler: (_lngs: any, _ns: string, key: string, _fallbackValue: any) => { if (isProduction) { captureError(`Key not found t('${key}')`);

Slide 130

Slide 130 text

import i18n from 'i18next'; import captureError from 'src/utils/captureError'; import { isProduction } from 'src/config'; import bg from './bg.json'; import en from './en.json'; import es from './es.json'; // NOTE(rstankov): Documentation https://www.i18next.com/overview/configuration-optio i18n.init({ resources: { bg: { translation: bg, }, en: { translation: en, }, es: { translation: es, }, }, lng: 'bg', saveMissing: true, missingKeyHandler: (_lngs: any, _ns: string, key: string, _fallbackValue: any) => { if (isProduction) { captureError(`Key not found t('${key}')`);

Slide 131

Slide 131 text

import i18n from 'i18next'; import captureError from 'src/utils/captureError'; import { isProduction } from 'src/config'; import bg from './bg.json'; import en from './en.json'; import es from './es.json'; // NOTE(rstankov): Documentation https://www.i18next.com/overview/configuration-optio i18n.init({ resources: { bg: { translation: bg, }, en: { translation: en, }, es: { translation: es, }, }, lng: 'bg', saveMissing: true, missingKeyHandler: (_lngs: any, _ns: string, key: string, _fallbackValue: any) => { if (isProduction) { captureError(`Key not found t('${key}')`);

Slide 132

Slide 132 text

// NOTE(rstankov): Documentation https://www.i18next.com/overview/configuration-optio i18n.init({ resources: { bg: { translation: bg, }, en: { translation: en, }, es: { translation: es, }, }, lng: 'bg', saveMissing: true, missingKeyHandler: (_lngs: any, _ns: string, key: string, _fallbackValue: any) => { if (isProduction) { captureError(`Key not found t('${key}')`); return key; } throw new Error(`Key not found t('${key}')`); }, compatibilityJSON: 'v3', });

Slide 133

Slide 133 text

// NOTE(rstankov): Documentation https://www.i18next.com/overview/configuration-optio i18n.init({ resources: { bg: { translation: bg, }, en: { translation: en, }, es: { translation: es, }, }, lng: 'bg', saveMissing: true, missingKeyHandler: (_lngs: any, _ns: string, key: string, _fallbackValue: any) => { if (isProduction) { captureError(`Key not found t('${key}')`); return key; } throw new Error(`Key not found t('${key}')`); }, compatibilityJSON: 'v3', });

Slide 134

Slide 134 text

// NOTE(rstankov): Documentation https://www.i18next.com/overview/configuration-optio i18n.init({ resources: { bg: { translation: bg, }, en: { translation: en, }, es: { translation: es, }, }, lng: 'bg', saveMissing: true, missingKeyHandler: (_lngs: any, _ns: string, key: string, _fallbackValue: any) => { if (isProduction) { captureError(`Key not found t('${key}')`); return key; } throw new Error(`Key not found t('${key}')`); }, compatibilityJSON: 'v3', });

Slide 135

Slide 135 text

captureError(`Key not found t('${key}')`); return key; } throw new Error(`Key not found t('${key}')`); }, compatibilityJSON: 'v3', }); export type ITranslation = keyof typeof bg; export type ILanguage = 'bg' | 'en' | 'es'; export default i18n.t as (key: keyof typeof bg, interpolations?: any) => string; export function changeLanguage(newLanguage: ILanguage) { if (i18n.language === newLanguage) { return; } return i18n.changeLanguage(newLanguage); }

Slide 136

Slide 136 text

export type ITranslation = keyof typeof bg; export type ILanguage = 'bg' | 'en' | 'es'; export default i18n.t as (key: keyof typeof bg, interpolations?: any) => string; export function changeLanguage(newLanguage: ILanguage) { if (i18n.language === newLanguage) { return; } return i18n.changeLanguage(newLanguage); }

Slide 137

Slide 137 text

▾ src/ ▸ components/ ▸ hooks/ ▸ screens/ ▸ styles/ ▸ translations/ ▸ types/ ▸ utils/ config.ts routes.ts app.json App.tsx

Slide 138

Slide 138 text

import * as React from 'react'; import { View, StyleSheet } from 'react-native'; import s from 'src/styles'; import Logo from 'src/components/Logo'; export default React.memo(function Ribbon() { return ( <> > ); }); const styles = StyleSheet.create({ container: { backgroundColor: s.colors.black, }, view: { marginTop: 10, borderTopLeftRadius: s.radius, borderTopRightRadius: s.radius, width: '100%',

Slide 139

Slide 139 text

import * as React from 'react'; import { View, StyleSheet } from 'react-native'; import s from 'src/styles'; import Logo from 'src/components/Logo'; export default React.memo(function Ribbon() { return ( <> > ); }); const styles = StyleSheet.create({ container: { backgroundColor: s.colors.black, }, view: { marginTop: 10, borderTopLeftRadius: s.radius, borderTopRightRadius: s.radius, width: '100%',

Slide 140

Slide 140 text

import * as React from 'react'; import { View, StyleSheet } from 'react-native'; import s from 'src/styles'; import Logo from 'src/components/Logo'; export default React.memo(function Ribbon() { return ( <> > ); }); const styles = StyleSheet.create({ container: { backgroundColor: s.colors.black, }, view: { marginTop: 10, borderTopLeftRadius: s.radius, borderTopRightRadius: s.radius, width: '100%',

Slide 141

Slide 141 text

}); const styles = StyleSheet.create({ container: { backgroundColor: s.colors.black, }, view: { marginTop: 10, borderTopLeftRadius: s.radius, borderTopRightRadius: s.radius, width: '100%', height: s.radius * 2, marginBottom: -s.radius, backgroundColor: s.colors.white, }, topBackground: { position: 'absolute', top: -500, height: 500, right: 0, left: 0, backgroundColor: s.colors.black, alignItems: 'center', justifyContent: 'flex-end', paddingBottom: s.spacing.l, }, });

Slide 142

Slide 142 text

const styles = StyleSheet.create({ container: { backgroundColor: s.colors.black, }, view: { marginTop: 10, borderTopLeftRadius: s.radius, borderTopRightRadius: s.radius, width: '100%', height: s.radius * 2, marginBottom: -s.radius, backgroundColor: s.colors.white, }, topBackground: { position: 'absolute', top: -500, height: 500, right: 0, left: 0, backgroundColor: s.colors.black, alignItems: 'center', justifyContent: 'flex-end', paddingBottom: s.spacing.l, }, });

Slide 143

Slide 143 text

Slide 144

Slide 144 text

Slide 145

Slide 145 text

import variables from 'src/styles'; export type ISpacing = keyof typeof spacing; export interface ISpacingProps { marginBottom?: ISpacing | null; marginHorizontal?: ISpacing | null; marginLeft?: ISpacing | null; marginRight?: ISpacing | null; marginTop?: ISpacing | null; marginVertical?: ISpacing | null; margin?: ISpacing | null; padding?: ISpacing | null; paddingBottom?: ISpacing | null; paddingHorizontal?: ISpacing | null; paddingLeft?: ISpacing | null; paddingRight?: ISpacing | null; paddingTop?: ISpacing | null; paddingVertical?: ISpacing | null; } export function spacingStyle(props: ISpacingProps, style: any = {}) { if (props.marginTop) { style.marginTop = variables.spacing[props.marginTop]; } // ... return style; }

Slide 146

Slide 146 text

import { spacingStyle, ISpacing } from '~/styles/spacing'; interface IProps extends ISpacingProps { someProps: any, // ... } function MyComponent(props) { // ... return ( {/* ... */} ); }

Slide 147

Slide 147 text

No content