Explore fundamental concepts of flexbox layout and responsive design in React Native with this quiz. Improve your understanding of key styling properties and learn how to create flexible, adaptive user interfaces for mobile applications.
Which flexbox property in React Native controls whether children are laid out horizontally or vertically within a container?
Explanation: The flexDirection property specifies the primary axis along which children are placed, such as 'row' for horizontal or 'column' for vertical. flexWrap controls whether children can wrap onto multiple lines but doesn't determine the main axis. alignContent is used for space distribution between lines. itemDirection is not a valid flexbox property, making flexDirection the correct answer.
If you want to align items in the center of a container both vertically and horizontally in React Native flexbox, which two properties should you use?
Explanation: alignItems aligns children along the cross axis, while justifyContent aligns them along the main axis, allowing for center alignment in both directions. alignSelf applies to individual items only and marginAuto is not a React Native property. centerItems, justify, contentAlign, and flexCenter are not valid React Native flexbox properties.
In React Native, what happens if you assign flex: 2 to one child and flex: 1 to another within the same container?
Explanation: Setting flex: 2 to one child and flex: 1 to another means the available space is divided into three parts, with the first child getting two and the second one. Both children getting equal space would require identical flex values. The statement that the second child takes more space is incorrect here, and the space values do not affect display unless constrained.
Which flexbox property enables wrapping of children onto multiple lines inside a container in React Native?
Explanation: The flexWrap property lets child elements move onto the next line if necessary. wrapItems, lineWrap, and itemsWrap are not valid React Native flexbox properties. Only flexWrap enables this specific behavior in the layout.
How can you ensure a component has a width that always fills half of the device’s screen in React Native?
Explanation: width: '50%' means the component's width will always be half of its parent, which is usually the device screen if the parent is the root. width: 50 sets a constant value of 50 units, not relative. maxWidth: '50%' only restricts the maximum width when the actual width is larger. flexGrow is unrelated to directly setting width as a screen percentage.
What is the default value of flexDirection in a React Native flexbox container?
Explanation: By default, React Native lays out items in a column vertically, so the flexDirection is 'column'. 'row' is commonly used for horizontal layouts but is not the default. 'horizontal' and 'vertical' are not accepted values for flexDirection in React Native.
If you set justifyContent to 'space-between' in React Native, how are child components arranged in the container?
Explanation: justifyContent: 'space-between' places the first child at the start and the last at the end, with equal space among the rest. Centered alignment would require 'center'. Aligning along the cross axis involves alignItems instead. Right alignment is achieved with 'flex-end', not 'space-between'.
Which technique helps make font sizes or margins responsive to different screen sizes in React Native?
Explanation: Calculating values based on device dimensions allows font sizes or margins to adjust according to screen size. React Native does not use px or rem units as web environments do. Hardcoding values, even with flex, does not provide true responsiveness.
Which property should you use to override the cross-axis alignment of an individual child in a flex container?
Explanation: alignSelf lets a specific child have its own alignment, separate from the alignItems value set on the container. alignCenter, selfAlign, and alignChildren are not recognized as valid flexbox or layout properties in React Native.
What value for justifyContent makes all child components in a row have equal space to their left and right, except for the most outer components?
Explanation: 'space-around' places equal space on both sides of each item, but edge items only have half the space next to the container border compared to the space between items. 'space-between' places no space at the edges, only between. 'space-evenly' distributes all spaces equally including edges. 'center' would simply center the row items.