Browse Source

Update deps and example

Janic Duplessis 5 years ago
parent
commit
aee3446314

+ 1
- 0
.eslintrc.js View File

@@ -23,6 +23,7 @@ module.exports = {
23 23
           '@typescript-eslint/explicit-member-accessibility': 'off',
24 24
           '@typescript-eslint/explicit-function-return-type': 'off',
25 25
           '@typescript-eslint/no-use-before-define': 'off',
26
+          '@typescript-eslint/ban-ts-ignore': 'off',
26 27
           'react-native/no-inline-styles': 'off',
27 28
         },
28 29
       ),

+ 0
- 13
android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.java View File

@@ -1,8 +1,6 @@
1 1
 package com.th3rdwave.safeareacontext;
2 2
 
3
-import android.app.Activity;
4 3
 import android.content.Context;
5
-import android.content.ContextWrapper;
6 4
 import android.os.Build;
7 5
 import android.view.Surface;
8 6
 import android.view.View;
@@ -30,17 +28,6 @@ public class SafeAreaView extends ReactViewGroup implements ViewTreeObserver.OnG
30 28
     mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
31 29
   }
32 30
 
33
-  private Activity getActivity() {
34
-    Context context = getContext();
35
-    while (context instanceof ContextWrapper) {
36
-      if (context instanceof Activity) {
37
-        return (Activity)context;
38
-      }
39
-      context = ((ContextWrapper)context).getBaseContext();
40
-    }
41
-    return null;
42
-  }
43
-
44 31
   private EdgeInsets getSafeAreaInsets() {
45 32
     // Window insets are parts of the window that are covered by system views (status bar,
46 33
     // navigation bar, notches). There are no apis the get these values for android < M so we

+ 34
- 138
example/App.tsx View File

@@ -1,59 +1,10 @@
1
-/**
2
- * Sample React Native App
3
- * https://github.com/facebook/react-native
4
- *
5
- * @format
6
- * @flow
7
- */
8
-
9 1
 import * as React from 'react';
10
-import { StyleSheet, ScrollView, View, Text, StatusBar } from 'react-native';
11
-
12
-import {
13
-  Header,
14
-  LearnMoreLinks,
15
-  Colors,
16
-  DebugInstructions,
17
-  ReloadInstructions,
18
-} from 'react-native/Libraries/NewAppScreen';
2
+import { View, Text, StatusBar, Button } from 'react-native';
19 3
 
20 4
 // import { SafeAreaProvider, useSafeArea } from 'react-native-safe-area-context'; in your app.
21 5
 import { SafeAreaProvider, useSafeArea } from '../src';
22 6
 
23
-type ForceInsets = 'always' | 'never';
24
-
25
-const CompatSafeAreaView = ({
26
-  forceInsets = {},
27
-  children,
28
-}: {
29
-  forceInsets?: {
30
-    top?: ForceInsets;
31
-    right?: ForceInsets;
32
-    bottom?: ForceInsets;
33
-    left?: ForceInsets;
34
-  };
35
-  children?: React.ReactNode;
36
-}) => {
37
-  const insets = useSafeArea();
38
-  const top = forceInsets.top === 'never' ? 0 : insets.top;
39
-  const right = forceInsets.right === 'never' ? 0 : insets.right;
40
-  const bottom = forceInsets.bottom === 'never' ? 0 : insets.bottom;
41
-  const left = forceInsets.left === 'never' ? 0 : insets.left;
42
-  return (
43
-    <View
44
-      style={{
45
-        paddingTop: top,
46
-        paddingRight: right,
47
-        paddingBottom: bottom,
48
-        paddingLeft: left,
49
-      }}
50
-    >
51
-      {children}
52
-    </View>
53
-  );
54
-};
55
-
56
-const App = () => {
7
+const Screen = () => {
57 8
   const insets = useSafeArea();
58 9
   return (
59 10
     <>
@@ -62,97 +13,42 @@ const App = () => {
62 13
         translucent={false}
63 14
         backgroundColor="transparent"
64 15
       />
65
-      <ScrollView
66
-        contentInsetAdjustmentBehavior="never"
67
-        style={styles.scrollView}
68
-      >
69
-        <CompatSafeAreaView>
70
-          <Header />
71
-          <View style={styles.body}>
72
-            <View style={styles.sectionContainer}>
73
-              <Text style={styles.sectionTitle}>Step One</Text>
74
-              <Text style={styles.sectionDescription}>
75
-                Edit <Text style={styles.highlight}>App.js</Text> to change this
76
-                screen and then come back to see your edits.
77
-              </Text>
78
-            </View>
79
-            <View style={styles.sectionContainer}>
80
-              <Text style={styles.sectionTitle}>See Your Changes</Text>
81
-              <Text style={styles.sectionDescription}>
82
-                <ReloadInstructions />
83
-              </Text>
84
-            </View>
85
-            <View style={styles.sectionContainer}>
86
-              <Text style={styles.sectionTitle}>Debug</Text>
87
-              <Text style={styles.sectionDescription}>
88
-                <DebugInstructions />
89
-              </Text>
90
-            </View>
91
-            <View style={styles.sectionContainer}>
92
-              <Text style={styles.sectionTitle}>Learn More</Text>
93
-              <Text style={styles.sectionDescription}>
94
-                Read the docs to discover what to do next:
95
-              </Text>
96
-            </View>
97
-            <LearnMoreLinks />
98
-          </View>
99
-        </CompatSafeAreaView>
100
-      </ScrollView>
101 16
       <View
102 17
         style={{
103
-          position: 'absolute',
104
-          top: 0,
105
-          right: 0,
106
-          left: 0,
107
-          height: insets.top,
108
-          backgroundColor: 'rgba(0, 0, 0, 0.3)',
18
+          flex: 1,
19
+          backgroundColor: 'red',
20
+          paddingTop: insets.top,
21
+          paddingLeft: insets.left,
22
+          paddingBottom: insets.bottom,
23
+          paddingRight: insets.right,
109 24
         }}
110
-      />
25
+      >
26
+        <View
27
+          style={{
28
+            flex: 1,
29
+            backgroundColor: 'white',
30
+            alignItems: 'center',
31
+            justifyContent: 'center',
32
+          }}
33
+        >
34
+          <Text>Insets: {JSON.stringify(insets, null, 2)}</Text>
35
+        </View>
36
+      </View>
111 37
     </>
112 38
   );
113 39
 };
114 40
 
115
-const styles = StyleSheet.create({
116
-  scrollView: {
117
-    backgroundColor: Colors.lighter,
118
-  },
119
-  engine: {
120
-    position: 'absolute',
121
-    right: 0,
122
-  },
123
-  body: {
124
-    backgroundColor: Colors.white,
125
-  },
126
-  sectionContainer: {
127
-    marginTop: 32,
128
-    paddingHorizontal: 24,
129
-  },
130
-  sectionTitle: {
131
-    fontSize: 24,
132
-    fontWeight: '600',
133
-    color: Colors.black,
134
-  },
135
-  sectionDescription: {
136
-    marginTop: 8,
137
-    fontSize: 18,
138
-    fontWeight: '400',
139
-    color: Colors.dark,
140
-  },
141
-  highlight: {
142
-    fontWeight: '700',
143
-  },
144
-  footer: {
145
-    color: Colors.dark,
146
-    fontSize: 12,
147
-    fontWeight: '600',
148
-    padding: 4,
149
-    paddingRight: 12,
150
-    textAlign: 'right',
151
-  },
152
-});
153
-
154
-export default () => (
155
-  <SafeAreaProvider>
156
-    <App />
157
-  </SafeAreaProvider>
158
-);
41
+export default function App() {
42
+  const [refreshKey, setRefreshKey] = React.useState(1);
43
+  return (
44
+    <View key={refreshKey} style={{ flex: 1 }}>
45
+      <SafeAreaProvider>
46
+        <Screen />
47
+        <Button
48
+          title="Refresh"
49
+          onPress={() => setRefreshKey(state => state + 1)}
50
+        />
51
+      </SafeAreaProvider>
52
+    </View>
53
+  );
54
+}

+ 12
- 12
package.json View File

@@ -44,20 +44,20 @@
44 44
   "devDependencies": {
45 45
     "@react-native-community/bob": "^0.7.0",
46 46
     "@react-native-community/eslint-config": "^0.0.5",
47
-    "@types/react-native": "^0.60.5",
48
-    "@typescript-eslint/eslint-plugin": "^1.7.0",
49
-    "@typescript-eslint/parser": "^1.7.0",
50
-    "eslint": "5.16.0",
51
-    "eslint-config-prettier": "^4.2.0",
52
-    "eslint-plugin-prettier": "3.0.1",
53
-    "expo": "^34.0.4",
54
-    "metro-react-native-babel-preset": "^0.55.0",
47
+    "@types/react-native": "^0.60.22",
48
+    "@typescript-eslint/eslint-plugin": "^2.6.0",
49
+    "@typescript-eslint/parser": "^2.6.0",
50
+    "eslint": "6.6.0",
51
+    "eslint-config-prettier": "^6.5.0",
52
+    "eslint-plugin-prettier": "3.1.1",
53
+    "expo": "^35.0.0",
54
+    "metro-react-native-babel-preset": "^0.57.0",
55 55
     "prettier": "^1.18.2",
56
-    "react": "^16.8.3",
57
-    "react-dom": "^16.9.0",
58
-    "react-native": "^0.60.5",
56
+    "react": "^16.11.0",
57
+    "react-dom": "^16.11.0",
58
+    "react-native": "^0.61.0",
59 59
     "react-native-web": "^0.11.7",
60
-    "typescript": "^3.5.3"
60
+    "typescript": "^3.6.4"
61 61
   },
62 62
   "repository": {
63 63
     "type": "git",

+ 8
- 9
src/NativeSafeAreaView.web.tsx View File

@@ -9,13 +9,13 @@ interface NativeSafeAreaViewProps {
9 9
   onInsetsChange: InsetChangeNativeCallback;
10 10
 }
11 11
 
12
-enum CSSTransitions {
13
-  WebkitTransition = 'webkitTransitionEnd',
14
-  Transition = 'transitionEnd',
15
-  MozTransition = 'transitionend',
16
-  MSTransition = 'msTransitionEnd',
17
-  OTransition = 'oTransitionEnd',
18
-}
12
+const CSSTransitions: Record<string, string> = {
13
+  WebkitTransition: 'webkitTransitionEnd',
14
+  Transition: 'transitionEnd',
15
+  MozTransition: 'transitionend',
16
+  MSTransition: 'msTransitionEnd',
17
+  OTransition: 'oTransitionEnd',
18
+};
19 19
 
20 20
 export default function NativeSafeAreaView({
21 21
   children,
@@ -67,7 +67,7 @@ function getSupportedTransitionEvent(): string {
67 67
 
68 68
   _supportedTransitionEvent = CSSTransitions.Transition;
69 69
   for (const key in CSSTransitions) {
70
-    if (element.style[key] !== undefined) {
70
+    if (element.style[key as keyof CSSStyleDeclaration] !== undefined) {
71 71
       _supportedTransitionEvent = CSSTransitions[key];
72 72
       break;
73 73
     }
@@ -82,7 +82,6 @@ function getSupportedEnv(): CssEnv {
82 82
   if (_supportedEnv !== null) {
83 83
     return _supportedEnv;
84 84
   }
85
-  // @ts-ignore: Property 'CSS' does not exist on type 'Window'.ts(2339)
86 85
   const { CSS } = window;
87 86
   if (
88 87
     CSS &&

+ 565
- 368
yarn.lock
File diff suppressed because it is too large
View File