0
0
React Nativemobile~20 mins

Image picker in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Image Picker Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What happens when the user taps the image picker button?
In a React Native app using the expo-image-picker library, what is the expected behavior when the user taps the button that triggers the image picker?
AThe app opens the device's photo gallery allowing the user to select an image.
BThe app crashes because the image picker is not supported on mobile devices.
CNothing happens because the button has no onPress handler.
DThe app opens the camera directly without showing the gallery.
Attempts:
2 left
💡 Hint
Think about what the image picker library is designed to do when triggered.
📝 Syntax
intermediate
2:00remaining
Which code snippet correctly requests permission to access the media library?
Select the correct React Native code snippet using expo-image-picker to request permission to access the media library.
Aconst { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
Bconst status = ImagePicker.requestPermissions();
Cconst status = await ImagePicker.getCameraPermissions();
Dconst { permission } = ImagePicker.askForPermissions();
Attempts:
2 left
💡 Hint
Look for the official method name to request media library permissions.
lifecycle
advanced
2:00remaining
When should you request image picker permissions in a React Native app?
Choose the best lifecycle moment to request image picker permissions in a React Native functional component.
ABefore the app is published, in the app.json configuration file.
BEvery time the user taps the image picker button.
CInside a useEffect hook that runs once when the component mounts.
DOnly after the user selects an image.
Attempts:
2 left
💡 Hint
Think about when you want to ask for permission to avoid delays during user interaction.
🔧 Debug
advanced
2:00remaining
Why does this image picker code fail to show the selected image?
Given this code snippet, why does the selected image not appear on the screen? const [image, setImage] = useState(null); const pickImage = async () => { let result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ImagePicker.MediaTypeOptions.Images, allowsEditing: true, quality: 1, }); if (!result.canceled) { setImage(result.assets[0].uri); } }; return (
AThe Image component is missing the resizeMode property, so the image won't display.
BThe code uses result.uri but the correct property is result.assets[0].uri in the latest expo-image-picker version.
CThe pickImage function is not marked async, so it doesn't wait for the picker.
DThe Button component does not have an onPress prop, so the function never runs.
Attempts:
2 left
💡 Hint
Check the structure of the result object returned by the image picker.
🧠 Conceptual
expert
2:00remaining
What is the main reason to ask for image picker permissions before user interaction?
Why is it better to request image picker permissions when the app or component loads rather than when the user taps the button to pick an image?
ABecause the image picker library requires permissions at build time.
BBecause permissions cannot be requested after the app is running.
CTo reduce the app size by preloading permissions.
DTo avoid interrupting the user flow with permission dialogs during image selection.
Attempts:
2 left
💡 Hint
Think about user experience and timing of permission dialogs.