From e02a423e30ff3baa3eb334aa22b82dea8119079b Mon Sep 17 00:00:00 2001 From: Shane Fitzpatrick Date: Tue, 5 Jun 2018 09:50:28 -0700 Subject: [PATCH 1/2] react-native: Add event for TextInput onFocus and onBlur --- types/react-native/index.d.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index ef574ec807..eaa2dcccfc 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -1078,6 +1078,12 @@ export type ReturnKeyTypeAndroid = "none" | "previous"; export type ReturnKeyTypeIOS = "default" | "google" | "join" | "route" | "yahoo" | "emergency-call"; export type ReturnKeyTypeOptions = ReturnKeyType | ReturnKeyTypeAndroid | ReturnKeyTypeIOS +export interface TextInputFocusEventData { + target: number, + text: string, + eventCount: number +} + /** * @see https://facebook.github.io/react-native/docs/textinput.html#props */ @@ -1159,7 +1165,7 @@ export interface TextInputProps /** * Callback that is called when the text input is blurred */ - onBlur?: () => void; + onBlur?: (e: NativeSyntheticEvent) => void; /** * Callback that is called when the text input's text changes. @@ -1198,7 +1204,7 @@ export interface TextInputProps /** * Callback that is called when the text input is focused */ - onFocus?: () => void; + onFocus?: (e: NativeSyntheticEvent) => void; /** * Callback that is called when the text input selection is changed. From 028d2422e95393529d5b14ba3acb328870c07f4a Mon Sep 17 00:00:00 2001 From: Shane Fitzpatrick Date: Sat, 9 Jun 2018 08:21:28 -0700 Subject: [PATCH 2/2] Adding a test --- types/react-native/test/index.tsx | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index b3487057ed..1f506eb124 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -49,8 +49,10 @@ import { NativeModules, MaskedViewIOS, TextInput, + TextInputFocusEventData, InputAccessoryView, - StatusBar + StatusBar, + NativeSyntheticEvent } from "react-native"; declare module "react-native" { @@ -447,6 +449,25 @@ class TextInputRefTest extends React.Component<{}, {username: string}> { } } +class TextInputFocusBlurEventTest extends React.Component { + handleOnBlur(e: NativeSyntheticEvent) { + } + + handleOnFocus(e: NativeSyntheticEvent) { + } + + render() { + return ( + + ) => this.handleOnBlur(e)} + onFocus={(e: NativeSyntheticEvent) => this.handleOnFocus(e)} + /> + + ) + } +} + class StatusBarTest extends React.Component { render() { StatusBar.setBarStyle("dark-content", true);