Challenge - 5 Problems
Device Info and Haptics Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Detecting Device Orientation Change
What will be the output behavior when the device orientation changes in this React Native component?
React Native
import React, { useState, useEffect } from 'react'; import { View, Text, Dimensions } from 'react-native'; export default function Orientation() { const [orientation, setOrientation] = useState('portrait'); useEffect(() => { const updateOrientation = () => { const { width, height } = Dimensions.get('window'); setOrientation(width > height ? 'landscape' : 'portrait'); }; Dimensions.addEventListener('change', updateOrientation); updateOrientation(); return () => Dimensions.removeEventListener('change', updateOrientation); }, []); return <View><Text>{`Orientation: ${orientation}`}</Text></View>; }
Attempts:
2 left
💡 Hint
Check how Dimensions event listeners update state on orientation change.
✗ Incorrect
The component listens to dimension changes and updates the orientation state accordingly, so the text reflects the current orientation.
❓ ui_behavior
intermediate1:30remaining
Triggering Haptic Feedback on Button Press
Which option correctly triggers a light haptic feedback when the button is pressed in React Native?
React Native
import React from 'react'; import { Button } from 'react-native'; import * as Haptics from 'expo-haptics'; export default function HapticButton() { return <Button title="Press me" onPress={() => Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light)} />; }
Attempts:
2 left
💡 Hint
Look for the method that triggers impact feedback with a light style.
✗ Incorrect
Haptics.impactAsync with ImpactFeedbackStyle.Light triggers a light vibration effect on supported devices.
❓ lifecycle
advanced2:30remaining
Cleaning Up Device Orientation Listener
What is the problem with this React Native code regarding device orientation listener cleanup?
React Native
import React, { useEffect, useState } from 'react'; import { Dimensions, Text, View } from 'react-native'; export default function Orientation() { const [orientation, setOrientation] = useState('portrait'); useEffect(() => { const handler = () => { const { width, height } = Dimensions.get('window'); setOrientation(width > height ? 'landscape' : 'portrait'); }; Dimensions.addEventListener('change', handler); return () => { Dimensions.removeEventListener('change', handler); }; }, []); return <View><Text>{orientation}</Text></View>; }
Attempts:
2 left
💡 Hint
Check how the removeEventListener function is called with the handler argument.
✗ Incorrect
The cleanup uses an anonymous arrow function wrapping handler, which is a different function reference than the one added, so the listener is not removed properly.
📝 Syntax
advanced1:30remaining
Correct Syntax for Using Haptics in React Native
Which code snippet correctly imports and uses Expo Haptics to trigger a medium impact feedback?
Attempts:
2 left
💡 Hint
Check the exact casing of ImpactFeedbackStyle constants and import style.
✗ Incorrect
The correct import is using namespace import * as Haptics, and the constant ImpactFeedbackStyle.Medium is capitalized exactly as shown.
🧠 Conceptual
expert1:00remaining
Understanding Device Info API Behavior
What will be the value of the variable 'isTablet' after running this React Native code on a phone device?
React Native
import * as Device from 'expo-device'; const isTablet = Device.isTablet;
Attempts:
2 left
💡 Hint
Check the meaning of Device.isTablet property in Expo Device API.
✗ Incorrect
Device.isTablet returns a boolean indicating if the device is a tablet. On a phone, it returns false.