@@ -5,7 +5,14 @@ import {
5
5
useRef ,
6
6
useState ,
7
7
} 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' ;
9
16
import {
10
17
ActivityIndicator ,
11
18
FlatList ,
@@ -72,7 +79,9 @@ interface GooglePlacesTextInputStyles {
72
79
} ;
73
80
}
74
81
75
- interface GooglePlacesTextInputProps {
82
+ type TextInputInheritedProps = Pick < TextInputProps , 'onFocus' | 'onBlur' > ;
83
+
84
+ interface GooglePlacesTextInputProps extends TextInputInheritedProps {
76
85
apiKey : string ;
77
86
value ?: string ;
78
87
placeHolderText ?: string ;
@@ -139,6 +148,8 @@ const GooglePlacesTextInput = forwardRef<
139
148
detailsFields = [ ] ,
140
149
onError,
141
150
enableDebug = false ,
151
+ onFocus,
152
+ onBlur,
142
153
} ,
143
154
ref
144
155
) => {
@@ -398,7 +409,11 @@ const GooglePlacesTextInput = forwardRef<
398
409
setSessionToken ( generateSessionToken ( ) ) ;
399
410
} ;
400
411
401
- const handleFocus = ( ) : void => {
412
+ const handleFocus = (
413
+ event : NativeSyntheticEvent < TextInputFocusEventData >
414
+ ) : void => {
415
+ onFocus ?.( event ) ;
416
+
402
417
if ( skipNextFocusFetch . current ) {
403
418
skipNextFocusFetch . current = false ;
404
419
return ;
@@ -409,6 +424,20 @@ const GooglePlacesTextInput = forwardRef<
409
424
}
410
425
} ;
411
426
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
+
412
441
const renderSuggestion = ( { item } : { item : PredictionItem } ) => {
413
442
const { mainText, secondaryText } = item . placePrediction . structuredFormat ;
414
443
@@ -521,15 +550,7 @@ const GooglePlacesTextInput = forwardRef<
521
550
value = { inputText }
522
551
onChangeText = { handleTextChange }
523
552
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 }
533
554
clearButtonMode = "never" // Disable iOS native clear button
534
555
/>
535
556
0 commit comments