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: README.md
-292Lines changed: 0 additions & 292 deletions
Original file line number
Diff line number
Diff line change
@@ -36,298 +36,6 @@ You then need to link the native parts of the library for the platforms you are
36
36
37
37
This library currently has experimental support for the new react-native architecture. Note that there will be breaking changes and only the latest version of react-native will be supported.
38
38
39
-
## Usage
40
-
41
-
This library has 2 important concepts, if you are familiar with React Context this is very similar.
42
-
43
-
### Providers
44
-
45
-
The [SafeAreaProvider](#safeareaprovider) component is a `View` from where insets provided by [Consumers](#consumers) are relative to. This means that if this view overlaps with any system elements (status bar, notches, etc.) these values will be provided to descendent consumers. Usually you will have one provider at the top of your app.
46
-
47
-
### Consumers
48
-
49
-
Consumers are components and hooks that allow using inset values provided by the nearest parent [Provider](#providers). Values are always relative to a provider and not to these components.
50
-
51
-
-[SafeAreaView](#safeareaview) is the preferred way to consume insets. This is a regular `View` with insets applied as extra padding or margin. It offers better performance by applying insets natively and avoids flickers that can happen with the other JS based consumers.
52
-
53
-
-[useSafeAreaInsets](#usesafeareainsets) offers more flexibility, but can cause some layout flicker in certain cases. Use this if you need more control over how insets are applied.
54
-
55
-
## API
56
-
57
-
### SafeAreaProvider
58
-
59
-
You should add `SafeAreaProvider` in your app root component. You may need to add it in other places like the root of modals and routes when using [`react-native-screens`](https://github.com/software-mansion/react-native-screens).
60
-
61
-
Note that providers should not be inside a `View` that is animated with `Animated` or inside a `ScrollView` since it can cause very frequent updates.
Accepts all [View](https://reactnative.dev/docs/view#props) props. Has a default style of `{flex: 1}`.
76
-
77
-
##### `initialMetrics`
78
-
79
-
Optional, defaults to `null`.
80
-
81
-
Can be used to provide the initial value for frame and insets, this allows rendering immediatly. See [optimization](#optimization) for more information on how to use this prop.
82
-
83
-
### SafeAreaView
84
-
85
-
`SafeAreaView` is a regular `View` component with the safe area insets applied as padding or margin.
86
-
87
-
Padding or margin styles are added to the insets, for example `style={{paddingTop: 10}}` on a `SafeAreaView` that has insets of 20 will result in a top padding of 30.
Optionally it can be set to an object `{ top?: EdgeMode, right?: EdgeMode, bottom?: EdgeMode, left?: EdgeMode }` where `EdgeMode = 'off' | 'additive' | 'maximum'`. Additive is a default mode and is the same as passing and edge in the array: `finalPadding = safeArea + padding`. Maximum mode will use safe area inset or padding/margin (depends on `mode`) if safe area is less: `finalPadding = max(safeArea, padding)`. For example if you want a floating UI element that should be at the bottom safe area edge on devices with safe area or 24px from the bottom of the screen on devices without safe area or if safe area is less than 24px:
Returns the safe area insets of the nearest provider. This allows manipulating the inset values from JavaScript. Note that insets are not updated synchronously so it might cause a slight delay for example when rotating the screen.
140
-
141
-
Object with `{ top: number, right: number, bottom: number, left: number }`.
React Context with the value of the safe area frame.
202
-
203
-
### `initialWindowMetrics`
204
-
205
-
Insets and frame of the window on initial render. This can be used with the `initialMetrics` from `SafeAreaProvider`. See [optimization](#optimization) for more information.
**NOTE:** This value can be null or out of date as it is computed when the native module is created.
217
-
218
-
## Deprecated apis
219
-
220
-
### useSafeArea
221
-
222
-
Use `useSafeAreaInsets` instead.
223
-
224
-
### SafeAreaConsumer
225
-
226
-
Use `SafeAreaInsetsContext.Consumer` instead.
227
-
228
-
### SafeAreaContext
229
-
230
-
Use `SafeAreaInsetsContext` instead.
231
-
232
-
### initialWindowSafeAreaInsets
233
-
234
-
Use `initialWindowMetrics` instead.
235
-
236
-
## Web SSR
237
-
238
-
If you are doing server side rendering on the web you can use `initialMetrics` to inject insets and frame value based on the device the user has, or simply pass zero values. Since insets measurement is async it will break rendering your page content otherwise.
239
-
240
-
## Optimization
241
-
242
-
If you can, use `SafeAreaView`. It's implemented natively so when rotating the device, there is no delay from the asynchronous bridge.
243
-
244
-
To speed up the initial render, you can import `initialWindowMetrics` from this package and set as the `initialMetrics` prop on the provider as described in Web SSR. You cannot do this if your provider remounts, or you are using `react-native-navigation`.
To have more control over the test values it is also possible to pass `initialMetrics` to
291
-
`SafeAreaProvider` to provide mock data for frame and insets.
292
-
293
-
```js
294
-
exportfunctionTestSafeAreaProvider({ children }) {
295
-
return (
296
-
<SafeAreaProvider
297
-
initialMetrics={{
298
-
frame: { x:0, y:0, width:0, height:0 },
299
-
insets: { top:0, left:0, right:0, bottom:0 },
300
-
}}
301
-
>
302
-
{children}
303
-
</SafeAreaProvider>
304
-
);
305
-
}
306
-
```
307
-
308
-
#### Enabling Babel Parsing for Modules
309
-
310
-
While trying to use this mock, a frequently encountered error is:
311
-
312
-
```js
313
-
SyntaxError: Cannot use import statement outside a module.
314
-
```
315
-
316
-
This issue arises due to the use of the import statement. To resolve it, you need to permit Babel to parse the file.
317
-
318
-
By default, [Jest does not parse files located within the node_modules folder](<(https://jestjs.io/docs/configuration#transformignorepatterns-arraystring)>).
319
-
320
-
However, you can modify this behavior as outlined in the Jest documentation on [`transformIgnorePatterns` customization](https://jestjs.io/docs/tutorial-react-native#transformignorepatterns-customization).
321
-
If you're using a preset, like the one from [react-native](https://github.com/facebook/react-native/blob/main/packages/react-native/jest-preset.js), you should update your Jest configuration to include `react-native-safe-area-context` as shown below:
0 commit comments