Преглед изворни кода

Add react-native-safe-area-view example

Janic Duplessis пре 4 година
родитељ
комит
f126189030
5 измењених фајлова са 46 додато и 4 уклоњено
  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 Прегледај датотеку

16
     "react-navigation-tabs": "^2.8.13",
16
     "react-navigation-tabs": "^2.8.13",
17
     "react-native-gesture-handler": "^1.6.1",
17
     "react-native-gesture-handler": "^1.6.1",
18
     "react-native-screens": "^2.7.0",
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 Прегледај датотеку

1
 import 'react-native-gesture-handler';
1
 import 'react-native-gesture-handler';
2
 import * as React from 'react';
2
 import * as React from 'react';
3
-import { DevSettings } from 'react-native';
3
+import { DevSettings, View, Text } from 'react-native';
4
 import { enableScreens } from 'react-native-screens';
4
 import { enableScreens } from 'react-native-screens';
5
 import AsyncStorage from '@react-native-community/async-storage';
5
 import AsyncStorage from '@react-native-community/async-storage';
6
 import ReactNavigation4Example from './ReactNavigation4Example';
6
 import ReactNavigation4Example from './ReactNavigation4Example';
7
 import ReactNavigation5Example from './ReactNavigation5Example';
7
 import ReactNavigation5Example from './ReactNavigation5Example';
8
 import SimpleExample from './SimpleExample';
8
 import SimpleExample from './SimpleExample';
9
 import NativeStackExample from './NativeStackExample';
9
 import NativeStackExample from './NativeStackExample';
10
+import ReactNativeSafeAreaView from './ReactNativeSafeAreaView';
10
 
11
 
11
 enableScreens();
12
 enableScreens();
12
 
13
 
20
   React.useEffect(() => {
21
   React.useEffect(() => {
21
     async function loadCurrentExample() {
22
     async function loadCurrentExample() {
22
       const example = await AsyncStorage.getItem(STORAGE_KEY);
23
       const example = await AsyncStorage.getItem(STORAGE_KEY);
23
-      setCurrentExample(example ?? 'simple');
24
+      setCurrentExample(example ?? null);
24
     }
25
     }
25
     loadCurrentExample();
26
     loadCurrentExample();
26
   }, []);
27
   }, []);
47
     DevSettings.addMenuItem('Show Native Stack Example', () => {
48
     DevSettings.addMenuItem('Show Native Stack Example', () => {
48
       setCurrentExample('native-stack');
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
   switch (currentExample) {
56
   switch (currentExample) {
58
       return <ReactNavigation5Example />;
62
       return <ReactNavigation5Example />;
59
     case 'native-stack':
63
     case 'native-stack':
60
       return <NativeStackExample />;
64
       return <NativeStackExample />;
65
+    case 'react-native-safe-area-view':
66
+      return <ReactNativeSafeAreaView />;
61
     default:
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 Прегледај датотеку

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 Прегледај датотеку

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

+ 7
- 0
yarn.lock Прегледај датотеку

12457
   dependencies:
12457
   dependencies:
12458
     fbjs "^1.0.0"
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
 react-native-safe-area-view@^0.14.9:
12467
 react-native-safe-area-view@^0.14.9:
12461
   version "0.14.9"
12468
   version "0.14.9"
12462
   resolved "https://registry.yarnpkg.com/react-native-safe-area-view/-/react-native-safe-area-view-0.14.9.tgz#90ee8383037010d9a5055a97cf97e4c1da1f0c3d"
12469
   resolved "https://registry.yarnpkg.com/react-native-safe-area-view/-/react-native-safe-area-view-0.14.9.tgz#90ee8383037010d9a5055a97cf97e4c1da1f0c3d"