mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
afb926abb1
commit
a911efaecd
+20
-18
@@ -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<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;
|
||||
|
||||
Reference in New Issue
Block a user