Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align TextInput event types with TypeScript #48971

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import * as React from 'react';
* For an example, look at InputAccessoryViewExample.js in RNTester.
*/

type Props = $ReadOnly<{
export type InputAccessoryViewProps = $ReadOnly<{
+children: React.Node,
/**
* An ID which is used to associate this `InputAccessoryView` to
Expand All @@ -87,7 +87,9 @@ type Props = $ReadOnly<{
backgroundColor?: ?ColorValue,
}>;

const InputAccessoryView: React.ComponentType<Props> = (props: Props) => {
const InputAccessoryView: React.ComponentType<InputAccessoryViewProps> = (
props: InputAccessoryViewProps,
) => {
const {width} = useWindowDimensions();

if (Platform.OS === 'ios') {
Expand Down
108 changes: 56 additions & 52 deletions packages/react-native/Libraries/Components/TextInput/TextInput.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import * as React from 'react';

type ReactRefSetter<T> = {current: null | T, ...} | ((ref: null | T) => mixed);

export type ChangeEvent = SyntheticEvent<
$ReadOnly<{
eventCount: number,
target: number,
text: string,
}>,
>;
export type TextInputChangeEventData = $ReadOnly<{
eventCount: number,
target: number,
text: string,
}>;

export type TextInputChangeEvent = SyntheticEvent<TextInputChangeEventData>;

export type TextInputEvent = SyntheticEvent<
$ReadOnly<{
Expand All @@ -46,52 +46,56 @@ export type TextInputEvent = SyntheticEvent<
}>,
>;

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

type TargetEvent = SyntheticEvent<
$ReadOnly<{
target: number,
}>,
>;
export type TextInputContentSizeChangeEvent =
SyntheticEvent<TextInputContentSizeChangeEventData>;

export type TargetEvent = $ReadOnly<{
target: number,
}>;

export type TextInputFocusEventData = TargetEvent;

export type BlurEvent = TargetEvent;
export type FocusEvent = TargetEvent;
export type TextInputBlurEvent = SyntheticEvent<TextInputFocusEventData>;
export type TextInputFocusEvent = SyntheticEvent<TextInputFocusEventData>;

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

export type SelectionChangeEvent = SyntheticEvent<
$ReadOnly<{
selection: Selection,
target: number,
}>,
>;
export type TextInputSelectionChangeEventData = $ReadOnly<{
...TargetEvent,
selection: Selection,
}>;

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

export type EditingEvent = SyntheticEvent<
$ReadOnly<{
eventCount: number,
text: string,
target: number,
}>,
>;
export type TextInputKeyPressEventData = $ReadOnly<{
...TargetEvent,
key: string,
target?: ?number,
eventCount: number,
}>;

export type TextInputKeyPressEvent = SyntheticEvent<TextInputKeyPressEventData>;

export type TextInputEndEditingEventData = $ReadOnly<{
...TargetEvent,
eventCount: number,
text: string,
}>;

export type TextInputEditingEvent =
SyntheticEvent<TextInputEndEditingEventData>;

type DataDetectorTypesType =
| 'phoneNumber'
Expand Down Expand Up @@ -727,12 +731,12 @@ export type Props = $ReadOnly<{
/**
* Callback that is called when the text input is blurred.
*/
onBlur?: ?(e: BlurEvent) => mixed,
onBlur?: ?(e: TextInputBlurEvent) => mixed,

/**
* Callback that is called when the text input's text changes.
*/
onChange?: ?(e: ChangeEvent) => mixed,
onChange?: ?(e: TextInputChangeEvent) => mixed,

/**
* DANGER: this API is not stable and will change in the future.
Expand All @@ -742,7 +746,7 @@ export type Props = $ReadOnly<{
*
* @platform ios
*/
unstable_onChangeSync?: ?(e: ChangeEvent) => mixed,
unstable_onChangeSync?: ?(e: TextInputChangeEvent) => mixed,

/**
* Callback that is called when the text input's text changes.
Expand All @@ -768,17 +772,17 @@ export type Props = $ReadOnly<{
*
* Only called for multiline text inputs.
*/
onContentSizeChange?: ?(e: ContentSizeChangeEvent) => mixed,
onContentSizeChange?: ?(e: TextInputContentSizeChangeEvent) => mixed,

/**
* Callback that is called when text input ends.
*/
onEndEditing?: ?(e: EditingEvent) => mixed,
onEndEditing?: ?(e: TextInputEditingEvent) => mixed,

/**
* Callback that is called when the text input is focused.
*/
onFocus?: ?(e: FocusEvent) => mixed,
onFocus?: ?(e: TextInputFocusEvent) => mixed,

/**
* Callback that is called when a key is pressed.
Expand All @@ -787,7 +791,7 @@ export type Props = $ReadOnly<{
* the typed-in character otherwise including `' '` for space.
* Fires before `onChange` callbacks.
*/
onKeyPress?: ?(e: KeyPressEvent) => mixed,
onKeyPress?: ?(e: TextInputKeyPressEvent) => mixed,

/**
* DANGER: this API is not stable and will change in the future.
Expand All @@ -802,7 +806,7 @@ export type Props = $ReadOnly<{
*
* @platform ios
*/
unstable_onKeyPressSync?: ?(e: KeyPressEvent) => mixed,
unstable_onKeyPressSync?: ?(e: TextInputKeyPressEvent) => mixed,

/**
* Called when a single tap gesture is detected.
Expand All @@ -824,13 +828,13 @@ export type Props = $ReadOnly<{
* This will be called with
* `{ nativeEvent: { selection: { start, end } } }`.
*/
onSelectionChange?: ?(e: SelectionChangeEvent) => mixed,
onSelectionChange?: ?(e: TextInputSelectionChangeEvent) => mixed,

/**
* Callback that is called when the text input's submit button is pressed.
* Invalid if `multiline={true}` is specified.
*/
onSubmitEditing?: ?(e: EditingEvent) => mixed,
onSubmitEditing?: ?(e: TextInputEditingEvent) => mixed,

/**
* Invoked on content scroll with `{ nativeEvent: { contentOffset: { x, y } } }`.
Expand Down
Loading
Loading