From a911efaecd005237816ddb480218eb5388460d16 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Thu, 22 Oct 2020 19:59:33 -0700 Subject: [PATCH] Text: Refine Exported Flow Type Summary: Refines the exported type of `Text` so that it is more accurate. Instead of `HostComponent` (which is not exactly accurate), we use the recently introduced types: `NativText` and `NativeVirtualText`. Changelog: [Changed][General] - Refined Flow type for `Text` component. Reviewed By: nadiia Differential Revision: D24486720 fbshipit-source-id: fad114fd14335933ebc2f7430d7b8b7838b6b523 --- Libraries/Text/Text.js | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/Libraries/Text/Text.js b/Libraries/Text/Text.js index 681922ea13f..a3aa9dfad06 100644 --- a/Libraries/Text/Text.js +++ b/Libraries/Text/Text.js @@ -21,7 +21,6 @@ const nullthrows = require('nullthrows'); const processColor = require('../StyleSheet/processColor'); import type {PressEvent} from '../Types/CoreEventTypes'; -import type {HostComponent} from '../Renderer/shims/ReactNativeTypes'; import type {PressRetentionOffset, TextProps} from './TextProps'; type ResponseHandlers = $ReadOnly<{| @@ -231,27 +230,30 @@ const isTouchable = (props: Props): boolean => props.onLongPress != null || props.onStartShouldSetResponder != null; -const Text = ( - props: TextProps, - forwardedRef: ?React.Ref, -) => { - return ; -}; -const TextToExport = React.forwardRef(Text); -TextToExport.displayName = 'Text'; +const Text: React.AbstractComponent< + TextProps, + React.ElementRef, +> = React.forwardRef( + ( + props: TextProps, + forwardedRef: ?React.Ref, + ) => { + return ; + }, +); +Text.displayName = 'Text'; // TODO: Deprecate this. /* $FlowFixMe(>=0.89.0 site=react_native_fb) This comment suppresses an error * found when Flow v0.89 was deployed. To see the error, delete this comment * and run Flow. */ -TextToExport.propTypes = DeprecatedTextPropTypes; +Text.propTypes = DeprecatedTextPropTypes; -type TextStatics = $ReadOnly<{| - propTypes: typeof DeprecatedTextPropTypes, -|}>; +const TextToExport: typeof Text & + $ReadOnly<{| + propTypes: typeof DeprecatedTextPropTypes, + |}> = + // $FlowFixMe[incompatible-type] - No good way to type a React.AbstractComponent with statics. + Text; -module.exports = ((TextToExport: any): React.AbstractComponent< - TextProps, - React.ElementRef>, -> & - TextStatics); +module.exports = TextToExport;