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:
      javascript Copy
      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:
      javascript Copy
      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:
      javascript Copy
      const styles = StyleSheet.create({
        container: {
          alignItems: 'center',
        },
      });

Example Usage

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

javascript Copy
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

senior

What are some limitations of using react-native-cli for instantiating a project?

senior

How would you implement animations on events?

senior

Does React Native compile JavaScript into Java for Android?

Bình luận

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

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