You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-6.x/handling-safe-area.md
+41-35Lines changed: 41 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,13 +15,15 @@ The area not overlapped by such items is referred to as "safe area".
15
15
16
16
We try to apply proper insets on the UI elements of the navigators to avoid being overlapped by such items. The goal is to (a) maximize usage of the screen (b) without hiding content or making it difficult to interact with by having it obscured by a physical display cutout or some operating system UI.
17
17
18
-
While React Navigation handles safe areas for the built-in UI elements by default, your own content also needs to handle it to ensure that content isn't hidden by these items.
18
+
While React Navigation handles safe areas for the built-in UI elements by default, your own content may also need to handle it to ensure that content isn't hidden by these items.
19
19
20
20
It's tempting to solve (a) by wrapping your entire app in a container with padding that ensures all content will not be occluded. But in doing so, we waste a bunch of space on the screen, as pictured in the image on the left below. What we ideally want is the image pictured on the right.
21
21
22
22

23
23
24
-
While React Native exports a `SafeAreaView` component, it has some inherent issues, i.e. if a screen containing safe area is animating, it causes jumpy behavior. In addition, this component only supports iOS 10+ with no support for older iOS versions or Android. We recommend to use the [react-native-safe-area-context](https://github.com/th3rdwave/react-native-safe-area-context) library to handle safe areas in a more reliable way.
24
+
While React Native exports a `SafeAreaView` component, this component only supports iOS 10+ with no support for older iOS versions or Android. In addition, it also has some issues, i.e. if a screen containing safe area is animating, it causes jumpy behavior. So we recommend to use the `useSafeAreaInsets` hook from the [react-native-safe-area-context](https://github.com/th3rdwave/react-native-safe-area-context) library to handle safe areas in a more reliable way.
25
+
26
+
> Note: The `react-native-safe-area-context` library also exports a `SafeAreaView` component. While it works on Android, it also has the same issues related to jumpy behavior when animating. So we recommend always using the `useSafeAreaInsets` hook instead and avoid using the `SafeAreaView` component.
25
27
26
28
The rest of this guide gives more information on how to support safe areas in React Navigation.
@@ -81,21 +86,36 @@ export default function App() {
81
86
82
87

83
88
84
-
To fix this issue you can apply safe area insets on your content. This can be achieved easily by using the `SafeAreaView` component from the `react-native-safe-area-context` library:
89
+
To fix this issue you can apply safe area insets on your content. This can be achieved using the `useSafeAreaInsets` hook from the `react-native-safe-area-context` library:
@@ -124,19 +144,6 @@ To fix this you can, once again, apply safe area insets to your content. This wi
124
144
125
145

126
146
127
-
## Use the `edges` prop to customize the safe area
128
-
129
-
In some cases you might need more control over which paddings are applied. For example, you can remove bottom padding by passing `edges` prop to `SafeAreaView`.
<Text style={styles.paragraph}>This is top text.</Text>
134
-
<Text style={styles.paragraph}>This is bottom text.</Text>
135
-
</SafeAreaView>
136
-
```
137
-
138
-
`edges` takes an array with the values `top`, `bottom`, `left` and `right` which controls which sides the safe area are applied to.
139
-
140
147
## Use the hook for more control
141
148
142
149
In some cases you might need more control over which paddings are applied. For example, you can only apply the top and the bottom padding by changing the `style` object:
@@ -171,7 +178,6 @@ Similarly, you could apply these paddings in `contentContainerStyle` of `FlatLis
171
178
172
179
## Summary
173
180
174
-
- Use `react-native-safe-area-context` instead of `SafeAreaView` from `react-native`
175
-
- Don't wrap your whole app in `SafeAreaView`, instead wrap content inside your screens
176
-
- Use the `edges` prop to apply safe area to specific sides
177
-
- Use the `useSafeAreaInsets` hook for more control over where the insets are applied
181
+
- Use `useSafeAreaInsets` hook from `react-native-safe-area-context` instead of `SafeAreaView` component
182
+
- Don't wrap your whole app in `SafeAreaView`, instead apply the styles to content inside your screens
183
+
- Apply only specific insets using the `useSafeAreaInsets` hook for more control
0 commit comments