Mobile app development
Cheat sheet 路 Level 1
Build the screens
Every command and idea of this level on one page: what to type, what it does, and what you see.
1Your first screen
One tiny component on the phone.
What to type What it does You see return <Text>Hello, Pocket Pet!</Text>;Return a Text 馃摫 Hello, Pocket Pet! 2One card, many pets
Send a name into a component.
What to type What it does You see return <Text>馃惗 {name}</Text>;Show the name that came in 馃摫 馃惗 Luna 3Every pet from the list
One card per pet, from data.
What to type What it does You see {pets.map((pet) => <PetCard key={pet.id} name={pet.name} />)}One card per pet 馃摫 馃惗 Milo 4Make the cards look good
Give a component a style.
What to type What it does You see <View style={styles.card}>Style the card 路 <Text style={styles.name}>馃惗 {name}</Text>Style the name 馃摫 馃惗 Luna 5Picture next to the name
Put things side by side.
What to type What it does You see card: { flexDirection: "row", alignItems: "center", gap: 12, backgroundColor: "white", padding: 16, borderRadius: 16, marginBottom: 12 },Side by side 路 6Luna's photo
Show a picture.
What to type What it does You see <Image source={{ uri: "cat.jpg" }} style={styles.photo} />Show a picture 馃摫 Luna 7Count the treats
A number that changes on tap.
What to type What it does You see const [treats, setTreats] = useState(0);Make state 路 <Button title="Give a treat" onPress={() => setTreats(treats + 1)} />Change it on tap 馃摫 Treats today: 0 8Nap time
A state that is true or false.
What to type What it does You see const [asleep, setAsleep] = useState(false);Start awake 路 <Button title={asleep ? "Wake up" : "Nap time"} onPress={() => setAsleep(!asleep)} />Flip it on tap 路 <Text style={styles.big}>{asleep ? "馃槾" : "馃惗"}</Text>The face follows 馃摫 馃惗 9Name your pet
A text box that state controls.
What to type What it does You see <TextInput style={styles.box} value={name} onChangeText={setName} placeholder="Pet name" />A text box 馃摫 馃惥 ... 10The right keyboard
Numbers only for the age.
What to type What it does You see keyboardType="number-pad"A number keyboard 路 onChangeText={setAge}Still the same box 路 11Add a pet
Put a new item into a list in state.
What to type What it does You see setPets([...pets, { id: String(Date.now()), name: name }]);A new list with the pet at the end 馃摫 馃惥 Biscuit 12Remove a pet
Take an item out of a list in state.
What to type What it does You see <Pressable key={pet.id} style={styles.pet} onPress={() => setPets(pets.filter((p) => p.id !== pet.id))}>Keep every other pet 馃摫 馃惥 Milo 13When there are no pets yet
Never show a blank screen.
What to type What it does You see {pets.length === 0 ? (Check for an empty list 路 <Text style={styles.emptyText}>No pets yet. Add your first one!</Text>A friendly empty screen 馃摫 No pets yet. Add your first one! 14A top bar of its own
Split a screen into small components.
What to type What it does You see <TopBar />Used in App 馃摫 Pocket Pet 15On your own: the water bowl
State, a goal and two buttons.
What to type What it does You see const [bowls, setBowls] = useState(0);Bowls in state 路 <Button title="+1 bowl" onPress={() => setBowls(bowls + 1)} />Add one 路 <Button title="Start over" onPress={() => setBowls(0)} />Start over 路 {bowls >= 6 && <Text style={styles.done}>Goal reached! 馃挧</Text>}The goal message 馃摫 Bowls today: 0 / 6