Compare commits

...
Author SHA1 Message Date
Jakub PiaseckiandFacebook GitHub Bot 7f7c735797 Align TextInput event types with TypeScript (#48971)
Summary:

Changelog: [Internal]

Mosltly align event types of TextInput components with TypeScript definitions.

Reviewed By: mellyeliu, thatmichael85

Differential Revision: D68713180
2025-01-31 01:40:54 -08:00
5 changed files with 222 additions and 212 deletions
@@ -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
@@ -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') {
@@ -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<{
@@ -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 BlurEvent = TargetEvent;
export type FocusEvent = TargetEvent;
export type TargetEvent = $ReadOnly<{
target: number,
}>;
export type TextInputFocusEventData = 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'
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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 } } }`.
@@ -66,13 +66,13 @@ if (Platform.OS === 'android') {
require('./RCTMultilineTextInputNativeComponent').Commands;
}
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<{
@@ -87,52 +87,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 BlurEvent = TargetEvent;
export type FocusEvent = TargetEvent;
export type TargetEvent = $ReadOnly<{
target: number,
}>;
export type TextInputFocusEventData = 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,
}>,
>;
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'
@@ -766,12 +770,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,
/**
* Callback that is called when the text input's text changes.
@@ -786,17 +790,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.
@@ -805,7 +809,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,
/**
* Called when a single tap gesture is detected.
@@ -827,13 +831,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 } } }`.
@@ -1419,7 +1423,7 @@ function InternalTextInput(props: Props): React.Node {
const ref = useMergeRefs<TextInputInstance>(setLocalRef, props.forwardedRef);
const _onChange = (event: ChangeEvent) => {
const _onChange = (event: TextInputChangeEvent) => {
const currentText = event.nativeEvent.text;
props.onChange && props.onChange(event);
props.onChangeText && props.onChangeText(currentText);
@@ -1438,7 +1442,7 @@ function InternalTextInput(props: Props): React.Node {
setMostRecentEventCount(event.nativeEvent.eventCount);
};
const _onSelectionChange = (event: SelectionChangeEvent) => {
const _onSelectionChange = (event: TextInputSelectionChangeEvent) => {
props.onSelectionChange && props.onSelectionChange(event);
if (inputRef.current == null) {
@@ -1453,14 +1457,14 @@ function InternalTextInput(props: Props): React.Node {
});
};
const _onFocus = (event: FocusEvent) => {
const _onFocus = (event: TextInputFocusEvent) => {
TextInputState.focusInput(inputRef.current);
if (props.onFocus) {
props.onFocus(event);
}
};
const _onBlur = (event: BlurEvent) => {
const _onBlur = (event: TextInputBlurEvent) => {
TextInputState.blurInput(inputRef.current);
if (props.onBlur) {
props.onBlur(event);
@@ -271,12 +271,14 @@ export type ScrollEvent = SyntheticEvent<
export type BlurEvent = SyntheticEvent<
$ReadOnly<{
target: number,
...
}>,
>;
export type FocusEvent = SyntheticEvent<
$ReadOnly<{
target: number,
...
}>,
>;
@@ -2836,13 +2836,13 @@ declare export default HostComponent<NativeProps>;
`;
exports[`public API should not change unintentionally Libraries/Components/TextInput/InputAccessoryView.js 1`] = `
"type Props = $ReadOnly<{
"export type InputAccessoryViewProps = $ReadOnly<{
+children: React.Node,
nativeID?: ?string,
style?: ?ViewStyleProp,
backgroundColor?: ?ColorValue,
}>;
declare const InputAccessoryView: React.ComponentType<Props>;
declare const InputAccessoryView: React.ComponentType<InputAccessoryViewProps>;
declare export default typeof InputAccessoryView;
"
`;
@@ -2884,13 +2884,12 @@ exports[`public API should not change unintentionally Libraries/Components/TextI
"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<{
eventCount: number,
@@ -2903,46 +2902,45 @@ export type TextInputEvent = SyntheticEvent<
text: string,
}>,
>;
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 BlurEvent = TargetEvent;
export type FocusEvent = TargetEvent;
}>;
export type TextInputContentSizeChangeEvent =
SyntheticEvent<TextInputContentSizeChangeEventData>;
export type TargetEvent = $ReadOnly<{
target: number,
}>;
export type TextInputFocusEventData = 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 KeyPressEvent = SyntheticEvent<
$ReadOnly<{
key: string,
target?: ?number,
eventCount?: ?number,
}>,
>;
export type EditingEvent = SyntheticEvent<
$ReadOnly<{
eventCount: number,
text: string,
target: number,
}>,
>;
export type TextInputSelectionChangeEventData = $ReadOnly<{
...TargetEvent,
selection: Selection,
}>;
export type TextInputSelectionChangeEvent =
SyntheticEvent<TextInputSelectionChangeEventData>;
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\\"
| \\"link\\"
@@ -3174,21 +3172,21 @@ export type Props = $ReadOnly<{
maxFontSizeMultiplier?: ?number,
maxLength?: ?number,
multiline?: ?boolean,
onBlur?: ?(e: BlurEvent) => mixed,
onChange?: ?(e: ChangeEvent) => mixed,
unstable_onChangeSync?: ?(e: ChangeEvent) => mixed,
onBlur?: ?(e: TextInputBlurEvent) => mixed,
onChange?: ?(e: TextInputChangeEvent) => mixed,
unstable_onChangeSync?: ?(e: TextInputChangeEvent) => mixed,
onChangeText?: ?(text: string) => mixed,
unstable_onChangeTextSync?: ?(text: string) => mixed,
onContentSizeChange?: ?(e: ContentSizeChangeEvent) => mixed,
onEndEditing?: ?(e: EditingEvent) => mixed,
onFocus?: ?(e: FocusEvent) => mixed,
onKeyPress?: ?(e: KeyPressEvent) => mixed,
unstable_onKeyPressSync?: ?(e: KeyPressEvent) => mixed,
onContentSizeChange?: ?(e: TextInputContentSizeChangeEvent) => mixed,
onEndEditing?: ?(e: TextInputEditingEvent) => mixed,
onFocus?: ?(e: TextInputFocusEvent) => mixed,
onKeyPress?: ?(e: TextInputKeyPressEvent) => mixed,
unstable_onKeyPressSync?: ?(e: TextInputKeyPressEvent) => mixed,
onPress?: ?(event: PressEvent) => mixed,
onPressIn?: ?(event: PressEvent) => mixed,
onPressOut?: ?(event: PressEvent) => mixed,
onSelectionChange?: ?(e: SelectionChangeEvent) => mixed,
onSubmitEditing?: ?(e: EditingEvent) => mixed,
onSelectionChange?: ?(e: TextInputSelectionChangeEvent) => mixed,
onSubmitEditing?: ?(e: TextInputEditingEvent) => mixed,
onScroll?: ?(e: ScrollEvent) => mixed,
placeholder?: ?Stringish,
placeholderTextColor?: ?ColorValue,
@@ -3238,13 +3236,12 @@ type TextInputInstance = HostInstance & {
+getNativeRef: () => ?HostInstance,
+setSelection: (start: number, end: number) => void,
};
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<{
eventCount: number,
@@ -3257,46 +3254,45 @@ export type TextInputEvent = SyntheticEvent<
text: string,
}>,
>;
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 BlurEvent = TargetEvent;
export type FocusEvent = TargetEvent;
}>;
export type TextInputContentSizeChangeEvent =
SyntheticEvent<TextInputContentSizeChangeEventData>;
export type TargetEvent = $ReadOnly<{
target: number,
}>;
export type TextInputFocusEventData = 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 KeyPressEvent = SyntheticEvent<
$ReadOnly<{
key: string,
target?: ?number,
eventCount?: ?number,
}>,
>;
export type EditingEvent = SyntheticEvent<
$ReadOnly<{
eventCount: number,
text: string,
target: number,
}>,
>;
export type TextInputSelectionChangeEventData = $ReadOnly<{
...TargetEvent,
selection: Selection,
}>;
export type TextInputSelectionChangeEvent =
SyntheticEvent<TextInputSelectionChangeEventData>;
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\\"
| \\"link\\"
@@ -3527,18 +3523,18 @@ export type Props = $ReadOnly<{
maxFontSizeMultiplier?: ?number,
maxLength?: ?number,
multiline?: ?boolean,
onBlur?: ?(e: BlurEvent) => mixed,
onChange?: ?(e: ChangeEvent) => mixed,
onBlur?: ?(e: TextInputBlurEvent) => mixed,
onChange?: ?(e: TextInputChangeEvent) => mixed,
onChangeText?: ?(text: string) => mixed,
onContentSizeChange?: ?(e: ContentSizeChangeEvent) => mixed,
onEndEditing?: ?(e: EditingEvent) => mixed,
onFocus?: ?(e: FocusEvent) => mixed,
onKeyPress?: ?(e: KeyPressEvent) => mixed,
onContentSizeChange?: ?(e: TextInputContentSizeChangeEvent) => mixed,
onEndEditing?: ?(e: TextInputEditingEvent) => mixed,
onFocus?: ?(e: TextInputFocusEvent) => mixed,
onKeyPress?: ?(e: TextInputKeyPressEvent) => mixed,
onPress?: ?(event: PressEvent) => mixed,
onPressIn?: ?(event: PressEvent) => mixed,
onPressOut?: ?(event: PressEvent) => mixed,
onSelectionChange?: ?(e: SelectionChangeEvent) => mixed,
onSubmitEditing?: ?(e: EditingEvent) => mixed,
onSelectionChange?: ?(e: TextInputSelectionChangeEvent) => mixed,
onSubmitEditing?: ?(e: TextInputEditingEvent) => mixed,
onScroll?: ?(e: ScrollEvent) => mixed,
placeholder?: ?Stringish,
placeholderTextColor?: ?ColorValue,
@@ -8590,11 +8586,13 @@ export type ScrollEvent = SyntheticEvent<
export type BlurEvent = SyntheticEvent<
$ReadOnly<{
target: number,
...
}>,
>;
export type FocusEvent = SyntheticEvent<
$ReadOnly<{
target: number,
...
}>,
>;
export type MouseEvent = SyntheticEvent<