Skip to content

Commit

Permalink
Make SafeAreView flow strict-local
Browse files Browse the repository at this point in the history
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
  • Loading branch information
TheSavior authored and facebook-github-bot committed Oct 18, 2019
1 parent f12c0e7 commit 84915a2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
52 changes: 23 additions & 29 deletions Libraries/Components/SafeAreaView/SafeAreaView.js
Expand Up @@ -4,22 +4,26 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
*/

const Platform = require('../../Utilities/Platform');
const React = require('react');
const View = require('../View/View');

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

type Props = $ReadOnly<{|
...ViewProps,
emulateUnlessSupported?: boolean,
|}>;

let exported: Class<React$Component<Props>>;
let exported: React.AbstractComponent<
Props,
React.ElementRef<HostComponent<mixed>>,
>;

/**
* Renders nested content and automatically applies paddings reflect the portion
Expand All @@ -31,37 +35,27 @@ let exported: Class<React$Component<Props>>;
* sensor housing area on iPhone X).
*/
if (Platform.OS === 'android') {
const SafeAreaView = (
props: Props,
forwardedRef?: ?React.Ref<typeof View>,
) => {
const {emulateUnlessSupported, ...localProps} = props;
return <View {...localProps} ref={forwardedRef} />;
};

const SafeAreaViewRef = React.forwardRef(SafeAreaView);
SafeAreaViewRef.displayName = 'SafeAreaView';
exported = ((SafeAreaViewRef: any): Class<React.Component<Props>>);
exported = React.forwardRef<Props, React.ElementRef<HostComponent<mixed>>>(
function SafeAreaView(props, forwardedRef) {
const {emulateUnlessSupported, ...localProps} = props;
return <View {...localProps} ref={forwardedRef} />;
},
);
} else {
const RCTSafeAreaViewNativeComponent = require('./RCTSafeAreaViewNativeComponent')
.default;

const SafeAreaView = (
props: Props,
forwardedRef?: ?React.Ref<typeof RCTSafeAreaViewNativeComponent>,
) => {
return (
<RCTSafeAreaViewNativeComponent
emulateUnlessSupported={true}
{...props}
ref={forwardedRef}
/>
);
};

const SafeAreaViewRef = React.forwardRef(SafeAreaView);
SafeAreaViewRef.displayName = 'SafeAreaView';
exported = ((SafeAreaViewRef: any): Class<React.Component<Props>>);
exported = React.forwardRef<Props, React.ElementRef<HostComponent<mixed>>>(
function SafeAreaView(props, forwardedRef) {
return (
<RCTSafeAreaViewNativeComponent
emulateUnlessSupported={true}
{...props}
ref={forwardedRef}
/>
);
},
);
}

module.exports = exported;
Expand Up @@ -25,21 +25,21 @@ exports[`<SafeAreaView /> should render as <SafeAreaView> when not mocked 1`] =
`;
exports[`<SafeAreaView /> should shallow render as <ForwardRef(SafeAreaView)> when mocked 1`] = `
<ForwardRef(_SafeAreaView)>
<ForwardRef(SafeAreaView)>
<View>
<Text>
Hello World!
</Text>
</View>
</ForwardRef(_SafeAreaView)>
</ForwardRef(SafeAreaView)>
`;
exports[`<SafeAreaView /> should shallow render as <ForwardRef(SafeAreaView)> when not mocked 1`] = `
<ForwardRef(_SafeAreaView)>
<ForwardRef(SafeAreaView)>
<View>
<Text>
Hello World!
</Text>
</View>
</ForwardRef(_SafeAreaView)>
</ForwardRef(SafeAreaView)>
`;

0 comments on commit 84915a2

Please sign in to comment.