Skip to content

Commit

Permalink
Improve Flow types
Browse files Browse the repository at this point in the history
Summary:
Some of the flow types were incomplete. So, I referenced the code in  `~/fbsource/xplat/js/react-native-github/ReactAndroid/src/main/java/com/facebook/react/views/textinput/` and in `~/fbsource/xplat/js/react-native-github/Libraries/Text/TextInput/` to make the flow types more specific.

I also fixed internal breakages. To avoid having to sprinkle `$FlowFixMe`s everywhere, I had to refactor some types, and some code.

Reviewed By: TheSavior

Differential Revision: D13121871

fbshipit-source-id: 9796aafc861544baf52d7ade823ab1be2d3f12d1
  • Loading branch information
RSNara authored and facebook-github-bot committed Nov 21, 2018
1 parent 35a65cd commit da0b139
Showing 1 changed file with 39 additions and 36 deletions.
75 changes: 39 additions & 36 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const warning = require('fbjs/lib/warning');
import type {TextStyleProp, ViewStyleProp} from 'StyleSheet';
import type {ColorValue} from 'StyleSheetTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {SyntheticEvent} from 'CoreEventTypes';
import type {SyntheticEvent, ScrollEvent} from 'CoreEventTypes';
import type {PressEvent} from 'CoreEventTypes';

let AndroidTextInput;
Expand All @@ -57,66 +57,69 @@ const onlyMultiline = {
children: true,
};

type Range = $ReadOnly<{|
start: number,
end: number,
|}>;
type Selection = $ReadOnly<{|
start: number,
end?: number,
|}>;
type ContentSize = $ReadOnly<{|
width: number,
height: number,
|}>;
type ContentOffset = $ReadOnly<{|
x: number,
y: number,
|}>;
type ChangeEvent = SyntheticEvent<
export type ChangeEvent = SyntheticEvent<
$ReadOnly<{|
target: number,
eventCount: number,
target: number,
text: string,
|}>,
>;
type TextInputEvent = SyntheticEvent<

export type TextInputEvent = SyntheticEvent<
$ReadOnly<{|
eventCount: number,
previousText: string,
range: Range,
range: $ReadOnly<{|
start: number,
end: number,
|}>,
target: number,
text: string,
|}>,
>;
type ContentSizeChangeEvent = SyntheticEvent<
$ReadOnly<{|
target: number,
contentSize: ContentSize,
|}>,
>;
type ScrollEvent = SyntheticEvent<

export type ContentSizeChangeEvent = SyntheticEvent<
$ReadOnly<{|
target: number,
contentOffset: ContentOffset,
contentSize: $ReadOnly<{|
width: number,
height: number,
|}>,
|}>,
>;

type TargetEvent = SyntheticEvent<
$ReadOnly<{|
target: number,
|}>,
>;
type SelectionChangeEvent = SyntheticEvent<

export type BlurEvent = TargetEvent;
export type FocusEvent = TargetEvent;

type Selection = $ReadOnly<{|
start: number,
end: number,
|}>;

export type SelectionChangeEvent = SyntheticEvent<
$ReadOnly<{|
selection: Selection,
target: number,
|}>,
>;
type KeyPressEvent = SyntheticEvent<

export type KeyPressEvent = SyntheticEvent<
$ReadOnly<{|
key: string,
target?: ?number,
eventCount?: ?number,
|}>,
>;
type EditingEvent = SyntheticEvent<

export type EditingEvent = SyntheticEvent<
$ReadOnly<{|
eventCount: number,
text: string,
target: number,
|}>,
Expand Down Expand Up @@ -245,8 +248,8 @@ type Props = $ReadOnly<{|
returnKeyType?: ?ReturnKeyType,
maxLength?: ?number,
multiline?: ?boolean,
onBlur?: ?(e: TargetEvent) => void,
onFocus?: ?(e: TargetEvent) => void,
onBlur?: ?(e: BlurEvent) => void,
onFocus?: ?(e: FocusEvent) => void,
onChange?: ?(e: ChangeEvent) => void,
onChangeText?: ?(text: string) => void,
onContentSizeChange?: ?(e: ContentSizeChangeEvent) => void,
Expand Down Expand Up @@ -1169,7 +1172,7 @@ const TextInput = createReactClass({
);
},

_onFocus: function(event: TargetEvent) {
_onFocus: function(event: FocusEvent) {
if (this.props.onFocus) {
this.props.onFocus(event);
}
Expand Down Expand Up @@ -1262,7 +1265,7 @@ const TextInput = createReactClass({
}
},

_onBlur: function(event: TargetEvent) {
_onBlur: function(event: BlurEvent) {
if (this.props.onBlur) {
this.props.onBlur(event);
}
Expand Down

0 comments on commit da0b139

Please sign in to comment.