React Native – View
View – View
is a container component used for layout and styling. It can contain other components like Text
, Image
, and even other View
components. It is the most commonly used component for building UI.
Use Cases:
- Handling touch events.
- Wrapping other components to apply styles.
- Creating layouts using flexbox.
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
const App = () => {
return (
<View style={styles.container}>
<View style={styles.box}>
<Text>Hello, View!</Text>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
box: {
width: 100,
height: 100,
backgroundColor: 'skyblue',
justifyContent: 'center',
alignItems: 'center',
},
});
export default App;