React Native SafeAreaView Examples

Example 1: render Text component in React Native SafeAreaView

In this example, we will render a Text component in SafeAreaView component. And because we are using SafeAreaView component, it will avoid the rounded corners and notch of the physical device and renders the content perfectly on the screen.

Javascript




// Filename - App.js
 
import { StyleSheet, SafeAreaView, Text } from "react-native";
 
export default function App() {
    return (
        <SafeAreaView style={styles.container}>
            <Text style={styles.title}>w3wiki</Text>
        </SafeAreaView>
      );
}
 
const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: "#3B5323",
      },
      title: {
        fontSize: 30,
        fontWeight: "bold",
        textAlign: "center",
        color: "#fff",
      },
});


Output:

Example 2: Button component in React Native SafeAreaView

In this example, we will render a Button component in SafeAreaView component. And because we are using SafeAreaView component, it will avoid the rounded corners and notch of the physical device and renders the content perfectly on the screen.

Javascript




// Filename - App.js
 
import { StyleSheet, SafeAreaView, Button } from "react-native";
 
export default function App() {
    return (
        <SafeAreaView style={styles.container}>
            <Button
                title="Press Me"
                color="#fff"
                onPress={() => {
                      alert("Welcome to w3wiki");
                }}
              />
        </SafeAreaView>
      );
}
 
const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: "#3B5323",
      },
});


Output:

Reference: https://reactnative.dev/docs/safeareaview



React Native SafeAreaView

React Native SafeAreaView renders content within the safe area boundaries of a device. The safe area refers to the display excluding the top status bar and front camera notch.

Similar Reads

Syntax:

{/*Content to render inside SafeAreaComponent*/}...

Need of React Native SafeAreaView

If you use the normal View component in React Native, you have to take care of this situation by yourself and make sure all the UI components render within the safe boundaries of a device. But the SafeAreaView component takes away that headache from you and makes sure everything works fine on a device. Every component you write in SafeAreaView will render within the safe area boundaries of a device....

Difference Between SafeAreaView and NormalAreaView Components

Below you can see the difference between a View component and a SafeAreaView component....

React Native SafeAreaView Examples

Example 1: render Text component in React Native SafeAreaView...