Skip to content

Commit a911efa

Browse files
yungstersfacebook-github-bot
authored andcommitted
Text: Refine Exported Flow Type
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
1 parent afb926a commit a911efa

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

Libraries/Text/Text.js

+20-18
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const nullthrows = require('nullthrows');
2121
const processColor = require('../StyleSheet/processColor');
2222

2323
import type {PressEvent} from '../Types/CoreEventTypes';
24-
import type {HostComponent} from '../Renderer/shims/ReactNativeTypes';
2524
import type {PressRetentionOffset, TextProps} from './TextProps';
2625

2726
type ResponseHandlers = $ReadOnly<{|
@@ -231,27 +230,30 @@ const isTouchable = (props: Props): boolean =>
231230
props.onLongPress != null ||
232231
props.onStartShouldSetResponder != null;
233232

234-
const Text = (
235-
props: TextProps,
236-
forwardedRef: ?React.Ref<typeof NativeText | typeof NativeVirtualText>,
237-
) => {
238-
return <TouchableText {...props} forwardedRef={forwardedRef} />;
239-
};
240-
const TextToExport = React.forwardRef(Text);
241-
TextToExport.displayName = 'Text';
233+
const Text: React.AbstractComponent<
234+
TextProps,
235+
React.ElementRef<typeof NativeText | typeof NativeVirtualText>,
236+
> = React.forwardRef(
237+
(
238+
props: TextProps,
239+
forwardedRef: ?React.Ref<typeof NativeText | typeof NativeVirtualText>,
240+
) => {
241+
return <TouchableText {...props} forwardedRef={forwardedRef} />;
242+
},
243+
);
244+
Text.displayName = 'Text';
242245

243246
// TODO: Deprecate this.
244247
/* $FlowFixMe(>=0.89.0 site=react_native_fb) This comment suppresses an error
245248
* found when Flow v0.89 was deployed. To see the error, delete this comment
246249
* and run Flow. */
247-
TextToExport.propTypes = DeprecatedTextPropTypes;
250+
Text.propTypes = DeprecatedTextPropTypes;
248251

249-
type TextStatics = $ReadOnly<{|
250-
propTypes: typeof DeprecatedTextPropTypes,
251-
|}>;
252+
const TextToExport: typeof Text &
253+
$ReadOnly<{|
254+
propTypes: typeof DeprecatedTextPropTypes,
255+
|}> =
256+
// $FlowFixMe[incompatible-type] - No good way to type a React.AbstractComponent with statics.
257+
Text;
252258

253-
module.exports = ((TextToExport: any): React.AbstractComponent<
254-
TextProps,
255-
React.ElementRef<HostComponent<TextProps>>,
256-
> &
257-
TextStatics);
259+
module.exports = TextToExport;

0 commit comments

Comments
 (0)