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

Add withSafeAreaConsumer HOC (#57)

* Add withSafeAreaConsumer HOC

It's a good option to inject the insets of SafeAreaConsumer as props from React class components

* Fix prettier issues
Juan David Nicholls Cardona пре 4 година
родитељ
комит
79ab4dd028
No account linked to committer's email address
1 измењених фајлова са 10 додато и 0 уклоњено
  1. 10
    0
      src/SafeAreaContext.tsx

+ 10
- 0
src/SafeAreaContext.tsx Прегледај датотеку

@@ -106,3 +106,13 @@ export function SafeAreaConsumer(
106 106
 ) {
107 107
   return <SafeAreaInsetsContext.Consumer {...props} />;
108 108
 }
109
+
110
+export function withSafeAreaInsets<T>(
111
+  WrappedComponent: React.ComponentType<T>,
112
+) {
113
+  return (props: T) => (
114
+    <SafeAreaConsumer>
115
+      {insets => <WrappedComponent {...props} insets={insets} />}
116
+    </SafeAreaConsumer>
117
+  );
118
+}