This document provides an introduction to React Native. It begins with an overview of what React Native is and how it allows React code to render natively on iOS and Android using a JavaScript bridge. It then discusses starting a new project using create-react-native-app or react-native init. The rest of the document outlines the roadmap, covering working with styles, layouts, lists, navigation, networking and touching the native side.
Introduction to a React Native workshop including the goals and a roadmap of topics to cover.
Introduction to core concepts of React Native, including state management and rendering methods.
Discussion on reconciliation in React, which determines state changes and updates the application.
Overview of React's support for various platforms, including web, iOS, and Android.
Explanation of how React Native operates with threads and the potential for code reuse across platforms.
Instructions on creating a new React Native project using two options: create-react-native-app and react-native init.
Practical steps to set up the React Native development environment and modifications to components.
Common errors encountered in React Native development and how to handle them effectively.
Guidelines for using basic components in React Native and implementing exercises to solidify knowledge.Explanation of styling in React Native using JavaScript; comparisons to traditional CSS methods.
Introduction to using Flexbox for layout in React Native, including key properties for effective design.
Using lists in React Native, including the FlatList component and exercises for building lists.
Introduction to navigation methods in React Native, including setting up a StackNavigator.
Using the Fetch API within React Native for networking calls and fetching data.
Focus on working with state and modifying native components; handling native package installations.
Recap of key topics covered in the workshop, concluding remarks, and contact info.
Nacho Martin
I writecode at Limenius.
We build tailor-made projects,
and provide consultancy
and formation.
We are very happy with React and React Native.
How Native isReact Native?
JS Thread
Business logic &
Description of what
components to render
28.
How Native isReact Native?
JS Thread Main Thread
UI manipulation
with native
components
Business logic &
Description of what
components to render
29.
How Native isReact Native?
JS Thread Main Thread
UI manipulation
with native
components
Business logic &
Description of what
components to render
Bridge
30.
How much codecan we reuse?
Tip: if you develop in one platform,
test the app in the other from time to time
70%? 80%? 90%?
Option 1: create-react-native-app
OnlyJS, no iOS or Android code
(outside node_modules)
If you want to modify native code, $ npm run eject
Uses the Expo app to test in real device
Meant to have a quick way of trying
react-native
Option 2: react-nativeinit
Complete project with native code
More control
Needed to use things like CodePush
Doesn’t need external tools to publish to
the store
Play around
Open app/App.jswith an editor
<Text style={styles.welcome}>Hi there!</Text>Change the text in
Try nesting
<Text>
<Text style={styles.welcome}>Hi there!</Text>
Amigo
</Text>
Try changing some styles
welcome: {
fontSize: 100,
textAlign: 'center',
margin: 10,
},
Try placing a console.log(‘hi’) before return(… and see it in
Chrome dev tools
https://www.slideshare.net/nachomartin/react-native-workshop-react-alicante
41.
Familiarize with errors
Whathappens if we…
remove a closing tag (</View>)
<View style={styles.container}>
Hi there!
</View>
put text not wrapped in <Text/>
try to comment a JSX line with //
return (
<View style={styles.container}>
<Text style={styles.welcome}>Hi there!</Text>
</View>
<View/>
)
have two root elements
use wrong properties for styles ( rename flex -> flexo )
remove the words export default
Exercise: Build newcomponents
Can you build a new component combining others?
Ideas: Image with footer (<Text/>), two buttons that display different alerts
Can you pass props to that component?
Ideas: Pass the text of the footer with props, pass also the image, pass the titles of the buttons
Can your build a component with local state?
Ideas: Modify the counter to have a “minus 1” button
No CSS. Everythingis JS
<View style={{
borderLeftColor: Colors.accent,
borderLeftWidth: 9,
backgroundColor: Colors.backgroundSection,
padding: 18,
paddingVertical: 9,
}}>
No class
No dimensions in pixels
No things like padding: 19 9 3 1
camelCased
Use constants
Exercise 2
FontSizes.gigantic
Colors.background
Container has:a background with color: Colors.highlight
components/MainHeader.js
Image is 40x90
FontSizes.subhead
With weight ‘200’
Colors.background
Pro exercise:Think how would you add support for themes
Dimensions
import {
Dimensions,
} from'react-native'
const windowSize = Dimensions.get('window')
mainImage: {
height: windowSize.height /3,
width: undefined
},
Our image height depends on the
Height of the window
Use sparingly
components/MovieHeader.js
58.
Dimensions
import {
Dimensions,
} from'react-native'
const windowSize = Dimensions.get('window')
mainImage: {
height: windowSize.height /3,
width: undefined
},
Our image height depends on the
Height of the window
Use sparingly
Exercise: Can you make another style dependant of
Dimensions?
What will happen if the device is rotated?
Can you find anything in the documentation to fix it?
components/MovieHeader.js
This is flexboxrealm
flexDirection
justifyContent
alignItems
alignSelf
flex
alignContent
flexBasis
flexGrow
flexShrink
flexWrap
62.
This is flexboxrealm
flexDirection
justifyContent
alignItems
alignSelf
flex
alignContent
flexBasis
flexGrow
flexShrink
flexWrap
flexDirection: ‘column' flexDirection: ‘row’
(Default)
63.
This is flexboxrealm
flexDirection
justifyContent
alignItems
alignSelf
flex
alignContent
flexBasis
flexGrow
flexShrink
flexWrap
flexDirection: ‘column' flexDirection: ‘row’
(Default)
main direction
crossdirection
64.
This is flexboxrealm
flexDirection
justifyContent
alignItems
alignSelf
flex
alignContent
flexBasis
flexGrow
flexShrink
flexWrap
flexDirection: ‘column' flexDirection: ‘row’
(Default)
main direction
crossdirection
cross direction
maindirection
Exercise 2
Hint: createsubviews if you need them
Optional: can you come up with a different layout for any of our three components?
app/components/MainHeader.js
Exercise
Can you useFlatList in
app/components/MovieList.js ?
git checkout flatLists
item => item
reminder
In this case works as
function(item) {
return item
}
git reset HEAD —hard
(To discard your changes)
Exercise
Can you makea navigation transition from Movie to
app/components/Actor ?
Steps:
- Declare the screen in app/App.js
- Use a TouchableHighlight to capture onPress in the actors
list of <Movie/>
- Provide an appropriate title in <Actor/>
- Make the actor displayed based on
props.navigation.state.params.name
Optional: have a look at
https://reactnavigation.org/docs/en/stack-navigator.html
And tweak the navigation (Ideas: mode modal, add something to headerRight)
Let’s do it
"rnpm":{
"assets": ["./assets/fonts/"]
}
package.json
git checkout mod-native
(To discard your changes)
git reset HEAD --hard
(Expo users: https://docs.expo.io/versions/latest/guides/using-custom-fonts)
123.
Let’s do it
"rnpm":{
"assets": ["./assets/fonts/"]
}
package.json
react-native link
git checkout mod-native
(To discard your changes)
git reset HEAD --hard
(Expo users: https://docs.expo.io/versions/latest/guides/using-custom-fonts)
124.
Assets linked
Changes tobe committed:
(use "git reset HEAD <file>..." to unstage)
new file: android/app/src/main/assets/fonts/OleoScript-Bold.ttf
new file: android/app/src/main/assets/fonts/OleoScript-Regular.ttf
modified: ios/travolta.xcodeproj/project.pbxproj
modified: ios/travolta/Info.plist
modified: package.json
125.
Summary:
What is ReactNative
Starting a project
Working with Styles
Layout
Lists
Navigation
Networking
Touching the native side