Skip to content

Commit

Permalink
Refactor TextInput to use new types
Browse files Browse the repository at this point in the history
  • Loading branch information
Saadnajmi committed Aug 2, 2024
1 parent f34c080 commit b5f9c54
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
import {ColorValue, StyleProp} from '../../StyleSheet/StyleSheet';
import {TextStyle} from '../../StyleSheet/StyleSheetTypes';
import {
NativeBlurEvent,
NativeFocusEvent,
NativeSyntheticEvent,
NativeTouchEvent,
TargetedEvent,
Expand Down Expand Up @@ -426,10 +428,18 @@ export interface TextInputAndroidProps {
verticalAlign?: 'auto' | 'top' | 'bottom' | 'middle' | undefined;
}

/**
* @see TextInputProps.onBlur
*/
export interface TextInputBlurEventData extends NativeBlurEvent {
text: string;
eventCount: number;
}

/**
* @see TextInputProps.onFocus
*/
export interface TextInputFocusEventData extends TargetedEvent {
export interface TextInputFocusEventData extends NativeFocusEvent {
text: string;
eventCount: number;
}
Expand Down Expand Up @@ -736,7 +746,7 @@ export interface TextInputProps
* Callback that is called when the text input is blurred
*/
onBlur?:
| ((e: NativeSyntheticEvent<TextInputFocusEventData>) => void)
| ((e: NativeSyntheticEvent<TextInputBlurEventData>) => void)
| undefined;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
import type {
BlurEvent,
FocusEvent,
PressEvent,
ScrollEvent,
SyntheticEvent,
Expand Down Expand Up @@ -96,15 +98,6 @@ export type ContentSizeChangeEvent = SyntheticEvent<
|}>,
>;

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

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

type Selection = $ReadOnly<{|
start: number,
end: number,
Expand Down
9 changes: 3 additions & 6 deletions packages/react-native/Libraries/Types/CoreEventTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,17 +270,14 @@ export type ScrollEvent = SyntheticEvent<
|}>,
>;

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

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

export type MouseEvent = SyntheticEvent<
$ReadOnly<{|
Expand Down

0 comments on commit b5f9c54

Please sign in to comment.