Intro to React Native
Link to slides:
http://links.uclaacm.com/hoth9-react-native-slides
Link to README:
http://links.uclaacm.com/hoth9-react-native-readme
The Game Plan
DISCLAIMER
💨
React Native
How does one natively react pls help
cross-platform mobile development
✨
✨
✨
✨
✨
✨
✨
Native Mobile Development
iOS Android
Cross-Platform Development
iOS Android
React Native
A fat TL;DR (Summary)
IOS and Android apps are made in different programming languages.
�React Native is a cross-platform Javascript tool that lets us!
Apps using React Native
Basic Setup
Create your first React Native app!
Open VSCode.
You only need to do this once!
Create your first React Native app pt. 2
You can use a simulator or scan the QR code with your phone to open your app on your phone!
Time to fill this with stuff
Javascript and XML’s love child
Javascript – a programming language.
XML - a markup language. (Tells browsers how to format information. Very very similar to HTML.)�
Javascript XML (JSX) - Their baby�
JSX basically lets us write UI in �Javascript.
Javascript
XML
JSX
JSX Cont.
Basically, JSX lets us store “markup” code into variables, and directly write it into JavaScript.
�Note: Save the file after typing code to instantly see your changes!
Components
“View” and “Text” are examples of components. Think of components like basic app elements provided to us!
Ex:
…and
TONS more.
Text and Image
Two bread and butter components that I’ll quickly demonstrate!
Text:
<Text> Ducks go quack </Text>
Image:
<Image source={require(‘./assets/duck.png’)} />
OR
<Image source={{uri: ‘https://someLinkToImage.png’,}}/>
Imports
Remember how React Native is cross-platform?
�DEMO
Views
Views are containers that hold stuff!
<View>
<Text> Hello :D </Text>
</View>
What is all this extra stuff
export default function App() {
return(
<View style={styles.container}>� <Text> Guess what? Chicken butt </Text>� </View>
);
}
Let’s make it pretty!
Stylesheets
Easy (and most common) way to format views
Stylesheet
app:
Demo
Custom Components
What are they: functions you make, that you can insert in multiple places later in your code.
Why this matters: Lets you call one function to reference a whole bunch of code, instead of typing the same code in a bunch of areas.
X
Custom Components Continued -> alliteration!
May be useful to put multiple parts of the same UI element onto the screen.��(UI means user interface– just the stuff the user sees.)
COMPONENT
Now, let’s make our app do something.
TouchableOpacity
DEMO
Screen changes
What if we wanted to have the screen change after the user presses a button?
Button
ACTION
useState()
useState() is a something called a “hook”.
useState()
?????????
Declares a new, constant variable (in this case, an array.)
The current state of whatever the element is.
Ex: *user clicks “Duck!” button.* *User clicks “No more duck!” button.*
A function we’ll call later in the body of our code to change the current state.
The initial value we set. This can be a string, integer, and so on. It’s just whatever value you want to start with.
How to use that current state value
So, we’ve defined our current state using the useState() function. How do we put it into our code?
�<Text>{duckState}</Text>��- This should change the text to whatever the current state “duckState” is.
DEMO
Time to make some ducks
WOOOO we made our first app!
There are still tons of things beyond this workshop that we didn’t cover. Even the stuff in this workshop, you could spend more than an hour on each!
Quick disclaimer for debugging
By now, whether you’ve been coding along or simply vibing to the information, it’s noteworthy to mention that bugs are common. YOU WILL MAKE ERRORS! (Unless you’re a coding god)
Common sources of headache (CHECK THESE!)
Happy Hacking!