From 84915a2d68c2cb4cc17ca3a4651f33ba71a787ee Mon Sep 17 00:00:00 2001 From: Eli White Date: Fri, 18 Oct 2019 14:47:34 -0700 Subject: [PATCH] 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 --- .../Components/SafeAreaView/SafeAreaView.js | 52 ++++++++----------- .../__snapshots__/SafeAreaView-test.js.snap | 8 +-- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/Libraries/Components/SafeAreaView/SafeAreaView.js b/Libraries/Components/SafeAreaView/SafeAreaView.js index 9c22f7dabb1..22fc9e44553 100644 --- a/Libraries/Components/SafeAreaView/SafeAreaView.js +++ b/Libraries/Components/SafeAreaView/SafeAreaView.js @@ -4,7 +4,7 @@ * 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 */ @@ -12,6 +12,7 @@ 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<{| @@ -19,7 +20,10 @@ type Props = $ReadOnly<{| emulateUnlessSupported?: boolean, |}>; -let exported: Class>; +let exported: React.AbstractComponent< + Props, + React.ElementRef>, +>; /** * Renders nested content and automatically applies paddings reflect the portion @@ -31,37 +35,27 @@ let exported: Class>; * sensor housing area on iPhone X). */ if (Platform.OS === 'android') { - const SafeAreaView = ( - props: Props, - forwardedRef?: ?React.Ref, - ) => { - const {emulateUnlessSupported, ...localProps} = props; - return ; - }; - - const SafeAreaViewRef = React.forwardRef(SafeAreaView); - SafeAreaViewRef.displayName = 'SafeAreaView'; - exported = ((SafeAreaViewRef: any): Class>); + exported = React.forwardRef>>( + function SafeAreaView(props, forwardedRef) { + const {emulateUnlessSupported, ...localProps} = props; + return ; + }, + ); } else { const RCTSafeAreaViewNativeComponent = require('./RCTSafeAreaViewNativeComponent') .default; - const SafeAreaView = ( - props: Props, - forwardedRef?: ?React.Ref, - ) => { - return ( - - ); - }; - - const SafeAreaViewRef = React.forwardRef(SafeAreaView); - SafeAreaViewRef.displayName = 'SafeAreaView'; - exported = ((SafeAreaViewRef: any): Class>); + exported = React.forwardRef>>( + function SafeAreaView(props, forwardedRef) { + return ( + + ); + }, + ); } module.exports = exported; diff --git a/Libraries/Components/SafeAreaView/__tests__/__snapshots__/SafeAreaView-test.js.snap b/Libraries/Components/SafeAreaView/__tests__/__snapshots__/SafeAreaView-test.js.snap index 93c8ecf54c9..9f41a3b95b4 100644 --- a/Libraries/Components/SafeAreaView/__tests__/__snapshots__/SafeAreaView-test.js.snap +++ b/Libraries/Components/SafeAreaView/__tests__/__snapshots__/SafeAreaView-test.js.snap @@ -25,21 +25,21 @@ exports[` should render as when not mocked 1`] = `; exports[` should shallow render as when mocked 1`] = ` - + Hello World! - + `; exports[` should shallow render as when not mocked 1`] = ` - + Hello World! - + `;