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.

Take the level exam
  1. 1Your first screen

    One tiny component on the phone.

    What to typeWhat it doesYou see
    return <Text>Hello, Pocket Pet!</Text>;Return a Text馃摫 Hello, Pocket Pet!
  2. 2One card, many pets

    Send a name into a component.

    What to typeWhat it doesYou see
    return <Text>馃惗 {name}</Text>;Show the name that came in馃摫 馃惗 Luna
  3. 3Every pet from the list

    One card per pet, from data.

    What to typeWhat it doesYou see
    {pets.map((pet) => <PetCard key={pet.id} name={pet.name} />)}One card per pet馃摫 馃惗 Milo
  4. 4Make the cards look good

    Give a component a style.

    What to typeWhat it doesYou see
    <View style={styles.card}>Style the card路
    <Text style={styles.name}>馃惗 {name}</Text>Style the name馃摫 馃惗 Luna
  5. 5Picture next to the name

    Put things side by side.

    What to typeWhat it doesYou see
    card: { flexDirection: "row", alignItems: "center", gap: 12, backgroundColor: "white", padding: 16, borderRadius: 16, marginBottom: 12 },Side by side路
  6. 6Luna's photo

    Show a picture.

    What to typeWhat it doesYou see
    <Image source={{ uri: "cat.jpg" }} style={styles.photo} />Show a picture馃摫 Luna
  7. 7Count the treats

    A number that changes on tap.

    What to typeWhat it doesYou see
    const [treats, setTreats] = useState(0);Make state路
    <Button title="Give a treat" onPress={() => setTreats(treats + 1)} />Change it on tap馃摫 Treats today: 0
  8. 8Nap time

    A state that is true or false.

    What to typeWhat it doesYou 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馃摫 馃惗
  9. 9Name your pet

    A text box that state controls.

    What to typeWhat it doesYou see
    <TextInput style={styles.box} value={name} onChangeText={setName} placeholder="Pet name" />A text box馃摫 馃惥 ...
  10. 10The right keyboard

    Numbers only for the age.

    What to typeWhat it doesYou see
    keyboardType="number-pad"A number keyboard路
    onChangeText={setAge}Still the same box路
  11. 11Add a pet

    Put a new item into a list in state.

    What to typeWhat it doesYou see
    setPets([...pets, { id: String(Date.now()), name: name }]);A new list with the pet at the end馃摫 馃惥 Biscuit
  12. 12Remove a pet

    Take an item out of a list in state.

    What to typeWhat it doesYou see
    <Pressable key={pet.id} style={styles.pet} onPress={() => setPets(pets.filter((p) => p.id !== pet.id))}>Keep every other pet馃摫 馃惥 Milo
  13. 13When there are no pets yet

    Never show a blank screen.

    What to typeWhat it doesYou 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!
  14. 14A top bar of its own

    Split a screen into small components.

    What to typeWhat it doesYou see
    <TopBar />Used in App馃摫 Pocket Pet
  15. 15On your own: the water bowl

    State, a goal and two buttons.

    What to typeWhat it doesYou 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