Change TextInput onSelectionChange event data

This commit is contained in:
Alexaner T
2018-06-21 19:36:35 +03:00
parent 1f4ac4ec56
commit fa2e5a65a1
2 changed files with 27 additions and 3 deletions
+12 -1
View File
@@ -1095,6 +1095,17 @@ export interface TextInputScrollEventData {
contentOffset: { x: number; y: number; }
}
/**
* @see TextInputProps.onSelectionChange
*/
export interface TextInputSelectionChangeEventData {
selection: {
start: number;
end: number;
};
target: number;
}
/**
* @see https://facebook.github.io/react-native/docs/textinput.html#props
*/
@@ -1220,7 +1231,7 @@ export interface TextInputProps
/**
* Callback that is called when the text input selection is changed.
*/
onSelectionChange?: (event: { nativeEvent: { selection: { start: number; end: number }; target: number } }) => void;
onSelectionChange?: (e: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => void;
/**
* Callback that is called when the text input's submit button is pressed.
+15 -2
View File
@@ -56,7 +56,8 @@ import {
StatusBar,
NativeSyntheticEvent,
GestureResponderEvent,
TextInputScrollEventData
TextInputScrollEventData,
TextInputSelectionChangeEventData,
} from "react-native";
declare module "react-native" {
@@ -492,6 +493,14 @@ class TextInputTest extends React.Component<{}, {username: string}> {
testNativeSyntheticEvent(e);
}
handleOnSelectionChange = (e: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => {
testNativeSyntheticEvent(e);
console.log(`target: ${ e.nativeEvent.target }`);
console.log(`start: ${ e.nativeEvent.selection.start }`);
console.log(`end: ${ e.nativeEvent.selection.end }`);
}
render() {
return (
<View>
@@ -503,7 +512,7 @@ class TextInputTest extends React.Component<{}, {username: string}> {
onChangeText={this.handleUsernameChange}
/>
<TextInput
<TextInput
multiline
onScroll={this.onScroll}
/>
@@ -512,6 +521,10 @@ class TextInputTest extends React.Component<{}, {username: string}> {
onBlur={this.handleOnBlur}
onFocus={this.handleOnFocus}
/>
<TextInput
onSelectionChange={this.handleOnSelectionChange}
/>
</View>
);
}