瀏覽代碼

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