0
0
React Nativemobile~20 mins

View component in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
View Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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>
  );
}
AA blue background with white text saying 'Hello World'.
BA blue background with black text saying 'Hello World'.
CA white background with blue text saying 'Hello World'.
DA white background with black text saying 'Hello World'.
Attempts:
2 left
💡 Hint
Look at the View's backgroundColor and Text's color styles.
lifecycle
intermediate
2: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>
  );
}
AThe Text has no padding because padding does not apply to nested Views.
BThe Text has 10 units of padding inside a red background only.
CThe Text has 30 units of padding combining both Views.
DThe Text has 20 units of padding inside a green background, which is inside a red background with 10 units padding.
Attempts:
2 left
💡 Hint
Padding applies to each View separately and stacks visually.
📝 Syntax
advanced
2: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>
  );
}
AWarning but no error; style string is ignored.
BRuntime error because style prop is a string instead of an object.
CRuntime error because Text components cannot be siblings inside View.
DNo error, the style string is accepted and applied.
Attempts:
2 left
💡 Hint
Check the type expected for the style prop in React Native.
navigation
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>
  );
}
AThe Button does not respond to taps because pointerEvents disables touch on the View and its children.
BThe Button responds but with a delay due to pointerEvents.
CThe Button responds normally to taps despite pointerEvents on the View.
DThe app crashes because pointerEvents is not a valid style.
Attempts:
2 left
💡 Hint
pointerEvents controls whether touches pass through the View and its children.
🧠 Conceptual
expert
2: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>
  );
}
AThe child View will have height 100, half of the parent height.
BThe child View will have zero height because flex does not apply inside fixed height parent.
CThe child View will fill the entire 200 height of the parent View.
DThe child View will overflow the parent and have height greater than 200.
Attempts:
2 left
💡 Hint
flex: 1 means fill available space inside the parent container.