@@ -5,7 +5,14 @@ import {
55 useRef ,
66 useState ,
77} from 'react' ;
8- import type { StyleProp , TextStyle , ViewStyle } from 'react-native' ;
8+ import type {
9+ StyleProp ,
10+ TextStyle ,
11+ ViewStyle ,
12+ TextInputProps ,
13+ TextInputFocusEventData ,
14+ NativeSyntheticEvent ,
15+ } from 'react-native' ;
916import {
1017 ActivityIndicator ,
1118 FlatList ,
@@ -72,7 +79,9 @@ interface GooglePlacesTextInputStyles {
7279 } ;
7380}
7481
75- interface GooglePlacesTextInputProps {
82+ type TextInputInheritedProps = Pick < TextInputProps , 'onFocus' | 'onBlur' > ;
83+
84+ interface GooglePlacesTextInputProps extends TextInputInheritedProps {
7685 apiKey : string ;
7786 value ?: string ;
7887 placeHolderText ?: string ;
@@ -139,6 +148,8 @@ const GooglePlacesTextInput = forwardRef<
139148 detailsFields = [ ] ,
140149 onError,
141150 enableDebug = false ,
151+ onFocus,
152+ onBlur,
142153 } ,
143154 ref
144155 ) => {
@@ -398,7 +409,11 @@ const GooglePlacesTextInput = forwardRef<
398409 setSessionToken ( generateSessionToken ( ) ) ;
399410 } ;
400411
401- const handleFocus = ( ) : void => {
412+ const handleFocus = (
413+ event : NativeSyntheticEvent < TextInputFocusEventData >
414+ ) : void => {
415+ onFocus ?.( event ) ;
416+
402417 if ( skipNextFocusFetch . current ) {
403418 skipNextFocusFetch . current = false ;
404419 return ;
@@ -409,6 +424,20 @@ const GooglePlacesTextInput = forwardRef<
409424 }
410425 } ;
411426
427+ const handleBlur = (
428+ event : NativeSyntheticEvent < TextInputFocusEventData >
429+ ) : void => {
430+ onBlur ?.( event ) ;
431+
432+ setTimeout ( ( ) => {
433+ if ( suggestionPressing . current ) {
434+ suggestionPressing . current = false ;
435+ } else {
436+ setShowSuggestions ( false ) ;
437+ }
438+ } , 10 ) ;
439+ } ;
440+
412441 const renderSuggestion = ( { item } : { item : PredictionItem } ) => {
413442 const { mainText, secondaryText } = item . placePrediction . structuredFormat ;
414443
@@ -521,15 +550,7 @@ const GooglePlacesTextInput = forwardRef<
521550 value = { inputText }
522551 onChangeText = { handleTextChange }
523552 onFocus = { handleFocus }
524- onBlur = { ( ) => {
525- setTimeout ( ( ) => {
526- if ( suggestionPressing . current ) {
527- suggestionPressing . current = false ;
528- } else {
529- setShowSuggestions ( false ) ;
530- }
531- } , 10 ) ;
532- } }
553+ onBlur = { handleBlur }
533554 clearButtonMode = "never" // Disable iOS native clear button
534555 />
535556
0 commit comments