Move onKeyPress from TextInputIOSProps to TextInputProps

This commit is contained in:
Alexader
2018-06-24 10:38:52 +03:00
parent e6b8a914b6
commit 184793074f
2 changed files with 31 additions and 7 deletions

View File

@@ -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
*/

View File

@@ -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>
);
}