mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-27 14:30:49 +08:00
Move onKeyPress from TextInputIOSProps to TextInputProps
This commit is contained in:
28
types/react-native/index.d.ts
vendored
28
types/react-native/index.d.ts
vendored
@@ -999,13 +999,6 @@ export interface TextInputIOSProps {
|
||||
*/
|
||||
keyboardAppearance?: "default" | "light" | "dark";
|
||||
|
||||
/**
|
||||
* Callback that is called when a key is pressed.
|
||||
* Pressed key value is passed as an argument to the callback handler.
|
||||
* Fires before onChange callbacks.
|
||||
*/
|
||||
onKeyPress?: (event: {nativeEvent: {key: string}}) => void;
|
||||
|
||||
/**
|
||||
* See DocumentSelectionState.js, some state that is responsible for maintaining selection information for a document
|
||||
*/
|
||||
@@ -1082,6 +1075,9 @@ export type ReturnKeyTypeAndroid = "none" | "previous";
|
||||
export type ReturnKeyTypeIOS = "default" | "google" | "join" | "route" | "yahoo" | "emergency-call";
|
||||
export type ReturnKeyTypeOptions = ReturnKeyType | ReturnKeyTypeAndroid | ReturnKeyTypeIOS;
|
||||
|
||||
/**
|
||||
* @see TextInputProps.onFocus
|
||||
*/
|
||||
export interface TextInputFocusEventData {
|
||||
target: number;
|
||||
text: string;
|
||||
@@ -1106,6 +1102,13 @@ export interface TextInputSelectionChangeEventData {
|
||||
target: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TextInputProps.onKeyPress
|
||||
*/
|
||||
export interface TextInputKeyPressEventData {
|
||||
key: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://facebook.github.io/react-native/docs/textinput.html#props
|
||||
*/
|
||||
@@ -1246,6 +1249,17 @@ export interface TextInputProps
|
||||
*/
|
||||
onScroll?: (e: NativeSyntheticEvent<TextInputScrollEventData>) => void;
|
||||
|
||||
/**
|
||||
* Callback that is called when a key is pressed.
|
||||
* This will be called with
|
||||
* `{ nativeEvent: { key: keyValue } }`
|
||||
* where keyValue is 'Enter' or 'Backspace' for respective keys and the typed-in character otherwise including ' ' for space.
|
||||
*
|
||||
* Fires before onChange callbacks.
|
||||
* Note: on Android only the inputs from soft keyboard are handled, not the hardware keyboard inputs.
|
||||
*/
|
||||
onKeyPress?: (e: NativeSyntheticEvent<TextInputKeyPressEventData>) => void;
|
||||
|
||||
/**
|
||||
* The string that will be rendered before text input has been entered
|
||||
*/
|
||||
|
||||
@@ -58,6 +58,7 @@ import {
|
||||
GestureResponderEvent,
|
||||
TextInputScrollEventData,
|
||||
TextInputSelectionChangeEventData,
|
||||
TextInputKeyPressEventData,
|
||||
} from "react-native";
|
||||
|
||||
declare module "react-native" {
|
||||
@@ -501,6 +502,11 @@ class TextInputTest extends React.Component<{}, {username: string}> {
|
||||
console.log(`end: ${ e.nativeEvent.selection.end }`);
|
||||
}
|
||||
|
||||
handleOnKeyPress = (e: NativeSyntheticEvent<TextInputKeyPressEventData>) => {
|
||||
testNativeSyntheticEvent(e);
|
||||
console.log(`key: ${ e.nativeEvent.key }`);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View>
|
||||
@@ -525,6 +531,10 @@ class TextInputTest extends React.Component<{}, {username: string}> {
|
||||
<TextInput
|
||||
onSelectionChange={this.handleOnSelectionChange}
|
||||
/>
|
||||
|
||||
<TextInput
|
||||
onKeyPress={this.handleOnKeyPress}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user