What does the flex property do in React Native layout?
The flex property tells a component how much space it should take relative to its siblings inside a container. A higher flex value means the component grows more to fill available space.
Click to reveal answer
beginner
How do you set a fixed width and height for a component in React Native?
You set fixed width and height by adding width and height properties in the style, for example: { width: 100, height: 50 } sets the component to 100 units wide and 50 units tall.
Click to reveal answer
beginner
What happens if you set flex: 1 on a component inside a container?
The component will expand to fill all available space in the container, sharing space equally if siblings also have flex: 1.
Click to reveal answer
intermediate
Can you use both fixed width/height and flex on the same component? What happens?
Yes, but fixed width and height take priority. The flex property will only affect the component if width or height is not fixed or set to auto.
Click to reveal answer
beginner
Why is using flex often better than fixed sizes for mobile layouts?
Because mobile screens vary in size, using flex helps components adjust and fill space proportionally, making the app look good on different devices without hardcoded sizes.
Click to reveal answer
In React Native, what does flex: 2 mean compared to flex: 1 on sibling components?
AThe component with <code>flex: 2</code> takes half the space of the one with <code>flex: 1</code>.
BBoth components take equal space regardless of flex values.
CThe component with <code>flex: 2</code> takes twice as much space as the one with <code>flex: 1</code>.
D<code>flex</code> only affects height, not width.
✗ Incorrect
flex defines proportional space. flex: 2 means twice the space compared to flex: 1.
If you want a component to be exactly 150 units wide and 100 units tall, which style should you use?
A{ width: 150, height: 100 }
B{ flexGrow: 150, flexShrink: 100 }
C{ flex: 1 }
D{ flexBasis: 150 }
✗ Incorrect
Setting width and height directly fixes the size.
What is the default value of flex in React Native if not specified?
Aundefined
B1
Cauto
D0
✗ Incorrect
The default flex is 0, meaning the component does not grow to fill space.
Which property controls how a component grows to fill available space in React Native?
Aheight
Bflex
Cwidth
Dmargin
✗ Incorrect
flex controls growth inside a flex container.
If a container has two children with styles { flex: 1 } and { flex: 3 }, how is space divided?
AFirst child gets 1/4, second child gets 3/4 of space
BEqual space for both
CFirst child gets 3/4, second child gets 1/4 of space
DSpace division depends on width property
✗ Incorrect
Space is divided in ratio 1:3, so first child gets 1/4 and second child 3/4.
Explain how flex, width, and height work together to control layout in React Native.
Think about how space is shared inside a container.
You got /4 concepts.
Describe why using flex is important for mobile app layouts compared to fixed sizes.
Imagine your app on small and large phones.
You got /4 concepts.
Practice
(1/5)
1. What does the flex property do in React Native layout?
easy
A. It changes the font size of text.
B. It sets a fixed width in pixels.
C. It makes the component grow or shrink to fill available space.
D. It sets a fixed height in pixels.
Solution
Step 1: Understand the role of flex
The flex property controls how a component grows or shrinks to fill space in its container.
Step 2: Compare with fixed sizes
Unlike fixed width or height, flex is flexible and adapts to screen size.
Final Answer:
It makes the component grow or shrink to fill available space. -> Option C
Quick Check:
Flex = flexible size [OK]
Hint: Flex means flexible size, not fixed pixels [OK]
Common Mistakes:
Confusing flex with fixed width or height
Thinking flex changes font size
Assuming flex sets exact pixel size
2. Which of the following is the correct way to set a fixed width of 100 pixels in React Native style?
easy
A. { width: 100 }
B. { width: '100' }
C. { width: '100px' }
D. { flex: 100 }
Solution
Step 1: Check value type for width
In React Native, fixed sizes are numbers without quotes, representing pixels.
Step 2: Identify correct syntax
Only { width: 100 } uses a number correctly; strings or units like 'px' are invalid.
Final Answer:
{ width: 100 } -> Option A
Quick Check:
Fixed size = number without quotes [OK]
Hint: Use numbers, not strings, for fixed sizes [OK]
Common Mistakes:
Using strings instead of numbers for width
Adding 'px' units which React Native does not use
Confusing flex with fixed width
3. What will be the height of the red box in this code?
import React from 'react';
import { View } from 'react-native';
export default function App() {
return (
);
}
medium
A. The red box will have height equal to flex 1.
B. The red box will fill all available space.
C. The red box will have height 0.
D. The red box will have height 100 pixels.
Solution
Step 1: Analyze red box style
The red box has height: 100, so it is fixed at 100 pixels tall.
Step 2: Understand flex on sibling
The blue box uses flex: 1 to fill remaining space, but red box height stays fixed.
Final Answer:
The red box will have height 100 pixels. -> Option D
Quick Check:
Fixed height overrides flex for that box [OK]
Hint: Fixed height overrides flex size [OK]
Common Mistakes:
Assuming flex affects fixed height components
Thinking red box fills all space
Confusing flex values with pixel sizes
4. Find the error in this React Native style code:
In React Native, flex must be a number, not a string.
Step 2: Validate width usage
width: 200 is correct as a number; no 'px' needed.
Final Answer:
flex should be a number, not a string. -> Option A
Quick Check:
flex = number, not string [OK]
Hint: flex and width values must be numbers, not strings [OK]
Common Mistakes:
Using strings for flex or width
Adding 'px' units to width
Thinking flex and width cannot coexist
5. You want a container with two boxes: the first box fixed width 100 pixels, the second box fills the rest of the screen width. Which style setup achieves this?