Curriculum
Course: Basic Components in React Native
Login

Curriculum

Basic Components in React Native

Text lesson

Lesson 2: View Component

Introduction: The View component is the most fundamental component for building layouts in React Native.

 

Using the View Component:

  • The View component acts as a container for other components.
  • It supports layout with flexbox and styling.

 

Example Code:

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

const App = () => {
return (
<View style={styles.container}>
<View style={styles.box}>
<Text>Box 1</Text>
</View>
<View style={styles.box}>
<Text>Box 2</Text>
</View>
</View>

);
};

const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'space-around',
alignItems: 'center',
},
box: {
width: 100,
height: 100,
backgroundColor: 'lightblue',
justifyContent: 'center',
alignItems: 'center',
},
});

export default App;

 

Conclusion: The View component is crucial for creating structured and responsive layouts. Understanding how to use View effectively will allow you to build complex UI structures.

Layer 1
Login Categories
This website uses cookies and asks your personal data to enhance your browsing experience.