Challenge - 5 Problems
View Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What is the output of this React Native View component?
Consider this React Native code snippet. What will be displayed on the screen?
React Native
import React from 'react'; import { View, Text } from 'react-native'; export default function App() { return ( <View style={{ backgroundColor: 'blue', padding: 20 }}> <Text style={{ color: 'white' }}>Hello World</Text> </View> ); }
Attempts:
2 left
💡 Hint
Look at the View's backgroundColor and Text's color styles.
✗ Incorrect
The View has a blue background and padding. The Text inside has white color, so the text appears white on blue background.
❓ lifecycle
intermediate2:00remaining
What happens if you nest multiple Views with different styles?
Given nested Views with different background colors and padding, what will be the visible padding around the innermost Text?
React Native
import React from 'react'; import { View, Text } from 'react-native'; export default function App() { return ( <View style={{ backgroundColor: 'red', padding: 10 }}> <View style={{ backgroundColor: 'green', padding: 20 }}> <Text>Nested Text</Text> </View> </View> ); }
Attempts:
2 left
💡 Hint
Padding applies to each View separately and stacks visually.
✗ Incorrect
The outer View has 10 units padding and red background. Inside it, the inner View has 20 units padding and green background. The Text is inside the inner View, so it has 20 units padding from the green View. The red View's padding surrounds the green View.
📝 Syntax
advanced2:00remaining
What error occurs with this View usage?
What error will this React Native code produce?
React Native
import React from 'react'; import { View, Text } from 'react-native'; export default function App() { return ( <View style={{ backgroundColor: 'yellow' }}> <Text>Hello</Text> <Text>World</Text> </View> ); }
Attempts:
2 left
💡 Hint
Check the type expected for the style prop in React Native.
✗ Incorrect
The style prop must be an object or array of objects, not a string. Passing a string causes a runtime error.
advanced
2:00remaining
How does View affect touch event handling in React Native?
If you wrap a Button inside a View with style {pointerEvents: 'none'}, what happens when you tap the Button?
React Native
import React from 'react'; import { View, Button, Alert } from 'react-native'; export default function App() { return ( <View style={{ pointerEvents: 'none' }}> <Button title="Press me" onPress={() => Alert.alert('Pressed!')} /> </View> ); }
Attempts:
2 left
💡 Hint
pointerEvents controls whether touches pass through the View and its children.
✗ Incorrect
Setting pointerEvents to 'none' disables touch events on the View and all its children, so the Button inside cannot be tapped.
🧠 Conceptual
expert2:00remaining
What is the effect of using flex: 1 on a View inside a parent with fixed height?
Given a parent View with fixed height 200 and a child View with style {flex: 1}, what height will the child View have?
React Native
import React from 'react'; import { View } from 'react-native'; export default function App() { return ( <View style={{ height: 200, backgroundColor: 'gray' }}> <View style={{ flex: 1, backgroundColor: 'blue' }} /> </View> ); }
Attempts:
2 left
💡 Hint
flex: 1 means fill available space inside the parent container.
✗ Incorrect
The parent View has fixed height 200. The child View with flex: 1 fills all available space inside the parent, so it gets height 200.