Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Core Components  ›  Capstone Project

Modal, ActivityIndicator and StatusBar

Modal 12 minModal shows content above the screen and must handle onRequestClose, ActivityIndicator shows the platform spinner while work is happening, and StatusBar sets how the top system strip looks.

Modal, ActivityIndicator and StatusBar

Three small moments in Sprout: a panel slides up to confirm "Delete this plant?", a spinner shows while the plant list loads, and the clock and battery icons at the top must stay readable on a dark header. Each has its own component.

The rule

Modal overlays, ActivityIndicator waits, StatusBar sets the top strip.

Modal shows content above the current screen. You control it with state:

const [confirmOpen, setConfirmOpen] = useState(false);

<Modal
  visible={confirmOpen}
  animationType="slide"
  transparent
  onRequestClose={() => setConfirmOpen(false)}
>
  <View style={styles.sheet}>
    <Text>Delete this plant?</Text>
    <Button title="Cancel" onPress={() => setConfirmOpen(false)} />
  </View>
</Modal>
  • visible shows or hides it.
  • animationType is 'none', 'slide' or 'fade'.
  • transparent lets the screen behind show through, so you can dim it instead of covering it.
  • onRequestClose runs when the user presses Android's back button (or swipes down a page-sheet modal on iOS). Always handle it, or the user can get stuck.

With transparent, the backdrop is your job: make the modal's outer View fill the screen with flex: 1 and a see-through dark colour such as 'rgba(0,0,0,0.4)', then place the white panel inside it.

ActivityIndicator is the platform's spinner:

{loading ? <ActivityIndicator size="large" color="#2e7d32" /> : <PlantList />}

It takes size ('small' or 'large'), color, and animating. Show it only while something is actually happening, and replace it with content or an error when the work ends.

StatusBar controls the strip with the time and battery. In an Expo project, use the one from expo-status-bar:

import { StatusBar } from 'expo-status-bar';

<StatusBar style="light" />

style can be 'light' (white icons, for dark backgrounds), 'dark', or 'auto' to follow the system theme. React Native's own StatusBar does the same job with barStyle="light-content" or "dark-content".

The shortcut

For every moment, ask "is this blocking, waiting, or framing?" A decision that blocks the screen: Modal. Waiting on work: ActivityIndicator. The frame of the device itself: StatusBar.

Three Sprout momentsStep 1 of 4
  1. Delete confirmation

    Blocking: the user must answer first. Modal with visible from state and onRequestClose.

Drills

Answer fast — trust the rule.

quick drill

What does onRequestClose on a Modal handle?

quick drill

Sprout's header is dark green. Which status bar setting keeps the icons readable?

quick drill

Which prop lets the screen behind a Modal show through?

quick drill

Which component shows the platform's loading spinner?

Remember

  • Modal overlays, ActivityIndicator waits, StatusBar sets the top strip.
  • Ask "blocking, waiting, or framing?"
  • Trap: a Modal without onRequestClose can trap Android users.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainA loading screen and a confirmation

Describe how Sprout should load its plant list and later confirm deleting a plant. Name the components and the key props you would use.