Skip to content

Commit

Permalink
Text: Refine Exported Flow Type
Browse files Browse the repository at this point in the history
Summary:
Refines the exported type of `Text` so that it is more accurate.

Instead of `HostComponent<TextProps>` (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
  • Loading branch information
yungsters authored and facebook-github-bot committed Oct 23, 2020
1 parent afb926a commit a911efa
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<{|
Expand Down Expand Up @@ -231,27 +230,30 @@ const isTouchable = (props: Props): boolean =>
props.onLongPress != null ||
props.onStartShouldSetResponder != null;

const Text = (
props: TextProps,
forwardedRef: ?React.Ref<typeof NativeText | typeof NativeVirtualText>,
) => {
return <TouchableText {...props} forwardedRef={forwardedRef} />;
};
const TextToExport = React.forwardRef(Text);
TextToExport.displayName = 'Text';
const Text: React.AbstractComponent<
TextProps,
React.ElementRef<typeof NativeText | typeof NativeVirtualText>,
> = React.forwardRef(
(
props: TextProps,
forwardedRef: ?React.Ref<typeof NativeText | typeof NativeVirtualText>,
) => {
return <TouchableText {...props} forwardedRef={forwardedRef} />;
},
);
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<HostComponent<TextProps>>,
> &
TextStatics);
module.exports = TextToExport;

0 comments on commit a911efa

Please sign in to comment.