Component - Width, height, and flex
This React Native component shows how width, height, and flex properties control the size and layout of boxes inside a container. It helps you understand how fixed sizes and flexible space sharing work together.
This React Native component shows how width, height, and flex properties control the size and layout of boxes inside a container. It helps you understand how fixed sizes and flexible space sharing work together.
View (container) ├─ View (box1) ├─ View (box2) └─ View (box3)
flex property do in React Native layout?flexflex property controls how a component grows or shrinks to fill space in its container.width or height, flex is flexible and adapts to screen size.{ width: 100 } uses a number correctly; strings or units like 'px' are invalid.import React from 'react';
import { View } from 'react-native';
export default function App() {
return (
);
}height: 100, so it is fixed at 100 pixels tall.flex: 1 to fill remaining space, but red box height stays fixed.const styles = {
container: {
flex: '1',
width: 200
}
};flex value typeflex must be a number, not a string.width usagewidth: 200 is correct as a number; no 'px' needed.flex should be a number, not a string. -> Option AflexDirection: 'row'.width: 100, Box2 uses flex: 1 to fill remaining space.Pass the test and this pattern moves unknown