← Back to Chapters

React Native Modal

? React Native Modal

? Quick Overview

Modal is a core React Native component used to display content above the current screen. It is commonly used for dialogs, alerts, forms, confirmations, and popups.

? Key Concepts

  • Modal appears on top of the current screen
  • Visibility is controlled using state
  • Supports animation types like slide and fade
  • Can be transparent or full-screen

? Syntax / Theory

The Modal component uses the visible prop to control whether it is shown or hidden. It usually works together with useState.

? View Code Example
// Basic Modal syntax
<Modal
  visible={true}
  animationType="slide"
  transparent={true}
>
</Modal>

? Code Example(s)

? View Code Example
// Modal example using useState
import React, { useState } from "react";
import { View, Text, Modal, Button } from "react-native";

export default function App() {
const [open, setOpen] = useState(false);

return (
<View>
<Button title="Open Modal" onPress={() => setOpen(true)} />

<Modal visible={open} animationType="slide">
<View>
<Text>This is a Modal</Text>
<Button title="Close" onPress={() => setOpen(false)} />
</View>
</Modal>
</View>
);
}

? Live Output / Explanation

What Happens?

  • User taps Open Modal
  • Modal slides from bottom
  • Close button hides the modal

? Interactive Example / Visualization

Interact with the phone simulator below to understand how the Modal component behaves in a real React Native environment.

My Native App

Press button to see Modal

✨ Hello World!

I am a React Native Modal.

? Use Cases

  • Login or signup popups
  • Confirmation dialogs
  • Bottom sheets
  • Image preview overlays

? Tips & Best Practices

  • Always control Modal using state
  • Close modal on back button (Android)
  • Avoid nesting multiple modals

? Try It Yourself

  • Create a fade animation modal
  • Add transparent background overlay
  • Close modal when tapping outside