Skip to content

Commit

Permalink
deps: Make a type-wrapper for a thing from react-native-safe-area-con…
Browse files Browse the repository at this point in the history
…text.

As Greg points out [1], `react-native-safe-area-context` isn't doing
the right thing with their type, and we lose type-checking on the
wrapped component's props.

So, make a small type-wrapper that works.

[1] zulip#4315 (comment)
  • Loading branch information
chrisbobbe committed Jan 7, 2021
1 parent 3730be4 commit 8f56964
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/react-native-safe-area-context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* @flow strict-local */
import type { ComponentType, ElementConfig } from 'react';
import {
withSafeAreaInsets as withSafeAreaInsetsInner,
type EdgeInsets,
} from 'react-native-safe-area-context';

import type { BoundedDiff } from './generics';

/* eslint-disable flowtype/generic-spacing */

/**
* Exactly like `withSafeAreaInsets` upstream, but properly typed.
*
* The correction is made here, instead of in the libdef, so that we
* can use the handy `BoundedDiff` type, as we do in our type-wrapper
* for react-redux's `connect`.
*/
export function withSafeAreaInsets<P, C: ComponentType<P>>(
WrappedComponent: C,
): ComponentType<$ReadOnly<BoundedDiff<$Exact<ElementConfig<C>>, {| insets: EdgeInsets |}>>> {
return withSafeAreaInsetsInner(WrappedComponent);
}

0 comments on commit 8f56964

Please sign in to comment.