|
@@ -1 +1,97 @@
|
1
|
1
|
# react-native-safe-area-context
|
|
2
|
+
|
|
3
|
+A flexible way to handle safe area, also works on Android!
|
|
4
|
+
|
|
5
|
+## Getting started
|
|
6
|
+
|
|
7
|
+Install the library using either Yarn:
|
|
8
|
+
|
|
9
|
+```
|
|
10
|
+yarn add react-native-safe-area-context
|
|
11
|
+```
|
|
12
|
+
|
|
13
|
+or npm:
|
|
14
|
+
|
|
15
|
+```
|
|
16
|
+npm install --save react-native-safe-area-context
|
|
17
|
+```
|
|
18
|
+
|
|
19
|
+You then need to link the native parts of the library for the platforms you are using. The easiest way to link the library is using the CLI tool by running this command from the root of your project:
|
|
20
|
+
|
|
21
|
+```
|
|
22
|
+react-native link react-native-safe-area-context
|
|
23
|
+```
|
|
24
|
+
|
|
25
|
+If you can't or don't want to use the CLI tool, you can also manually link the library using the instructions below (click on the arrow to show them):
|
|
26
|
+
|
|
27
|
+<details>
|
|
28
|
+<summary>Manually link the library on iOS</summary>
|
|
29
|
+
|
|
30
|
+Either follow the [instructions in the React Native documentation](https://facebook.github.io/react-native/docs/linking-libraries-ios#manual-linking) to manually link the framework or link using [Cocoapods](https://cocoapods.org) by adding this to your `Podfile`:
|
|
31
|
+
|
|
32
|
+```ruby
|
|
33
|
+pod 'react-native-safe-area-context', :path => '../node_modules/react-native-safe-area-context'
|
|
34
|
+```
|
|
35
|
+
|
|
36
|
+</details>
|
|
37
|
+
|
|
38
|
+<details>
|
|
39
|
+<summary>Manually link the library on Android</summary>
|
|
40
|
+
|
|
41
|
+Make the following changes:
|
|
42
|
+
|
|
43
|
+#### `android/settings.gradle`
|
|
44
|
+```groovy
|
|
45
|
+include ':react-native-safe-area-context'
|
|
46
|
+project(':react-native-safe-area-context').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-safe-area-context/android')
|
|
47
|
+```
|
|
48
|
+
|
|
49
|
+#### `android/app/build.gradle`
|
|
50
|
+```groovy
|
|
51
|
+dependencies {
|
|
52
|
+ ...
|
|
53
|
+ implementation project(':react-native-safe-area-context')
|
|
54
|
+}
|
|
55
|
+```
|
|
56
|
+
|
|
57
|
+#### `android/app/src/main/.../MainApplication.java`
|
|
58
|
+On top, where imports are:
|
|
59
|
+
|
|
60
|
+```java
|
|
61
|
+import com.th3rdwave.safeareacontext.SafeAreaContextPackage;
|
|
62
|
+```
|
|
63
|
+
|
|
64
|
+Add the `SafeAreaContextPackage` class to your list of exported packages.
|
|
65
|
+
|
|
66
|
+```java
|
|
67
|
+@Override
|
|
68
|
+protected List<ReactPackage> getPackages() {
|
|
69
|
+ return Arrays.asList(
|
|
70
|
+ new MainReactPackage(),
|
|
71
|
+ new SafeAreaContextPackage()
|
|
72
|
+ );
|
|
73
|
+}
|
|
74
|
+```
|
|
75
|
+</details>
|
|
76
|
+
|
|
77
|
+## Example
|
|
78
|
+
|
|
79
|
+```js
|
|
80
|
+import React from 'react';
|
|
81
|
+import { View } from 'react-native';
|
|
82
|
+import { SafeAreaProvider, useSafeArea } from 'react-native-safe-area-context';
|
|
83
|
+
|
|
84
|
+function SomeComponent() {
|
|
85
|
+ const insets = useSafeArea();
|
|
86
|
+
|
|
87
|
+ return <View style={{ paddingTop: insets.top }} />;
|
|
88
|
+}
|
|
89
|
+
|
|
90
|
+function App() {
|
|
91
|
+ return (
|
|
92
|
+ <SafeAreaProvider>
|
|
93
|
+ <SomeComponent />
|
|
94
|
+ </SafeAreaProvider>
|
|
95
|
+ );
|
|
96
|
+}
|
|
97
|
+```
|