Skip to content

Commit 84915a2

Browse files
elicwhitefacebook-github-bot
authored andcommitted
Make SafeAreView flow strict-local
Summary: The forwardRef calls were able to be cleaned up and consolidated a bit. Changelog: [Changed][SafeAreaView] Improved SafeAreaView's typing, removing extra underscore from display name Reviewed By: cpojer Differential Revision: D17881901 fbshipit-source-id: 00f876d34600f4cfd44075eb7ad7192c9a885907
1 parent f12c0e7 commit 84915a2

File tree

2 files changed

+27
-33
lines changed

2 files changed

+27
-33
lines changed

Libraries/Components/SafeAreaView/SafeAreaView.js

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow
7+
* @flow strict-local
88
* @format
99
*/
1010

1111
const Platform = require('../../Utilities/Platform');
1212
const React = require('react');
1313
const View = require('../View/View');
1414

15+
import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
1516
import type {ViewProps} from '../View/ViewPropTypes';
1617

1718
type Props = $ReadOnly<{|
1819
...ViewProps,
1920
emulateUnlessSupported?: boolean,
2021
|}>;
2122

22-
let exported: Class<React$Component<Props>>;
23+
let exported: React.AbstractComponent<
24+
Props,
25+
React.ElementRef<HostComponent<mixed>>,
26+
>;
2327

2428
/**
2529
* Renders nested content and automatically applies paddings reflect the portion
@@ -31,37 +35,27 @@ let exported: Class<React$Component<Props>>;
3135
* sensor housing area on iPhone X).
3236
*/
3337
if (Platform.OS === 'android') {
34-
const SafeAreaView = (
35-
props: Props,
36-
forwardedRef?: ?React.Ref<typeof View>,
37-
) => {
38-
const {emulateUnlessSupported, ...localProps} = props;
39-
return <View {...localProps} ref={forwardedRef} />;
40-
};
41-
42-
const SafeAreaViewRef = React.forwardRef(SafeAreaView);
43-
SafeAreaViewRef.displayName = 'SafeAreaView';
44-
exported = ((SafeAreaViewRef: any): Class<React.Component<Props>>);
38+
exported = React.forwardRef<Props, React.ElementRef<HostComponent<mixed>>>(
39+
function SafeAreaView(props, forwardedRef) {
40+
const {emulateUnlessSupported, ...localProps} = props;
41+
return <View {...localProps} ref={forwardedRef} />;
42+
},
43+
);
4544
} else {
4645
const RCTSafeAreaViewNativeComponent = require('./RCTSafeAreaViewNativeComponent')
4746
.default;
4847

49-
const SafeAreaView = (
50-
props: Props,
51-
forwardedRef?: ?React.Ref<typeof RCTSafeAreaViewNativeComponent>,
52-
) => {
53-
return (
54-
<RCTSafeAreaViewNativeComponent
55-
emulateUnlessSupported={true}
56-
{...props}
57-
ref={forwardedRef}
58-
/>
59-
);
60-
};
61-
62-
const SafeAreaViewRef = React.forwardRef(SafeAreaView);
63-
SafeAreaViewRef.displayName = 'SafeAreaView';
64-
exported = ((SafeAreaViewRef: any): Class<React.Component<Props>>);
48+
exported = React.forwardRef<Props, React.ElementRef<HostComponent<mixed>>>(
49+
function SafeAreaView(props, forwardedRef) {
50+
return (
51+
<RCTSafeAreaViewNativeComponent
52+
emulateUnlessSupported={true}
53+
{...props}
54+
ref={forwardedRef}
55+
/>
56+
);
57+
},
58+
);
6559
}
6660

6761
module.exports = exported;

Libraries/Components/SafeAreaView/__tests__/__snapshots__/SafeAreaView-test.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ exports[`<SafeAreaView /> should render as <SafeAreaView> when not mocked 1`] =
2525
`;
2626
2727
exports[`<SafeAreaView /> should shallow render as <ForwardRef(SafeAreaView)> when mocked 1`] = `
28-
<ForwardRef(_SafeAreaView)>
28+
<ForwardRef(SafeAreaView)>
2929
<View>
3030
<Text>
3131
Hello World!
3232
</Text>
3333
</View>
34-
</ForwardRef(_SafeAreaView)>
34+
</ForwardRef(SafeAreaView)>
3535
`;
3636
3737
exports[`<SafeAreaView /> should shallow render as <ForwardRef(SafeAreaView)> when not mocked 1`] = `
38-
<ForwardRef(_SafeAreaView)>
38+
<ForwardRef(SafeAreaView)>
3939
<View>
4040
<Text>
4141
Hello World!
4242
</Text>
4343
</View>
44-
</ForwardRef(_SafeAreaView)>
44+
</ForwardRef(SafeAreaView)>
4545
`;

0 commit comments

Comments
 (0)