Build: Simple View Screen
This screen shows how to use the View component to create a colored box with some text inside.
Target UI
--------------------- | | | [ Blue Box ] | | Hello inside | | | ---------------------
--------------------- | | | [ Blue Box ] | | Hello inside | | | ---------------------
import React from 'react'; import { View, Text, StyleSheet } from 'react-native'; export default function SimpleViewScreen() { return ( <View style={styles.container}> {/* TODO: Add your View and Text components here */} </View> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', }, });
import React from 'react'; import { View, Text, StyleSheet } from 'react-native'; export default function SimpleViewScreen() { return ( <View style={styles.container}> <View style={styles.blueBox}> <Text style={styles.text}>Hello inside</Text> </View> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', }, blueBox: { backgroundColor: 'blue', width: 200, height: 100, margin: 20, justifyContent: 'center', alignItems: 'center', }, text: { color: 'white', fontSize: 16, }, });
We created a blue box using a View component styled with a blue background, fixed width and height, and margin for spacing. Inside this View, we placed a Text component with white color to contrast the blue background. We used justifyContent and alignItems to center the text horizontally and vertically inside the box. The outer container View centers the blue box on the screen.
--------------------- | | | [ Blue Box ] | | Hello inside | | | ---------------------
View component in React Native?View with a red background in React Native?import React from 'react';
import { View, Text } from 'react-native';
export default function App() {
return (
One
Two
Three
);
}return (
First
Second
Third
Outside
);Pass the test and this pattern moves unknown