Challenge - 5 Problems
Touchable Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Difference in Visual Feedback Between TouchableOpacity and TouchableHighlight
When you press a button wrapped in TouchableOpacity versus one wrapped in TouchableHighlight, what visual effect do you see?
Attempts:
2 left
💡 Hint
Think about how the button looks when you tap it in each case.
✗ Incorrect
TouchableOpacity reduces the opacity of its child component to show feedback, making it look faded. TouchableHighlight adds a colored overlay (highlight) on top of the child component.
❓ lifecycle
intermediate2:00remaining
TouchableHighlight Underlay Color Behavior
What happens if you do not set the
underlayColor prop on a TouchableHighlight component?Attempts:
2 left
💡 Hint
Try pressing a TouchableHighlight without underlayColor set.
✗ Incorrect
If underlayColor is not specified, TouchableHighlight uses a default gray color for the underlay to show feedback.
📝 Syntax
advanced2:00remaining
Correct Usage of TouchableOpacity with onPress
Which code snippet correctly implements a TouchableOpacity button that logs 'Pressed!' when tapped?
React Native
import React from 'react'; import { TouchableOpacity, Text } from 'react-native'; export default function MyButton() { return ( <TouchableOpacity onPress={() => console.log('Pressed!')}> <Text>Press Me</Text> </TouchableOpacity> ); }
Attempts:
2 left
💡 Hint
Remember JSX syntax requires tags to be enclosed in angle brackets.
✗ Incorrect
Option D correctly uses JSX syntax with angle brackets and proper nesting. Options A and B are missing angle brackets or use invalid syntax. Option D is identical to C.
🔧 Debug
advanced2:00remaining
Why Does TouchableHighlight Not Show Feedback?
You wrapped a button in TouchableHighlight but pressing it does not show any visual feedback. What is the most likely cause?
Attempts:
2 left
💡 Hint
Check the background color of the child inside TouchableHighlight.
✗ Incorrect
If the child component has a transparent background, the underlay color will not be visible, so no feedback appears. Adding a background color to the child fixes this.
🧠 Conceptual
expert3:00remaining
Choosing Between TouchableOpacity and TouchableHighlight
You want a button that shows a subtle fade effect on press and works well with images and text. Which component is best to use and why?
Attempts:
2 left
💡 Hint
Think about the visual effect and compatibility with different child elements.
✗ Incorrect
TouchableOpacity reduces the opacity of its children, creating a subtle fade effect that works well with images and text. TouchableHighlight adds a colored overlay which may not always look good with images.