0
0
React Nativemobile~20 mins

Modal and bottom sheet in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Modal and Bottom Sheet Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
Modal Visibility Toggle Behavior

What will happen when the button inside this React Native modal is pressed?

React Native
import React, { useState } from 'react';
import { View, Text, Button, Modal } from 'react-native';

export default function App() {
  const [visible, setVisible] = useState(false);
  return (
    <View>
      <Button title="Show Modal" onPress={() => setVisible(true)} />
      <Modal visible={visible} transparent={true} animationType="slide">
        <View>
          <Text>Hello Modal</Text>
          <Button title="Close" onPress={() => setVisible(false)} />
        </View>
      </Modal>
    </View>
  );
}
AThe modal appears and closes automatically after 3 seconds without user action.
BThe modal never appears because the visible state is never set to true.
CThe modal appears when 'Show Modal' is pressed and disappears when 'Close' is pressed.
DThe modal appears but cannot be closed because the 'Close' button does not change state.
Attempts:
2 left
💡 Hint

Look at how the visible state changes on button presses.

navigation
intermediate
2:00remaining
Bottom Sheet Dismiss Behavior

In React Native, which method is commonly used to dismiss a bottom sheet component when the user taps outside it?

ADisable user interaction outside the bottom sheet so it cannot be dismissed.
BSet the bottom sheet's visible prop to false without any overlay or touch handling.
CUse a timer to automatically close the bottom sheet after a fixed time.
DUse a transparent overlay with a touchable area that calls a function to close the bottom sheet.
Attempts:
2 left
💡 Hint

Think about how to detect taps outside the bottom sheet area.

lifecycle
advanced
2:00remaining
Modal Component Lifecycle Impact

What happens to the child components inside a React Native Modal when the modal is hidden (visible=false)?

AThe child components are unmounted and destroyed.
BThe child components remain mounted but are not visible on screen.
CThe child components continue to render on screen behind the modal.
DThe child components throw an error because modal is hidden.
Attempts:
2 left
💡 Hint

Consider how React Native handles components inside a modal when visibility changes.

📝 Syntax
advanced
2:00remaining
Correct Syntax for Bottom Sheet State Control

Which code snippet correctly toggles a bottom sheet's visibility state in React Native?

React Native
const [isVisible, setIsVisible] = useState(false);
AsetIsVisible(!isVisible);
BsetIsVisible = !isVisible;
CisVisible = !setIsVisible;
DsetIsVisible.toggle();
Attempts:
2 left
💡 Hint

Remember how to update state using the setter function from useState.

🔧 Debug
expert
3:00remaining
Modal Not Closing on Button Press Debugging

Given this code, why does the modal not close when pressing the 'Close' button?

React Native
import React, { useState } from 'react';
import { View, Text, Button, Modal } from 'react-native';

export default function App() {
  const [visible, setVisible] = useState(false);
  return (
    <View>
      <Button title="Show Modal" onPress={() => setVisible(true)} />
      <Modal visible={visible} transparent={true} animationType="slide">
        <View>
          <Text>Hello Modal</Text>
          <Button title="Close" onPress={() => setVisible(false)} />
        </View>
      </Modal>
    </View>
  );
}
AThe onPress handler is passing the setter function without calling it, so state never changes.
BThe modal's visible prop is misspelled, so it never updates.
CThe useState hook is not imported correctly, causing state to be undefined.
DThe Button component does not support onPress events inside a Modal.
Attempts:
2 left
💡 Hint

Check how the onPress function is written for the 'Close' button.