0
0
React Nativemobile~20 mins

TouchableOpacity and TouchableHighlight in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Touchable Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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?
ATouchableOpacity shows a colored overlay, while TouchableHighlight dims the button's opacity.
BBoth TouchableOpacity and TouchableHighlight show a ripple effect on press.
CTouchableOpacity dims the button's opacity, while TouchableHighlight shows a colored overlay.
DNeither TouchableOpacity nor TouchableHighlight provide any visual feedback on press.
Attempts:
2 left
💡 Hint
Think about how the button looks when you tap it in each case.
lifecycle
intermediate
2:00remaining
TouchableHighlight Underlay Color Behavior
What happens if you do not set the underlayColor prop on a TouchableHighlight component?
ATouchableHighlight will use a default gray color as the underlay when pressed.
BTouchableHighlight will throw a runtime error because underlayColor is required.
CTouchableHighlight will not show any visual feedback when pressed.
DTouchableHighlight will crash the app on press.
Attempts:
2 left
💡 Hint
Try pressing a TouchableHighlight without underlayColor set.
📝 Syntax
advanced
2: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>
  );
}
ATouchableOpacity onPress={() => console.log('Pressed!')}><Text>Press Me</Text></TouchableOpacity>
BTouchableOpacity(onPress={() => console.log('Pressed!')}) {<Text>Press Me</Text>}
C>yticapOelbahcuoT/<>txeT/<eM sserP>txeT<>})'!desserP'(gol.elosnoc >= )({=sserPno yticapOelbahcuoT<
D<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.
🔧 Debug
advanced
2: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?
ATouchableHighlight must be wrapped inside a ScrollView to show feedback.
BThe child component has a transparent background, so the underlay color is not visible.
CTouchableHighlight only works on Android, not iOS.
DTouchableHighlight requires an onPress prop to show feedback, and it is missing.
Attempts:
2 left
💡 Hint
Check the background color of the child inside TouchableHighlight.
🧠 Conceptual
expert
3: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?
ATouchableOpacity, because it reduces opacity smoothly and works well with any child content.
BTouchableHighlight, because it adds a colored overlay that works better with images only.
CTouchableHighlight, because it disables opacity changes and only works with text children.
DTouchableOpacity, because it requires setting underlayColor for visual feedback.
Attempts:
2 left
💡 Hint
Think about the visual effect and compatibility with different child elements.