Permalink
Browse files

Flow strict TextProps (#22122)

Summary:
Related to #22100

Turn on Flow strict mode for TextProps.
I used ResponseHandlers type definition defined in Text.js.

I wanted to move ResponseHandlers type to TextProps and reuse it inside the file.
I know I could use $Shape<> to maybe keys but how do I elegantly maybe every values ?
Unless having a straightforward solution, I found it clearer to copy paste these types.

- All flow tests succeed.

[GENERAL] [ENHANCEMENT] [TextProps.js] - Flow strict mode
Pull Request resolved: #22122

Reviewed By: TheSavior

Differential Revision: D13055759

Pulled By: RSNara

fbshipit-source-id: 230b43c7c94d7f82f5727ad11541b0cb98bc5e3a
  • Loading branch information...
exced authored and facebook-github-bot committed Nov 21, 2018
1 parent 45c5183 commit 79274979b775e89d5f54a557a34062f873134199
Showing with 19 additions and 19 deletions.
  1. +12 −12 Libraries/Text/Text.js
  2. +7 −7 Libraries/Text/TextProps.js
@@ -27,10 +27,10 @@ import type {PressRetentionOffset, TextProps} from 'TextProps';

type ResponseHandlers = $ReadOnly<{|
onStartShouldSetResponder: () => boolean,
onResponderGrant: (event: SyntheticEvent<>, dispatchID: string) => void,
onResponderMove: (event: SyntheticEvent<>) => void,
onResponderRelease: (event: SyntheticEvent<>) => void,
onResponderTerminate: (event: SyntheticEvent<>) => void,
onResponderGrant: (event: PressEvent, dispatchID: string) => void,
onResponderMove: (event: PressEvent) => void,
onResponderRelease: (event: PressEvent) => void,
onResponderTerminate: (event: PressEvent) => void,
onResponderTerminationRequest: () => boolean,
|}>;

@@ -93,12 +93,12 @@ class TouchableText extends React.Component<Props, State> {
touchableHandleLongPress: ?(event: PressEvent) => void;
touchableHandlePress: ?(event: PressEvent) => void;
touchableHandleResponderGrant: ?(
event: SyntheticEvent<>,
event: PressEvent,
dispatchID: string,
) => void;
touchableHandleResponderMove: ?(event: SyntheticEvent<>) => void;
touchableHandleResponderRelease: ?(event: SyntheticEvent<>) => void;
touchableHandleResponderTerminate: ?(event: SyntheticEvent<>) => void;
touchableHandleResponderMove: ?(event: PressEvent) => void;
touchableHandleResponderRelease: ?(event: PressEvent) => void;
touchableHandleResponderTerminate: ?(event: PressEvent) => void;
touchableHandleResponderTerminationRequest: ?() => boolean;

state = {
@@ -173,25 +173,25 @@ class TouchableText extends React.Component<Props, State> {
}
return shouldSetResponder;
},
onResponderGrant: (event: SyntheticEvent<>, dispatchID: string): void => {
onResponderGrant: (event: PressEvent, dispatchID: string): void => {
nullthrows(this.touchableHandleResponderGrant)(event, dispatchID);
if (this.props.onResponderGrant != null) {
this.props.onResponderGrant.call(this, event, dispatchID);
}
},
onResponderMove: (event: SyntheticEvent<>): void => {
onResponderMove: (event: PressEvent): void => {
nullthrows(this.touchableHandleResponderMove)(event);
if (this.props.onResponderMove != null) {
this.props.onResponderMove.call(this, event);
}
},
onResponderRelease: (event: SyntheticEvent<>): void => {
onResponderRelease: (event: PressEvent): void => {
nullthrows(this.touchableHandleResponderRelease)(event);
if (this.props.onResponderRelease != null) {
this.props.onResponderRelease.call(this, event);
}
},
onResponderTerminate: (event: SyntheticEvent<>): void => {
onResponderTerminate: (event: PressEvent): void => {
nullthrows(this.touchableHandleResponderTerminate)(event);
if (this.props.onResponderTerminate != null) {
this.props.onResponderTerminate.call(this, event);
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
*/

@@ -106,12 +106,12 @@ export type TextProps = $ReadOnly<{
* See https://facebook.github.io/react-native/docs/text.html#onpress
*/
onPress?: ?(event: PressEvent) => mixed,
onResponderGrant?: ?Function,
onResponderMove?: ?Function,
onResponderRelease?: ?Function,
onResponderTerminate?: ?Function,
onResponderTerminationRequest?: ?Function,
onStartShouldSetResponder?: ?Function,
onResponderGrant?: ?(event: PressEvent, dispatchID: string) => void,
onResponderMove?: ?(event: PressEvent) => void,
onResponderRelease?: ?(event: PressEvent) => void,
onResponderTerminate?: ?(event: PressEvent) => void,
onResponderTerminationRequest?: ?() => boolean,
onStartShouldSetResponder?: ?() => boolean,
onTextLayout?: ?(event: TextLayoutEvent) => mixed,

/**

0 comments on commit 7927497

Please sign in to comment.