React Native Styling & Layout
Flexbox, absolute positioning, responsive design, safe area, platform-specific styles
1What is the default flexDirection in React Native?
What is the default flexDirection in React Native?
回答
In React Native, flexDirection defaults to 'column', unlike on the web where it defaults to 'row'. This means child elements are arranged vertically from top to bottom by default. This difference reflects typical mobile interface conventions, where vertical layouts are more common.
2How to create a reusable style in React Native?
How to create a reusable style in React Native?
回答
StyleSheet.create() is the recommended method for creating styles in React Native. It allows defining a style object that can be reused across multiple components. This approach optimizes performance by validating styles once at startup and referencing them by ID rather than recreating objects on each render.
3Which property to use to center an element both horizontally AND vertically within its container?
Which property to use to center an element both horizontally AND vertically within its container?
回答
To center an element in both axes, combine justifyContent: 'center' (main axis) and alignItems: 'center' (cross axis). With the default flexDirection ('column'), justifyContent centers vertically and alignItems centers horizontally. These two properties work together to achieve perfect centering.
What is the default unit of measurement used in React Native for dimensions?
Which property allows positioning an element absolutely relative to its parent?
+15 面接問題