Bird
Raised Fist0
React Nativemobile~8 mins

Modal and bottom sheet in React Native - Build, Publish & Deploy

Choose your learning style10 modes available
Build & Publish - Modal and bottom sheet
Performance Impact

Using modals and bottom sheets affects app performance mainly during animations and rendering. Smooth animations target 60 frames per second (fps) to feel natural. Poorly optimized modals can cause frame drops, making the UI feel slow or janky. Memory usage is usually low unless the modal loads heavy content like images or videos. Battery impact is minimal but can increase if animations run continuously or if modals keep background tasks alive.

Optimization Tips

To keep modals and bottom sheets smooth at 60fps, limit the complexity of their content. Avoid heavy computations or large images inside the modal. Use React Native's Animated API or libraries like Reanimated for performant animations. Lazy load modal content only when needed. Also, avoid nesting multiple modals to reduce rendering overhead. Use native modal components when possible for better performance.

App Bundle Size and Startup Time

Modals and bottom sheets themselves add minimal size to the app bundle. However, including third-party libraries for advanced bottom sheets can increase bundle size by a few megabytes. Keep dependencies minimal and only include what you use. Large images or videos inside modals can increase app size if bundled. Startup time is usually unaffected unless modals preload heavy data on app launch.

iOS vs Android Differences

On iOS, modals typically use UIKit components under the hood, supporting smooth native transitions and gestures. Bottom sheets follow iOS Human Interface Guidelines with swipe-to-dismiss gestures. Android uses Jetpack Compose or XML layouts with Material Design bottom sheets and modals. Android bottom sheets often support persistent and modal types. Gesture behavior and appearance differ slightly, so test on both platforms to ensure consistent user experience.

Store Review Guidelines
  • Ensure modals do not block critical app functionality or trap users without a clear way to dismiss.
  • Follow accessibility guidelines: provide proper labels, focus management, and support screen readers.
  • Do not use modals for deceptive or disruptive ads, as this violates both Apple App Store and Google Play policies.
  • Respect user privacy if modals request permissions or personal data.
  • Test modal behavior on different device sizes and orientations to meet responsive design requirements.
Self-Check: Slow Modal Load

If your modal takes 5 seconds to appear, likely causes include loading heavy images or data synchronously, running expensive computations on the main thread, or using non-optimized animations. To fix this, lazy load content after modal opens, move heavy work off the UI thread, and simplify animations.

Key Result
Modals and bottom sheets must be optimized for smooth 60fps animations and minimal memory use. Use native components and lazy loading to keep app size small and startup fast. Test on both iOS and Android for consistent behavior and follow store guidelines for accessibility and user experience.

Practice

(1/5)
1. What is the main purpose of a Modal component in React Native?
easy
A. To display content over the current screen and keep user focus
B. To navigate between different screens
C. To create a permanent footer on the screen
D. To handle background tasks silently

Solution

  1. Step 1: Understand what a Modal does

    A Modal appears on top of the current screen and blocks interaction with the background.
  2. Step 2: Compare options

    Only To display content over the current screen and keep user focus describes this behavior correctly; others describe unrelated features.
  3. Final Answer:

    To display content over the current screen and keep user focus -> Option A
  4. Quick Check:

    Modal = Overlay content [OK]
Hint: Modals block background, focus user attention [OK]
Common Mistakes:
  • Confusing Modal with navigation
  • Thinking Modal is a footer or background task
  • Assuming Modal is always full screen
2. Which of the following is the correct way to control the visibility of a Modal in React Native?
easy
A. <Modal show={true}>
B. <Modal visible={true}>
C. <Modal isVisible={true}>
D. <Modal display={true}>

Solution

  1. Step 1: Recall the correct prop for Modal visibility

    The React Native Modal uses the visible prop to show or hide the modal.
  2. Step 2: Check each option

    Only <Modal visible={true}> uses visible correctly; others use incorrect prop names.
  3. Final Answer:

    <Modal visible={true}> -> Option B
  4. Quick Check:

    Modal visibility prop = visible [OK]
Hint: Use visible prop to toggle Modal display [OK]
Common Mistakes:
  • Using show or isVisible instead of visible
  • Confusing display with visible
  • Forgetting to pass boolean value
3. What will happen when the following React Native code runs?
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>
  </>
);
medium
A. The modal appears sliding up when 'Show Modal' is pressed and closes when 'Close' is pressed
B. The modal appears instantly without animation
C. The modal never appears because visible is false initially
D. The modal is always visible and cannot be closed

Solution

  1. Step 1: Understand state controlling Modal visibility

    The state variable modalVisible starts false, so modal is hidden initially.
  2. Step 2: Analyze button actions

    Pressing 'Show Modal' sets modalVisible to true, showing modal with slide animation. 'Close' button sets it back to false, hiding modal.
  3. Final Answer:

    The modal appears sliding up when 'Show Modal' is pressed and closes when 'Close' is pressed -> Option A
  4. Quick Check:

    State controls visible with animation [OK]
Hint: State true shows modal; false hides it [OK]
Common Mistakes:
  • Assuming modal shows without pressing button
  • Ignoring animationType effect
  • Thinking modal cannot be closed
4. Identify the error in this React Native Modal usage:
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)} />
);
medium
A. The onRequestClose prop is missing
B. The Button component is outside the Modal and will not render
C. Modal must be wrapped inside a single parent element
D. The visible prop should be a string, not boolean

Solution

  1. Step 1: Check JSX structure

    The return statement has two sibling elements: Modal and Button, which is invalid JSX without a wrapper.
  2. Step 2: Identify correct fix

    Wrapping Modal and Button inside a fragment or View fixes the error.
  3. Final Answer:

    Modal must be wrapped inside a single parent element -> Option C
  4. Quick Check:

    JSX requires one parent element [OK]
Hint: Wrap siblings in a fragment or View [OK]
Common Mistakes:
  • Ignoring JSX syntax rules
  • Thinking onRequestClose is optional on Android
  • Confusing visible prop type
5. You want to create a bottom sheet modal that slides up from the bottom and closes when tapping outside it. Which combination of props and components achieves this behavior in React Native?
hard
A. Use Modal visible={false} animationType="slide" transparent={true} with no tap detection
B. Use Modal visible={true} animationType="fade" without transparent prop and no tap detection
C. Use Modal visible={true} animationType="none" transparent={false} with a Button inside
D. Use Modal visible={true} animationType="slide" transparent={true} with a TouchableWithoutFeedback wrapping the background to detect taps

Solution

  1. 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.
  2. Step 2: Identify correct props and components

    Using transparent={true} allows background taps. Wrapping background in TouchableWithoutFeedback lets you detect taps to close modal.
  3. Step 3: Eliminate wrong options

    Options B, C, and D miss transparency, correct animation, or tap detection.
  4. Final Answer:

    Use <Modal visible={true} animationType="slide" transparent={true}> with a TouchableWithoutFeedback wrapping the background to detect taps -> Option D
  5. Quick Check:

    Slide + transparent + tap detection = bottom sheet [OK]
Hint: Slide + transparent + tap outside closes modal [OK]
Common Mistakes:
  • Forgetting transparent prop for background tap
  • Using fade animation instead of slide
  • Not handling tap outside to close
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard