Browse Source

Add react-native-safe-area-view example

Janic Duplessis 4 years ago
parent
commit
f126189030
5 changed files with 46 additions and 4 deletions
  1. 2
    1
      example/package.json
  2. 22
    3
      example/src/App.tsx
  3. 14
    0
      example/src/ReactNativeSafeAreaView.tsx
  4. 1
    0
      package.json
  5. 7
    0
      yarn.lock

+ 2
- 1
example/package.json View File

@@ -16,6 +16,7 @@
16 16
     "react-navigation-tabs": "^2.8.13",
17 17
     "react-native-gesture-handler": "^1.6.1",
18 18
     "react-native-screens": "^2.7.0",
19
-    "react-native-reanimated": "^1.8.0"
19
+    "react-native-reanimated": "^1.8.0",
20
+    "react-native-safe-area-view": "^1.1.1"
20 21
   }
21 22
 }

+ 22
- 3
example/src/App.tsx View File

@@ -1,12 +1,13 @@
1 1
 import 'react-native-gesture-handler';
2 2
 import * as React from 'react';
3
-import { DevSettings } from 'react-native';
3
+import { DevSettings, View, Text } from 'react-native';
4 4
 import { enableScreens } from 'react-native-screens';
5 5
 import AsyncStorage from '@react-native-community/async-storage';
6 6
 import ReactNavigation4Example from './ReactNavigation4Example';
7 7
 import ReactNavigation5Example from './ReactNavigation5Example';
8 8
 import SimpleExample from './SimpleExample';
9 9
 import NativeStackExample from './NativeStackExample';
10
+import ReactNativeSafeAreaView from './ReactNativeSafeAreaView';
10 11
 
11 12
 enableScreens();
12 13
 
@@ -20,7 +21,7 @@ export default function App() {
20 21
   React.useEffect(() => {
21 22
     async function loadCurrentExample() {
22 23
       const example = await AsyncStorage.getItem(STORAGE_KEY);
23
-      setCurrentExample(example ?? 'simple');
24
+      setCurrentExample(example ?? null);
24 25
     }
25 26
     loadCurrentExample();
26 27
   }, []);
@@ -47,6 +48,9 @@ export default function App() {
47 48
     DevSettings.addMenuItem('Show Native Stack Example', () => {
48 49
       setCurrentExample('native-stack');
49 50
     });
51
+    DevSettings.addMenuItem('Show React Native Safe Area View Example', () => {
52
+      setCurrentExample('react-native-safe-area-view');
53
+    });
50 54
   }, []);
51 55
 
52 56
   switch (currentExample) {
@@ -58,7 +62,22 @@ export default function App() {
58 62
       return <ReactNavigation5Example />;
59 63
     case 'native-stack':
60 64
       return <NativeStackExample />;
65
+    case 'react-native-safe-area-view':
66
+      return <ReactNativeSafeAreaView />;
61 67
     default:
62
-      return null;
68
+      return (
69
+        <View
70
+          style={{
71
+            flex: 1,
72
+            alignItems: 'center',
73
+            justifyContent: 'center',
74
+            padding: 24,
75
+          }}
76
+        >
77
+          <Text style={{ textAlign: 'center', fontSize: 14 }}>
78
+            Open the dev menu to choose an example
79
+          </Text>
80
+        </View>
81
+      );
63 82
   }
64 83
 }

+ 14
- 0
example/src/ReactNativeSafeAreaView.tsx View File

@@ -0,0 +1,14 @@
1
+import * as React from 'react';
2
+import { View } from 'react-native';
3
+import { SafeAreaProvider } from 'react-native-safe-area-context';
4
+import SafeAreaView from 'react-native-safe-area-view';
5
+
6
+export default function ReactNativeSafeAreaView() {
7
+  return (
8
+    <SafeAreaProvider>
9
+      <SafeAreaView style={{ flex: 1, backgroundColor: 'red' }}>
10
+        <View style={{ flex: 1, backgroundColor: 'blue' }} />
11
+      </SafeAreaView>
12
+    </SafeAreaProvider>
13
+  );
14
+}

+ 1
- 0
package.json View File

@@ -76,6 +76,7 @@
76 76
     "react-navigation": "^4.3.9",
77 77
     "react-navigation-stack": "^2.5.0",
78 78
     "react-navigation-tabs": "^2.8.13",
79
+    "react-native-safe-area-view": "1.1.1",
79 80
     "react-native-gesture-handler": "^1.6.1",
80 81
     "react-native-screens": "^2.7.0",
81 82
     "react-native-reanimated": "^1.8.0",

+ 7
- 0
yarn.lock View File

@@ -12457,6 +12457,13 @@ react-native-reanimated@^1.8.0:
12457 12457
   dependencies:
12458 12458
     fbjs "^1.0.0"
12459 12459
 
12460
+react-native-safe-area-view@1.1.1:
12461
+  version "1.1.1"
12462
+  resolved "https://registry.yarnpkg.com/react-native-safe-area-view/-/react-native-safe-area-view-1.1.1.tgz#9833e34c384d0513f4831afcd1e54946f13897b2"
12463
+  integrity sha512-bbLCtF+tqECyPWlgkWbIwx4vDPb0GEufx/ZGcSS4UljMcrpwluachDXoW9DBxhbMCc6k1V0ccqHWN7ntbRdERQ==
12464
+  dependencies:
12465
+    hoist-non-react-statics "^2.3.1"
12466
+
12460 12467
 react-native-safe-area-view@^0.14.9:
12461 12468
   version "0.14.9"
12462 12469
   resolved "https://registry.yarnpkg.com/react-native-safe-area-view/-/react-native-safe-area-view-0.14.9.tgz#90ee8383037010d9a5055a97cf97e4c1da1f0c3d"