Browse Source

Allow using multiple providers again

Janic Duplessis 4 years ago
parent
commit
e1cafde288
1 changed files with 11 additions and 17 deletions
  1. 11
    17
      src/index.tsx

+ 11
- 17
src/index.tsx View File

14
   children,
14
   children,
15
   initialSafeAreaInsets,
15
   initialSafeAreaInsets,
16
 }: SafeAreaViewProps) {
16
 }: SafeAreaViewProps) {
17
-  let parentInsets = useParentSafeArea();
17
+  const parentInsets = useParentSafeArea();
18
   const [insets, setInsets] = React.useState<EdgeInsets | null | undefined>(
18
   const [insets, setInsets] = React.useState<EdgeInsets | null | undefined>(
19
-    initialSafeAreaInsets,
19
+    initialSafeAreaInsets || parentInsets,
20
   );
20
   );
21
   const onInsetsChange = React.useCallback((event: InsetChangedEvent) => {
21
   const onInsetsChange = React.useCallback((event: InsetChangedEvent) => {
22
     setInsets(event.nativeEvent.insets);
22
     setInsets(event.nativeEvent.insets);
23
   }, []);
23
   }, []);
24
 
24
 
25
-  // If a provider is nested inside of another provider then we can just use
26
-  // the parent insets, without rendering another native safe area view
27
-  if (parentInsets != null) {
28
-    return <View style={styles.fill}>{children}</View>;
29
-  } else {
30
-    return (
31
-      <NativeSafeAreaView style={styles.fill} onInsetsChange={onInsetsChange}>
32
-        {insets != null ? (
33
-          <SafeAreaContext.Provider value={insets}>
34
-            {children}
35
-          </SafeAreaContext.Provider>
36
-        ) : null}
37
-      </NativeSafeAreaView>
38
-    );
39
-  }
25
+  return (
26
+    <NativeSafeAreaView style={styles.fill} onInsetsChange={onInsetsChange}>
27
+      {insets != null ? (
28
+        <SafeAreaContext.Provider value={insets}>
29
+          {children}
30
+        </SafeAreaContext.Provider>
31
+      ) : null}
32
+    </NativeSafeAreaView>
33
+  );
40
 }
34
 }
41
 
35
 
42
 const styles = StyleSheet.create({
36
 const styles = StyleSheet.create({