What if you could show important info without making users leave their current screen?
Why Modal and bottom sheet in React Native? - Purpose & Use Cases
Imagine you want to show a quick message or extra options on your app screen, but you have to create a whole new page and navigate back and forth just to do that.
It feels like opening a new door every time you want to check something small.
Manually creating new screens for small pop-ups is slow and clunky.
Users get lost navigating back and forth, and developers spend too much time managing screen transitions.
It's easy to make mistakes with navigation states and hard to keep the app smooth.
Modals and bottom sheets let you show content on top of the current screen without leaving it.
They slide up or appear as overlays, so users stay in context and developers write less code.
This makes your app feel faster and easier to use.
navigation.navigate('NewScreen')
navigation.goBack()setModalVisible(true);
<Modal visible={modalVisible}>...</Modal>You can create smooth, user-friendly pop-ups and menus that keep users focused and your app responsive.
When you tap a photo in a gallery app, a modal can show the photo details without leaving the gallery.
Or a bottom sheet can slide up with sharing options, letting you act quickly.
Modals and bottom sheets keep users on the same screen while showing extra content.
They reduce navigation complexity and improve user experience.
Using them saves development time and makes apps feel modern and smooth.
Practice
Modal component in React Native?Solution
Step 1: Understand what a Modal does
A Modal appears on top of the current screen and blocks interaction with the background.Step 2: Compare options
Only To display content over the current screen and keep user focus describes this behavior correctly; others describe unrelated features.Final Answer:
To display content over the current screen and keep user focus -> Option AQuick Check:
Modal = Overlay content [OK]
- Confusing Modal with navigation
- Thinking Modal is a footer or background task
- Assuming Modal is always full screen
Modal in React Native?Solution
Step 1: Recall the correct prop for Modal visibility
The React Native Modal uses thevisibleprop to show or hide the modal.Step 2: Check each option
Only<Modal visible={true}>usesvisiblecorrectly; others use incorrect prop names.Final Answer:
<Modal visible={true}> -> Option BQuick Check:
Modal visibility prop = visible [OK]
- Using show or isVisible instead of visible
- Confusing display with visible
- Forgetting to pass boolean value
const [modalVisible, setModalVisible] = React.useState(false);
return (
<>
<Button title="Show Modal" onPress={() => setModalVisible(true)} />
<Modal visible={modalVisible} animationType="slide">
<View>
<Text>Hello Modal</Text>
<Button title="Close" onPress={() => setModalVisible(false)} />
</View>
</Modal>
</>
);Solution
Step 1: Understand state controlling Modal visibility
The state variablemodalVisiblestarts false, so modal is hidden initially.Step 2: Analyze button actions
Pressing 'Show Modal' setsmodalVisibleto true, showing modal with slide animation. 'Close' button sets it back to false, hiding modal.Final Answer:
The modal appears sliding up when 'Show Modal' is pressed and closes when 'Close' is pressed -> Option AQuick Check:
State controls visible with animation [OK]
- Assuming modal shows without pressing button
- Ignoring animationType effect
- Thinking modal cannot be closed
const [show, setShow] = React.useState(false);
return (
<Modal visible={show} animationType="fade" onRequestClose={() => setShow(false)}>
<View>
<Text>Modal Content</Text>
</View>
</Modal>
<Button title="Open" onPress={() => setShow(true)} />
);Solution
Step 1: Check JSX structure
The return statement has two sibling elements: Modal and Button, which is invalid JSX without a wrapper.Step 2: Identify correct fix
Wrapping Modal and Button inside a fragment or View fixes the error.Final Answer:
Modal must be wrapped inside a single parent element -> Option CQuick Check:
JSX requires one parent element [OK]
- Ignoring JSX syntax rules
- Thinking onRequestClose is optional on Android
- Confusing visible prop type
Solution
Step 1: Understand bottom sheet modal requirements
It must slide up (animationType="slide"), be transparent so background is visible, and detect taps outside to close.Step 2: Identify correct props and components
Usingtransparent={true}allows background taps. Wrapping background in TouchableWithoutFeedback lets you detect taps to close modal.Step 3: Eliminate wrong options
Options B, C, and D miss transparency, correct animation, or tap detection.Final Answer:
Use <Modal visible={true} animationType="slide" transparent={true}> with a TouchableWithoutFeedback wrapping the background to detect taps -> Option DQuick Check:
Slide + transparent + tap detection = bottom sheet [OK]
- Forgetting transparent prop for background tap
- Using fade animation instead of slide
- Not handling tap outside to close
Ready to prove it?
Pass the test and this pattern moves unknown
