Pārlūkot izejas kodu

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 gadus atpakaļ
vecāks
revīzija
79ab4dd028
No account linked to committer's email address
1 mainītis faili ar 10 papildinājumiem un 0 dzēšanām
  1. 10
    0
      src/SafeAreaContext.tsx

+ 10
- 0
src/SafeAreaContext.tsx Parādīt failu

@@ -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
+}