Procházet zdrojové kódy

Allow using multiple providers again

Janic Duplessis před 4 roky
rodič
revize
e1cafde288
1 změnil soubory, kde provedl 11 přidání a 17 odebrání
  1. 11
    17
      src/index.tsx

+ 11
- 17
src/index.tsx Zobrazit soubor

@@ -14,29 +14,23 @@ export function SafeAreaProvider({
14 14
   children,
15 15
   initialSafeAreaInsets,
16 16
 }: SafeAreaViewProps) {
17
-  let parentInsets = useParentSafeArea();
17
+  const parentInsets = useParentSafeArea();
18 18
   const [insets, setInsets] = React.useState<EdgeInsets | null | undefined>(
19
-    initialSafeAreaInsets,
19
+    initialSafeAreaInsets || parentInsets,
20 20
   );
21 21
   const onInsetsChange = React.useCallback((event: InsetChangedEvent) => {
22 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 36
 const styles = StyleSheet.create({