Complete the code to make the button respond to touches using TouchableOpacity.
import React from 'react'; import { Text, View, [1] } from 'react-native'; export default function App() { return ( <View> <[1] onPress={() => alert('Pressed!')}> <Text>Press Me</Text> </[1]> </View> ); }
TouchableOpacity is used to make components respond to touches with an opacity effect.
Complete the code to use TouchableHighlight with a custom underlay color.
import React from 'react'; import { Text, View, TouchableHighlight } from 'react-native'; export default function App() { return ( <View> <TouchableHighlight underlayColor=[1] onPress={() => alert('Pressed!')}> <Text>Press Here</Text> </TouchableHighlight> </View> ); }
The underlayColor prop sets the color shown when the button is pressed. '#DDDDDD' is a light gray color.
Fix the error in the code by choosing the correct prop to handle press events on TouchableOpacity.
import React from 'react'; import { Text, View, TouchableOpacity } from 'react-native'; export default function App() { return ( <View> <TouchableOpacity [1]={() => alert('Clicked!')}> <Text>Click Me</Text> </TouchableOpacity> </View> ); }
TouchableOpacity uses the onPress prop to handle touch events, not onClick or others.
Fill both blanks to create a TouchableHighlight that changes underlay color and shows a message on press.
import React from 'react'; import { Text, View, [1] } from 'react-native'; export default function App() { return ( <View> <[1] underlayColor=[2] onPress={() => alert('Hello!')}> <Text>Tap Me</Text> </[1]> </View> ); }
TouchableHighlight is imported and used with underlayColor set to a gray shade '#AAAAAA'.
Fill all three blanks to create a TouchableOpacity with an active opacity and a press handler.
import React from 'react'; import { Text, View, TouchableOpacity } from 'react-native'; export default function App() { return ( <View> <TouchableOpacity activeOpacity=[1] onPress=[2]> <Text>[3]</Text> </TouchableOpacity> </View> ); }
activeOpacity controls the opacity when pressed (0.5 means half transparent). onPress is a function that shows an alert. The Text shows 'Press Me'.