In this lesson, you will learn how to use the Modal component to display isolated task flows or confirmation screens that sit on top of your existing app interface.
What is a Modal?
Think of a modal as a temporary "pop-up" window that takes over the screen to grab the user's full attention. Unlike standard navigation that pushes a new page onto a stack, a modal acts as an overlay layer. It is perfect for self-contained tasks, such as creating a new to-do item, selecting a filter, or forcing a user to confirm a critical action like "Delete Account."
Implementing a Modal
To create a modal, we wrap the content we want to display inside the Modal component. We control its visibility using a boolean state variable. When the state is true, the modal appears; when it is false, it disappears.
Here is a simple example:
import React, { useState } from 'react';
import { Modal, View, Text, Button } from 'react-native';
const TaskModal = () => {
const [isVisible, setIsVisible] = useState(false);
return (
<View>
<Button title="Open Task Creator" onPress={() => setIsVisible(true)} />
<Modal visible={isVisible} animationType="slide">
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Create a new task here!</Text>
<Button title="Close" onPress={() => setIsVisible(false)} />
</View>
</Modal>
</View>
);
};
Why use an isolated layer?
When you use a modal, the underlying screen remains "underneath" the overlay. This provides a clear visual signal to the user that they are in an interrupted flow. Because modals are isolated, they prevent the user from interacting with the main list or background content until they complete or cancel the task inside the modal.
When deciding whether to use a modal versus a standard screen, ask yourself: "Does this task need to be finished before the user returns to what they were doing?" If the answer is yes, a modal is the perfect tool for the job.
Key Takeaway: Use the Modal component to create high-priority, self-contained interaction layers that suspend the background app flow until the task is resolved.