Mobile app development

Cheat sheet · Level 3

Ready for the store

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. 1Ask for permission, and handle No

    The camera is private: the app has to ask first.

    What to typeWhat it doesYou see
    const { granted } = await ImagePicker.requestCameraPermissionsAsync();Ask for the camera📱 Report a problem
  2. 2Take a photo

    Open the camera and show the picture.

    What to typeWhat it doesYou see
    const result = await ImagePicker.launchCameraAsync();Open the camera·
    if (!result.canceled) setPhoto(result.assets[0].uri);Only if a photo was taken📱 Report a problem
  3. 3Where am I?

    Fill in the street from the phone's location.

    What to typeWhat it doesYou see
    const pos = await Location.getCurrentPositionAsync();Get the position·
    const [address] = await Location.reverseGeocodeAsync(pos.coords);Numbers to an address·
    setPlace(address.street + ", " + address.city);Show the street and city📱 Where is it?
  4. 4Remind me later

    A notification that brings people back.

    What to typeWhat it doesYou see
    await Notifications.scheduleNotificationAsync({Schedule a notification·
    content: { title: "Fix-It", body: "Your report is waiting. Finish it?" },Its title and words·
    trigger: { seconds: 3600 },In one hour📱 Not finished?
  5. 5Work offline: keep reports in a queue

    No signal? Keep the report, don't lose it.

    What to typeWhat it doesYou see
    const saved = await AsyncStorage.getItem("queue");Load the queue·
    const queue = saved ? JSON.parse(saved) : [];Start empty if there is none·
    queue.push(report);Add the report·
    await AsyncStorage.setItem("queue", JSON.stringify(queue));Save the queue📱 Report a problem
  6. 6Send the queue when back online

    Waiting reports go out by themselves.

    What to typeWhat it doesYou see
    const stop = NetInfo.addEventListener((state) => {Listen for the connection·
    if (state.isConnected) sendQueue();Only when connected·
    return stop;Stop listening when the screen closes📱 Back online
  7. 7Phones and tablets: two layouts

    Use the space on a big screen.

    What to typeWhat it doesYou see
    const { width } = useWindowDimensions();Read the screen width·
    const wide = width >= 600;600 or wider is a tablet·
    <View style={[styles.screen, { flexDirection: wide ? "row" : "column" }]}>Side by side on a tablet📱 Tablet layout: list and map side by side
  8. 8Follow the phone's dark mode

    Dark phone, dark app.

    What to typeWhat it doesYou see
    const scheme = useColorScheme();Ask the phone📱 Theme: dark
  9. 9Screen readers and big text

    Everyone can use the app, even without seeing the screen.

    What to typeWhat it doesYou see
    accessibilityLabel="Take a photo"What the reader says·
    accessibilityRole="button"What it is·
    accessibilityHint="Opens the camera"What a tap does·
    <Text style={styles.title} maxFontSizeMultiplier={1.5}>Report a problem</Text>A title that can't grow too big🔊 Take a photo, button. Opens the camera
  10. 10A long list that stays fast

    500 reports, and the screen still opens at once.

    What to typeWhat it doesYou see
    initialNumToRender={12}Draw the first rows first·
    const Row = memo(function Row({ title }) {Rows draw again only when they change·
    import { memo } from "react";Import memo⏱ First draw: 12 of 500 rows
  11. 11Test a component

    A few lines that check your app for you, every time.

    What to typeWhat it doesYou see
    test("shows Fixed for a fixed report", () => {A second test·
    render(<StatusBadge status="fixed" />);Draw a fixed report·
    expect(screen.getByText("Fixed ✓")).toBeTruthy();Check the words✓ shows Fixed for a fixed report
  12. 12Test a whole flow

    Type, tap, check: like a person would.

    What to typeWhat it doesYou see
    test("sends a report", () => {A new test·
    fireEvent.changeText(screen.getByPlaceholderText("What's broken?"), "Pothole");Type into the box·
    expect(screen.getByText("Thanks! Report sent.")).toBeTruthy();Expect the thanks✓ sends a report
  13. 13Read a crash report

    A red screen is a clue, not a disaster.

    What to typeWhat it doesYou see
    renderItem={({ item }) => <Text style={styles.row}>{item.text} · {item.place?.street ?? "Place not added"}</Text>}Ask only if the place is there📱 Graffiti · Place not added
  14. 14Fix the crash, then add a test

    Make sure that crash never comes back.

    What to typeWhat it doesYou see
    return <Text>{report.text} · {report.place?.street ?? "Place not added"}</Text>;The fix·
    test("shows a report with no place", () => {A test for the crash·
    render(<ReportRow report={{ text: "Graffiti" }} />);A report with no place·
    expect(screen.getByText("Graffiti · Place not added")).toBeTruthy();Expect the fallbackTests: 2 passed, 0 failed
  15. 15App icon, opening screen and name

    What people see before the app even opens.

    What to typeWhat it doesYou see
    name: "Fix-It",The name under the icon·
    icon: "./assets/fixit-icon.png",The icon📱 Fix-It
  16. 16Version number and release notes

    Tell the store, and the people, what's new.

    What to typeWhat it doesYou see
    version: "1.1.0",New features: the middle number goes up·
    ios: { buildNumber: "2" },A new build number (iOS)·
    android: { versionCode: 2 },A new build number (Android)·
    whatsNew: ["Add a photo to a report", "Reports wait and send when you're back online"],What's new📱 Version 1.1.0
  17. 17On your own: the release checklist

    One screen that says when Fix-It is ready to ship.

    What to typeWhat it doesYou see
    const [done, setDone] = useState([]);Ticks in state·
    AsyncStorage.setItem("checklist", JSON.stringify(next));Save them as text·
    const dark = useColorScheme() === "dark";Follow dark mode·
    <Text style={{ color: color, fontWeight: "700" }}>{left === 0 ? "Ready to ship! 🚀" : left + " left before the store"}</Text>Ready to ship📱 2 left before the store