Skip to content

Commit 701859b

Browse files
huntiefacebook-github-bot
authored andcommitted
Deprecate *EventData types in favour of *Event (facebook#50215)
Summary: Pull Request resolved: facebook#50215 Backwards compatible updates to `CoreEventTypes`, `Image`, `Switch`, `TextInput` to align types and reduce root exports. The effects of this change can be seen in `packages/react-native/types/__typetests__/index.tsx` (smoke test file against current manual TypeScript definitions). Under Flow, exports on each `*EventData` type are directly removed (unreferenced). Changelog: [General][Deprecated] - Deprecate `*EventData` types on `Image`, `Switch`, `TextInput` components. These can be substituted for `*Event`, e.g. `NativeSyntheticEvent<ImageLoadEventData>` becomes `ImageLoadEvent`. Reviewed By: NickGerleman Differential Revision: D71734361 fbshipit-source-id: 287c775e840319242984d248169c267abf8f032b
1 parent 4b82896 commit 701859b

File tree

13 files changed

+229
-172
lines changed

13 files changed

+229
-172
lines changed

packages/react-native/Libraries/Components/Switch/Switch.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export interface SwitchPropsIOS extends ViewProps {
3838
tintColor?: ColorValue | undefined;
3939
}
4040

41+
/**
42+
* @deprecated Use `SwitchChangeEvent` instead.
43+
*/
4144
export interface SwitchChangeEventData extends TargetedEvent {
4245
value: boolean;
4346
}

packages/react-native/Libraries/Components/Switch/Switch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export type SwitchPropsIOS = {
4646
tintColor?: ?ColorValue,
4747
};
4848

49-
export type SwitchChangeEventData = $ReadOnly<{
49+
type SwitchChangeEventData = $ReadOnly<{
5050
target: number,
5151
value: boolean,
5252
}>;

packages/react-native/Libraries/Components/TextInput/TextInput.d.ts

Lines changed: 64 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -455,22 +455,33 @@ export interface TextInputAndroidProps {
455455
}
456456

457457
/**
458-
* @see TextInputProps.onFocus
458+
* @deprecated Use `TextInputFocusEvent` instead
459459
*/
460460
export interface TextInputFocusEventData extends TargetedEvent {
461461
text: string;
462462
eventCount: number;
463463
}
464464

465465
/**
466-
* @see TextInputProps.onScroll
466+
* @see TextInputProps.onFocus
467+
*/
468+
export type TextInputFocusEvent = NativeSyntheticEvent<TextInputFocusEventData>;
469+
470+
/**
471+
* @deprecated Use `TextInputScrollEvent` instead
467472
*/
468473
export interface TextInputScrollEventData {
469474
contentOffset: {x: number; y: number};
470475
}
471476

472477
/**
473-
* @see TextInputProps.onSelectionChange
478+
* @see TextInputProps.onScroll
479+
*/
480+
export type TextInputScrollEvent =
481+
NativeSyntheticEvent<TextInputScrollEventData>;
482+
483+
/**
484+
* @deprecated Use `TextInputSelectionChangeEvent` instead
474485
*/
475486
export interface TextInputSelectionChangeEventData extends TargetedEvent {
476487
selection: {
@@ -480,41 +491,77 @@ export interface TextInputSelectionChangeEventData extends TargetedEvent {
480491
}
481492

482493
/**
483-
* @see TextInputProps.onKeyPress
494+
* @see TextInputProps.onSelectionChange
495+
*/
496+
export type TextInputSelectionChangeEvent =
497+
NativeSyntheticEvent<TextInputSelectionChangeEventData>;
498+
499+
/**
500+
* @deprecated Use `TextInputKeyPressEvent` instead
484501
*/
485502
export interface TextInputKeyPressEventData {
486503
key: string;
487504
}
488505

489506
/**
490-
* @see TextInputProps.onChange
507+
* @see TextInputProps.onKeyPress
508+
*/
509+
export type TextInputKeyPressEvent =
510+
NativeSyntheticEvent<TextInputKeyPressEventData>;
511+
512+
/**
513+
* @deprecated Use `TextInputChangeEvent` instead
491514
*/
492515
export interface TextInputChangeEventData extends TargetedEvent {
493516
eventCount: number;
494517
text: string;
495518
}
496519

497520
/**
498-
* @see TextInputProps.onContentSizeChange
521+
* @see TextInputProps.onChange
522+
*/
523+
export type TextInputChangeEvent =
524+
NativeSyntheticEvent<TextInputChangeEventData>;
525+
526+
/**
527+
* @deprecated Use `TextInputContentSizeChangeEvent` instead
499528
*/
500529
export interface TextInputContentSizeChangeEventData {
501530
contentSize: {width: number; height: number};
502531
}
503532

504533
/**
505-
* @see TextInputProps.onEndEditing
534+
* @see TextInputProps.onContentSizeChange
535+
*/
536+
export type TextInputContentSizeChangeEvent =
537+
NativeSyntheticEvent<TextInputContentSizeChangeEventData>;
538+
539+
/**
540+
* @deprecated Use `TextInputEndEditingEvent` instead
506541
*/
507542
export interface TextInputEndEditingEventData {
508543
text: string;
509544
}
510545

511546
/**
512-
* @see TextInputProps.onSubmitEditing
547+
* @see TextInputProps.onEndEditing
548+
*/
549+
export type TextInputEndEditingEvent =
550+
NativeSyntheticEvent<TextInputEndEditingEventData>;
551+
552+
/**
553+
* @deprecated Use `TextInputSubmitEditingEvent` instead
513554
*/
514555
export interface TextInputSubmitEditingEventData {
515556
text: string;
516557
}
517558

559+
/**
560+
* @see TextInputProps.onSubmitEditing
561+
*/
562+
export type TextInputSubmitEditingEvent =
563+
NativeSyntheticEvent<TextInputSubmitEditingEventData>;
564+
518565
/**
519566
* @see https://reactnative.dev/docs/textinput#props
520567
*/
@@ -763,16 +810,12 @@ export interface TextInputProps
763810
/**
764811
* Callback that is called when the text input is blurred
765812
*/
766-
onBlur?:
767-
| ((e: NativeSyntheticEvent<TextInputFocusEventData>) => void)
768-
| undefined;
813+
onBlur?: ((e: TextInputFocusEvent) => void) | undefined;
769814

770815
/**
771816
* Callback that is called when the text input's text changes.
772817
*/
773-
onChange?:
774-
| ((e: NativeSyntheticEvent<TextInputChangeEventData>) => void)
775-
| undefined;
818+
onChange?: ((e: TextInputChangeEvent) => void) | undefined;
776819

777820
/**
778821
* Callback that is called when the text input's text changes.
@@ -788,15 +831,13 @@ export interface TextInputProps
788831
* Only called for multiline text inputs.
789832
*/
790833
onContentSizeChange?:
791-
| ((e: NativeSyntheticEvent<TextInputContentSizeChangeEventData>) => void)
834+
| ((e: TextInputContentSizeChangeEvent) => void)
792835
| undefined;
793836

794837
/**
795838
* Callback that is called when text input ends.
796839
*/
797-
onEndEditing?:
798-
| ((e: NativeSyntheticEvent<TextInputEndEditingEventData>) => void)
799-
| undefined;
840+
onEndEditing?: ((e: TextInputEndEditingEvent) => void) | undefined;
800841

801842
/**
802843
* Called when a single tap gesture is detected.
@@ -818,33 +859,25 @@ export interface TextInputProps
818859
/**
819860
* Callback that is called when the text input is focused
820861
*/
821-
onFocus?:
822-
| ((e: NativeSyntheticEvent<TextInputFocusEventData>) => void)
823-
| undefined;
862+
onFocus?: ((e: TextInputFocusEvent) => void) | undefined;
824863

825864
/**
826865
* Callback that is called when the text input selection is changed.
827866
*/
828-
onSelectionChange?:
829-
| ((e: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => void)
830-
| undefined;
867+
onSelectionChange?: ((e: TextInputSelectionChangeEvent) => void) | undefined;
831868

832869
/**
833870
* Callback that is called when the text input's submit button is pressed.
834871
*/
835-
onSubmitEditing?:
836-
| ((e: NativeSyntheticEvent<TextInputSubmitEditingEventData>) => void)
837-
| undefined;
872+
onSubmitEditing?: ((e: TextInputSubmitEditingEvent) => void) | undefined;
838873

839874
/**
840875
* Invoked on content scroll with
841876
* `{ nativeEvent: { contentOffset: { x, y } } }`.
842877
*
843878
* May also contain other properties from ScrollEvent but on Android contentSize is not provided for performance reasons.
844879
*/
845-
onScroll?:
846-
| ((e: NativeSyntheticEvent<TextInputScrollEventData>) => void)
847-
| undefined;
880+
onScroll?: ((e: TextInputScrollEvent) => void) | undefined;
848881

849882
/**
850883
* Callback that is called when a key is pressed.
@@ -855,9 +888,7 @@ export interface TextInputProps
855888
* Fires before onChange callbacks.
856889
* Note: on Android only the inputs from soft keyboard are handled, not the hardware keyboard inputs.
857890
*/
858-
onKeyPress?:
859-
| ((e: NativeSyntheticEvent<TextInputKeyPressEventData>) => void)
860-
| undefined;
891+
onKeyPress?: ((e: TextInputKeyPressEvent) => void) | undefined;
861892

862893
/**
863894
* The string that will be rendered before text input has been entered

packages/react-native/Libraries/Components/TextInput/TextInput.flow.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ import {
2323
} from '../../StyleSheet/StyleSheet';
2424
import * as React from 'react';
2525

26-
export type TextInputChangeEventData = $ReadOnly<{
26+
type TextInputChangeEventData = $ReadOnly<{
2727
eventCount: number,
2828
target: number,
2929
text: string,
3030
}>;
3131

32-
export type TextInputChangeEvent =
33-
NativeSyntheticEvent<TextInputChangeEventData>;
32+
type TextInputChangeEvent = NativeSyntheticEvent<TextInputChangeEventData>;
3433

3534
export type TextInputEvent = NativeSyntheticEvent<
3635
$ReadOnly<{
@@ -45,7 +44,7 @@ export type TextInputEvent = NativeSyntheticEvent<
4544
}>,
4645
>;
4746

48-
export type TextInputContentSizeChangeEventData = $ReadOnly<{
47+
type TextInputContentSizeChangeEventData = $ReadOnly<{
4948
target: number,
5049
contentSize: $ReadOnly<{
5150
width: number,
@@ -56,11 +55,11 @@ export type TextInputContentSizeChangeEventData = $ReadOnly<{
5655
export type TextInputContentSizeChangeEvent =
5756
NativeSyntheticEvent<TextInputContentSizeChangeEventData>;
5857

59-
export type TargetEvent = $ReadOnly<{
58+
type TargetEvent = $ReadOnly<{
6059
target: number,
6160
}>;
6261

63-
export type TextInputFocusEventData = TargetEvent;
62+
type TextInputFocusEventData = TargetEvent;
6463

6564
export type TextInputBlurEvent = NativeSyntheticEvent<TextInputFocusEventData>;
6665
export type TextInputFocusEvent = NativeSyntheticEvent<TextInputFocusEventData>;
@@ -70,15 +69,15 @@ type Selection = $ReadOnly<{
7069
end: number,
7170
}>;
7271

73-
export type TextInputSelectionChangeEventData = $ReadOnly<{
72+
type TextInputSelectionChangeEventData = $ReadOnly<{
7473
...TargetEvent,
7574
selection: Selection,
7675
}>;
7776

7877
export type TextInputSelectionChangeEvent =
7978
NativeSyntheticEvent<TextInputSelectionChangeEventData>;
8079

81-
export type TextInputKeyPressEventData = $ReadOnly<{
80+
type TextInputKeyPressEventData = $ReadOnly<{
8281
...TargetEvent,
8382
key: string,
8483
target?: ?number,
@@ -88,27 +87,27 @@ export type TextInputKeyPressEventData = $ReadOnly<{
8887
export type TextInputKeyPressEvent =
8988
NativeSyntheticEvent<TextInputKeyPressEventData>;
9089

91-
/**
92-
* @see TextInputProps.onEndEditing
93-
*/
94-
export type TextInputEndEditingEventData = $ReadOnly<{
90+
type TextInputEndEditingEventData = $ReadOnly<{
9591
...TargetEvent,
9692
eventCount: number,
9793
text: string,
9894
}>;
9995

96+
/**
97+
* @see TextInputProps.onEndEditing
98+
*/
10099
export type TextInputEndEditingEvent =
101100
NativeSyntheticEvent<TextInputEndEditingEventData>;
102101

103-
/**
104-
* @see TextInputProps.onSubmitEditing
105-
*/
106-
export type TextInputSubmitEditingEventData = $ReadOnly<{
102+
type TextInputSubmitEditingEventData = $ReadOnly<{
107103
...TargetEvent,
108104
eventCount: number,
109105
text: string,
110106
}>;
111107

108+
/**
109+
* @see TextInputProps.onSubmitEditing
110+
*/
112111
export type TextInputSubmitEditingEvent =
113112
NativeSyntheticEvent<TextInputSubmitEditingEventData>;
114113

0 commit comments

Comments
 (0)