Câu hỏi phỏng vấn React Native
Câu hỏi

Explain the use of Flexbox in React Native?

Câu trả lời

Flexbox is a powerful layout system in React Native that allows developers to create responsive and flexible user interfaces. It is particularly useful for accommodating different screen sizes and orientations, making it an essential tool for mobile app development. Here’s a detailed explanation of the use of Flexbox in React Native:

Key Properties of Flexbox

  1. flexDirection:

    • Description: Determines the primary axis of the layout, which can be either horizontal or vertical.
    • Values:
      • row: Aligns children from left to right.
      • column (default): Aligns children from top to bottom.
      • row-reverse: Aligns children from right to left.
      • column-reverse: Aligns children from bottom to top.
    • Example:
      const styles = StyleSheet.create({
        container: {
          flexDirection: 'row',
        },
      });
  2. justifyContent:

    • Description: Aligns children along the main axis (primary axis).
    • Values:
      • flex-start (default): Aligns children to the start of the main axis.
      • flex-end: Aligns children to the end of the main axis.
      • center: Centers children along the main axis.
      • space-between: Distributes children evenly with the first child at the start and the last child at the end.
      • space-around: Distributes children evenly with equal space around them.
      • space-evenly: Distributes children evenly with equal space between them.
    • Example:
      const styles = StyleSheet.create({
        container: {
          justifyContent: 'center',
        },
      });
  3. alignItems:

    • Description: Aligns children along the cross axis (secondary axis).
    • Values:
      • flex-start: Aligns children to the start of the cross axis.
      • flex-end: Aligns children to the end of the cross axis.
      • center: Centers children along the cross axis.
      • stretch (default): Stretches children to fill the container along the cross axis.
    • Example:
      const styles = StyleSheet.create({
        container: {
          alignItems: 'center',
        },
      });

Example Usage

Here is a simple example demonstrating the use of Flexbox in a React Native component:

import React from 'react';
import { StyleSheet, View, Text } from 'react-native';

const FlexboxExam...
middle

middle

Gợi ý câu hỏi phỏng vấn

expert

How is InteractionManager important?

middle

What does TouchableHighlight do and when do you use it?

junior

When would you use ScrollView over FlatList or vice-versa?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào