From 10c835214160cc5a5726c8dd9f0d42a0275d198b Mon Sep 17 00:00:00 2001 From: Spencer Ahrens Date: Tue, 5 Feb 2019 15:23:14 -0800 Subject: [PATCH] Fix flow typing of Text Summary: Make Text prop types exact to catch tons of errors, including typos like in https://fb.workplace.com/groups/rn.support/permalink/2306953619353240/. I tried to fix things when it was totally obvious what the intent was, but otherwise tried to keep the existing behavior the same, even if it meant that usage of some props was getting ignored, like `hitSlop`. Reviewed By: TheSavior Differential Revision: D13892999 fbshipit-source-id: 5003508a648287e4eca8055fb59da5f03bd066cc --- Libraries/Text/Text.js | 11 +++++------ Libraries/Text/TextProps.js | 7 +++++-- RNTester/js/TextInputExample.ios.js | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Libraries/Text/Text.js b/Libraries/Text/Text.js index 5df2ca4dc..972405793 100644 --- a/Libraries/Text/Text.js +++ b/Libraries/Text/Text.js @@ -34,10 +34,10 @@ type ResponseHandlers = $ReadOnly<{| onResponderTerminationRequest: () => boolean, |}>; -type Props = $ReadOnly<{ +type Props = $ReadOnly<{| ...TextProps, forwardedRef: ?React.Ref<'RCTText' | 'RCTVirtualText'>, -}>; +|}>; type State = {| touchable: {| @@ -286,7 +286,6 @@ TextToExport.displayName = 'Text'; * and run Flow. */ TextToExport.propTypes = DeprecatedTextPropTypes; -/* $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. */ -module.exports = (TextToExport: Class>); +module.exports = ((TextToExport: $FlowFixMe): Class< + NativeComponent, +>); diff --git a/Libraries/Text/TextProps.js b/Libraries/Text/TextProps.js index f70619f4b..2ffa8959f 100644 --- a/Libraries/Text/TextProps.js +++ b/Libraries/Text/TextProps.js @@ -29,13 +29,15 @@ export type PressRetentionOffset = $ReadOnly<{| /** * @see https://facebook.github.io/react-native/docs/text.html#reference */ -export type TextProps = $ReadOnly<{ +export type TextProps = $ReadOnly<{| /** * Indicates whether the view is an accessibility element. * * See https://facebook.github.io/react-native/docs/text.html#accessible */ accessible?: ?boolean, + accessibilityHint?: ?Stringish, + accessibilityLabel?: ?Stringish, accessibilityRole?: ?AccessibilityRole, accessibilityStates?: ?AccessibilityStates, accessibilityTraits?: ?(AccessibilityTrait | Array), @@ -112,6 +114,7 @@ export type TextProps = $ReadOnly<{ onResponderTerminate?: ?(event: PressEvent) => void, onResponderTerminationRequest?: ?() => boolean, onStartShouldSetResponder?: ?() => boolean, + onMoveShouldSetResponder?: ?() => boolean, onTextLayout?: ?(event: TextLayoutEvent) => mixed, /** @@ -180,4 +183,4 @@ export type TextProps = $ReadOnly<{ * See https://facebook.github.io/react-native/docs/text.html#supperhighlighting */ suppressHighlighting?: ?boolean, -}>; +|}>; diff --git a/RNTester/js/TextInputExample.ios.js b/RNTester/js/TextInputExample.ios.js index 64fd1cbb2..b7a61032e 100644 --- a/RNTester/js/TextInputExample.ios.js +++ b/RNTester/js/TextInputExample.ios.js @@ -630,7 +630,7 @@ exports.examples = [ (first raw text node) - (internal raw text node) + (internal raw text node) (last raw text node) @@ -640,7 +640,7 @@ exports.examples = [ multiline={true} value="(value property)"> (first raw text node) - (internal raw text node) + (internal raw text node) (last raw text node)