Skip to content

Commit

Permalink
Align TextInput types with TypeScript (#48972)
Browse files Browse the repository at this point in the history
Summary:

Changelog: [Internal]

Align TextInput types with TypeScript definitions.

Reviewed By: huntie

Differential Revision: D68713179
  • Loading branch information
j-piasecki authored and facebook-github-bot committed Jan 31, 2025
1 parent 7f7c735 commit 3bc793a
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,31 @@ type DataDetectorTypesType =
| 'all';

export type KeyboardType =
// Cross Platform
| 'default'
| 'email-address'
| 'numeric'
| 'phone-pad'
| 'number-pad'
| 'decimal-pad'
| 'url'
// iOS-only
| 'url';

export type KeyboardTypeIOS =
| 'ascii-capable'
| 'numbers-and-punctuation'
| 'name-phone-pad'
| 'twitter'
| 'web-search'
// iOS 10+ only
| 'ascii-capable-number-pad'
// Android-only
| 'visible-password';
| 'ascii-capable-number-pad';

export type KeyboardTypeAndroid = 'visible-password';

export type KeyboardTypeOptions =
| KeyboardType
| KeyboardTypeIOS
| KeyboardTypeAndroid;

export type InputMode =
export type InputModeOptions =
| 'none'
| 'text'
| 'decimal'
Expand All @@ -138,24 +143,23 @@ export type InputMode =
| 'email'
| 'url';

export type ReturnKeyType =
// Cross Platform
| 'done'
| 'go'
| 'next'
| 'search'
| 'send'
// Android-only
| 'none'
| 'previous'
// iOS-only
export type ReturnKeyType = 'done' | 'go' | 'next' | 'search' | 'send';

export type ReturnKeyTypeIOS =
| 'default'
| 'emergency-call'
| 'google'
| 'join'
| 'route'
| 'yahoo';

export type ReturnKeyTypeAndroid = 'none' | 'previous';

export type ReturnKeyTypeOptions =
| ReturnKeyType
| ReturnKeyTypeIOS
| ReturnKeyTypeAndroid;

export type SubmitBehavior = 'submit' | 'blurAndSubmit' | 'newline';

export type AutoCapitalize = 'none' | 'sentences' | 'words' | 'characters';
Expand Down Expand Up @@ -208,18 +212,20 @@ export type TextContentType =
| 'flightNumber'
| 'shipmentTrackingNumber';

export type enterKeyHintType =
| 'enter'
| 'done'
| 'go'
| 'next'
| 'previous'
| 'search'
| 'send';
export type EnterKeyHintTypeAndroid = 'previous';

export type EnterKeyHintTypeIOS = 'enter';

export type EnterKeyHintType = 'done' | 'go' | 'next' | 'search' | 'send';

export type EnterKeyHintTypeOptions =
| EnterKeyHintType
| EnterKeyHintTypeAndroid
| EnterKeyHintTypeIOS;

type PasswordRules = string;

type IOSProps = $ReadOnly<{
export type TextInputIOSProps = $ReadOnly<{
/**
* If true, the keyboard shortcuts (undo/redo and copy buttons) are disabled. The default value is false.
* @platform ios
Expand Down Expand Up @@ -356,7 +362,7 @@ type IOSProps = $ReadOnly<{
smartInsertDelete?: ?boolean,
}>;

type AndroidProps = $ReadOnly<{
export type TextInputAndroidProps = $ReadOnly<{
/**
* When provided it will set the color of the cursor (or "caret") in the component.
* Unlike the behavior of `selectionColor` the cursor color will be set independently
Expand Down Expand Up @@ -450,10 +456,10 @@ type AndroidProps = $ReadOnly<{
underlineColorAndroid?: ?ColorValue,
}>;

export type Props = $ReadOnly<{
export type TextInputProps = $ReadOnly<{
...$Diff<ViewProps, $ReadOnly<{style: ?ViewStyleProp}>>,
...IOSProps,
...AndroidProps,
...TextInputIOSProps,
...TextInputAndroidProps,

/**
* Can tell `TextInput` to automatically capitalize certain characters.
Expand Down Expand Up @@ -656,7 +662,7 @@ export type Props = $ReadOnly<{
* - `search`
* - `send`
*/
enterKeyHint?: ?enterKeyHintType,
enterKeyHint?: ?EnterKeyHintTypeOptions,

/**
* `inputMode` works like the `inputmode` attribute in HTML, it determines which
Expand All @@ -673,7 +679,7 @@ export type Props = $ReadOnly<{
* - `email`
* - `url`
*/
inputMode?: ?InputMode,
inputMode?: ?InputModeOptions,

/**
* Determines which keyboard to open, e.g.`numeric`.
Expand Down Expand Up @@ -705,7 +711,7 @@ export type Props = $ReadOnly<{
* - `visible-password`
*
*/
keyboardType?: ?KeyboardType,
keyboardType?: ?KeyboardTypeOptions,

/**
* Specifies largest possible scale a font can reach when `allowFontScaling` is enabled.
Expand Down Expand Up @@ -892,7 +898,7 @@ export type Props = $ReadOnly<{
* - `route`
* - `yahoo`
*/
returnKeyType?: ?ReturnKeyType,
returnKeyType?: ?ReturnKeyTypeOptions,

/**
* If `true`, the text input obscures the text entered so that sensitive text
Expand Down Expand Up @@ -1104,7 +1110,7 @@ type ImperativeMethods = $ReadOnly<{
*/
type InternalTextInput = component(
ref: React.RefSetter<$ReadOnly<{...HostInstance, ...ImperativeMethods}>>,
...Props
...TextInputProps
);

export type TextInputComponentStatics = $ReadOnly<{
Expand Down
85 changes: 44 additions & 41 deletions packages/react-native/Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,31 @@ type DataDetectorTypesType =
| 'all';

export type KeyboardType =
// Cross Platform
| 'default'
| 'email-address'
| 'numeric'
| 'phone-pad'
| 'number-pad'
| 'decimal-pad'
| 'url'
// iOS-only
| 'url';

export type KeyboardTypeIOS =
| 'ascii-capable'
| 'numbers-and-punctuation'
| 'name-phone-pad'
| 'twitter'
| 'web-search'
// iOS 10+ only
| 'ascii-capable-number-pad'
// Android-only
| 'visible-password';
| 'ascii-capable-number-pad';

export type KeyboardTypeAndroid = 'visible-password';

export type KeyboardTypeOptions =
| KeyboardType
| KeyboardTypeIOS
| KeyboardTypeAndroid;

export type InputMode =
export type InputModeOptions =
| 'none'
| 'text'
| 'decimal'
Expand All @@ -179,24 +184,23 @@ export type InputMode =
| 'email'
| 'url';

export type ReturnKeyType =
// Cross Platform
| 'done'
| 'go'
| 'next'
| 'search'
| 'send'
// Android-only
| 'none'
| 'previous'
// iOS-only
export type ReturnKeyType = 'done' | 'go' | 'next' | 'search' | 'send';

export type ReturnKeyTypeIOS =
| 'default'
| 'emergency-call'
| 'google'
| 'join'
| 'route'
| 'yahoo';

export type ReturnKeyTypeAndroid = 'none' | 'previous';

export type ReturnKeyTypeOptions =
| ReturnKeyType
| ReturnKeyTypeIOS
| ReturnKeyTypeAndroid;

export type SubmitBehavior = 'submit' | 'blurAndSubmit' | 'newline';

export type AutoCapitalize = 'none' | 'sentences' | 'words' | 'characters';
Expand Down Expand Up @@ -249,21 +253,20 @@ export type TextContentType =
| 'flightNumber'
| 'shipmentTrackingNumber';

export type enterKeyHintType =
// Cross Platform
| 'done'
| 'go'
| 'next'
| 'search'
| 'send'
// Android-only
| 'previous'
// iOS-only
| 'enter';
export type EnterKeyHintTypeAndroid = 'previous';

export type EnterKeyHintTypeIOS = 'enter';

export type EnterKeyHintType = 'done' | 'go' | 'next' | 'search' | 'send';

export type EnterKeyHintTypeOptions =
| EnterKeyHintType
| EnterKeyHintTypeAndroid
| EnterKeyHintTypeIOS;

type PasswordRules = string;

type IOSProps = $ReadOnly<{
export type TextInputIOSProps = $ReadOnly<{
/**
* If true, the keyboard shortcuts (undo/redo and copy buttons) are disabled. The default value is false.
* @platform ios
Expand Down Expand Up @@ -403,7 +406,7 @@ type IOSProps = $ReadOnly<{
smartInsertDelete?: ?boolean,
}>;

type AndroidProps = $ReadOnly<{
export type TextInputAndroidProps = $ReadOnly<{
/**
* When provided it will set the color of the cursor (or "caret") in the component.
* Unlike the behavior of `selectionColor` the cursor color will be set independently
Expand Down Expand Up @@ -489,10 +492,10 @@ type AndroidProps = $ReadOnly<{
underlineColorAndroid?: ?ColorValue,
}>;

export type Props = $ReadOnly<{
export type TextInputProps = $ReadOnly<{
...$Diff<ViewProps, $ReadOnly<{style: ?ViewStyleProp}>>,
...IOSProps,
...AndroidProps,
...TextInputIOSProps,
...TextInputAndroidProps,

/**
* Can tell `TextInput` to automatically capitalize certain characters.
Expand Down Expand Up @@ -695,7 +698,7 @@ export type Props = $ReadOnly<{
* - `search`
* - `send`
*/
enterKeyHint?: ?enterKeyHintType,
enterKeyHint?: ?EnterKeyHintTypeOptions,

/**
* `inputMode` works like the `inputmode` attribute in HTML, it determines which
Expand All @@ -712,7 +715,7 @@ export type Props = $ReadOnly<{
* - `email`
* - `url`
*/
inputMode?: ?InputMode,
inputMode?: ?InputModeOptions,

/**
* Determines which keyboard to open, e.g.`numeric`.
Expand Down Expand Up @@ -744,7 +747,7 @@ export type Props = $ReadOnly<{
* - `visible-password`
*
*/
keyboardType?: ?KeyboardType,
keyboardType?: ?KeyboardTypeOptions,

/**
* Specifies largest possible scale a font can reach when `allowFontScaling` is enabled.
Expand Down Expand Up @@ -895,7 +898,7 @@ export type Props = $ReadOnly<{
* - `route`
* - `yahoo`
*/
returnKeyType?: ?ReturnKeyType,
returnKeyType?: ?ReturnKeyTypeOptions,

/**
* If `true`, the text input obscures the text entered so that sensitive text
Expand Down Expand Up @@ -1019,7 +1022,7 @@ function useTextInputStateSynchronization_STATE({
text,
viewCommands,
}: {
props: Props,
props: TextInputProps,
mostRecentEventCount: number,
selection: ?Selection,
inputRef: React.RefObject<null | HostInstance>,
Expand Down Expand Up @@ -1100,7 +1103,7 @@ function useTextInputStateSynchronization_REFS({
text,
viewCommands,
}: {
props: Props,
props: TextInputProps,
mostRecentEventCount: number,
selection: ?Selection,
inputRef: React.RefObject<null | HostInstance>,
Expand Down Expand Up @@ -1286,7 +1289,7 @@ function useTextInputStateSynchronization_REFS({
* or control this param programmatically with native code.
*
*/
function InternalTextInput(props: Props): React.Node {
function InternalTextInput(props: TextInputProps): React.Node {
const {
'aria-busy': ariaBusy,
'aria-checked': ariaChecked,
Expand Down
Loading

0 comments on commit 3bc793a

Please sign in to comment.