0
0
React Nativemobile~20 mins

Margin, padding, border in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Margin, Padding & Border Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
Understanding margin effect on layout
Given the following React Native code, what will be the space between the blue box and the red box?
React Native
import React from 'react';
import { View } from 'react-native';

export default function App() {
  return (
    <View style={{ flexDirection: 'row' }}>
      <View style={{ width: 50, height: 50, backgroundColor: 'blue', marginRight: 20 }} />
      <View style={{ width: 50, height: 50, backgroundColor: 'red' }} />
    </View>
  );
}
AThere will be a 20-pixel space between the blue and red boxes.
BThere will be a 20-pixel space inside the blue box around its content.
CThe boxes will touch each other with no space.
DThe red box will have a 20-pixel space around it.
Attempts:
2 left
💡 Hint
Margin adds space outside the component's border.
ui_behavior
intermediate
2:00remaining
Padding effect inside a component
What will be the visible effect of the padding in this React Native component?
React Native
import React from 'react';
import { View, Text } from 'react-native';

export default function App() {
  return (
    <View style={{ backgroundColor: 'yellow', padding: 15 }}>
      <Text>Text inside padded box</Text>
    </View>
  );
}
AThe yellow box will shrink by 15 pixels on each side.
BThe yellow box will have 15 pixels of space outside its border.
CThe text will be 15 pixels larger in font size.
DThe text will have 15 pixels of space inside the yellow box around it.
Attempts:
2 left
💡 Hint
Padding adds space inside the component's border.
ui_behavior
advanced
2:00remaining
Border width and color effect
What will be the visible border around the green box in this React Native code?
React Native
import React from 'react';
import { View } from 'react-native';

export default function App() {
  return (
    <View style={{ width: 100, height: 100, backgroundColor: 'green', borderWidth: 5, borderColor: 'black' }} />
  );
}
ANo border will appear because borderColor is ignored without borderStyle.
BA black border 5 pixels thick will appear around the green box.
CA green border 5 pixels thick will appear around the box.
DA black border 1 pixel thick will appear around the green box.
Attempts:
2 left
💡 Hint
Border width and color define the visible border thickness and color.
lifecycle
advanced
2:00remaining
Effect of margin and padding on touchable area
In React Native, if a TouchableOpacity has margin and padding, which area responds to touch?
React Native
import React from 'react';
import { TouchableOpacity, Text } from 'react-native';

export default function App() {
  return (
    <TouchableOpacity style={{ margin: 20, padding: 10, backgroundColor: 'lightblue' }}>
      <Text>Press me</Text>
    </TouchableOpacity>
  );
}
ANeither margin nor padding areas respond to touch.
BBoth margin and padding areas respond to touch.
COnly the area inside the padding responds to touch; margin area does not.
DOnly the margin area responds to touch; padding area does not.
Attempts:
2 left
💡 Hint
Margin is outside the component's touchable area; padding is inside.
🔧 Debug
expert
2:00remaining
Why is the border not visible?
A developer wrote this code but the border does not show. What is the reason?
React Native
import React from 'react';
import { View } from 'react-native';

export default function App() {
  return (
    <View style={{ width: 100, height: 100, backgroundColor: 'white', borderColor: 'red' }} />
  );
}
AThe borderWidth is missing, so the border is not drawn.
BThe borderColor 'red' is invalid and ignored.
CThe backgroundColor 'white' hides the border.
DThe View needs a borderStyle set to 'solid' to show the border.
Attempts:
2 left
💡 Hint
Border color alone does not create a visible border without width.