|
| 1 | +import { |
| 2 | + ForwardRefExoticComponent, |
| 3 | + RefAttributes, |
| 4 | + TextInputProps, |
| 5 | +} from 'react-native'; |
| 6 | + |
| 7 | +export interface GooglePlacesTextInputProps extends TextInputProps { |
| 8 | + /** |
| 9 | + * Google API key for accessing Google Places API |
| 10 | + */ |
| 11 | + apiKey: string; |
| 12 | + |
| 13 | + /** |
| 14 | + * Callback that is called when a place is selected |
| 15 | + */ |
| 16 | + onPlaceSelected?: (place: GooglePlaceData) => void; |
| 17 | + |
| 18 | + /** |
| 19 | + * Callback that is called with the fetched prediction data |
| 20 | + */ |
| 21 | + onPredictionsFetched?: (predictions: GooglePrediction[]) => void; |
| 22 | + |
| 23 | + /** |
| 24 | + * Placeholder text for the input |
| 25 | + */ |
| 26 | + placeholder?: string; |
| 27 | + |
| 28 | + /** |
| 29 | + * Custom styles for the text input |
| 30 | + */ |
| 31 | + textInputStyle?: object; |
| 32 | + |
| 33 | + /** |
| 34 | + * Custom styles for the suggestions container |
| 35 | + */ |
| 36 | + suggestionsContainerStyle?: object; |
| 37 | + |
| 38 | + /** |
| 39 | + * Custom styles for each suggestion item |
| 40 | + */ |
| 41 | + suggestionItemStyle?: object; |
| 42 | + |
| 43 | + /** |
| 44 | + * Custom styles for each suggestion item text |
| 45 | + */ |
| 46 | + suggestionItemTextStyle?: object; |
| 47 | + |
| 48 | + /** |
| 49 | + * Language code (e.g., 'en', 'fr') for the Google Places API responses |
| 50 | + */ |
| 51 | + language?: string; |
| 52 | + |
| 53 | + /** |
| 54 | + * Country code (e.g., 'us', 'ca') to restrict results to specific countries |
| 55 | + */ |
| 56 | + components?: string; |
| 57 | + |
| 58 | + /** |
| 59 | + * Types of predictions to return |
| 60 | + */ |
| 61 | + types?: string; |
| 62 | + |
| 63 | + /** |
| 64 | + * Minimum length of text to trigger predictions |
| 65 | + */ |
| 66 | + minLength?: number; |
| 67 | + |
| 68 | + /** |
| 69 | + * Timeout (in ms) after which the request will be canceled if not completed |
| 70 | + */ |
| 71 | + fetchTimeout?: number; |
| 72 | + |
| 73 | + /** |
| 74 | + * Whether to enable the clear button in the text input |
| 75 | + */ |
| 76 | + enableClearButton?: boolean; |
| 77 | + |
| 78 | + /** |
| 79 | + * Whether to enable powered by Google logo |
| 80 | + */ |
| 81 | + enablePoweredByGoogle?: boolean; |
| 82 | + |
| 83 | + /** |
| 84 | + * Custom debounce delay in ms for API requests |
| 85 | + */ |
| 86 | + debounce?: number; |
| 87 | + |
| 88 | + /** |
| 89 | + * Whether to disable suggestions dropdown |
| 90 | + */ |
| 91 | + disableSuggestions?: boolean; |
| 92 | +} |
| 93 | + |
| 94 | +export interface GooglePrediction { |
| 95 | + /** |
| 96 | + * Place ID from Google Places API |
| 97 | + */ |
| 98 | + place_id: string; |
| 99 | + |
| 100 | + /** |
| 101 | + * Description of the place |
| 102 | + */ |
| 103 | + description: string; |
| 104 | + |
| 105 | + /** |
| 106 | + * Structured formatting for the place |
| 107 | + */ |
| 108 | + structured_formatting?: { |
| 109 | + main_text: string; |
| 110 | + secondary_text?: string; |
| 111 | + }; |
| 112 | + |
| 113 | + /** |
| 114 | + * Additional place details |
| 115 | + */ |
| 116 | + [key: string]: any; |
| 117 | +} |
| 118 | + |
| 119 | +export interface GooglePlaceData { |
| 120 | + /** |
| 121 | + * Place ID from Google Places API |
| 122 | + */ |
| 123 | + place_id: string; |
| 124 | + |
| 125 | + /** |
| 126 | + * Full text description of the place |
| 127 | + */ |
| 128 | + description?: string; |
| 129 | + |
| 130 | + /** |
| 131 | + * Place details when available |
| 132 | + */ |
| 133 | + details?: { |
| 134 | + /** |
| 135 | + * Formatted address of the place |
| 136 | + */ |
| 137 | + formatted_address?: string; |
| 138 | + |
| 139 | + /** |
| 140 | + * Geometry information including location coordinates |
| 141 | + */ |
| 142 | + geometry?: { |
| 143 | + location?: { |
| 144 | + lat: number; |
| 145 | + lng: number; |
| 146 | + }; |
| 147 | + }; |
| 148 | + |
| 149 | + /** |
| 150 | + * Place name |
| 151 | + */ |
| 152 | + name?: string; |
| 153 | + |
| 154 | + /** |
| 155 | + * Additional place details components |
| 156 | + */ |
| 157 | + address_components?: Array<{ |
| 158 | + long_name: string; |
| 159 | + short_name: string; |
| 160 | + types: string[]; |
| 161 | + }>; |
| 162 | + |
| 163 | + /** |
| 164 | + * Any other details returned by Google Places API |
| 165 | + */ |
| 166 | + [key: string]: any; |
| 167 | + }; |
| 168 | +} |
| 169 | + |
| 170 | +/** |
| 171 | + * A React Native component that provides Google Places autocomplete functionality in a text input. |
| 172 | + */ |
| 173 | +declare const GooglePlacesTextInput: ForwardRefExoticComponent< |
| 174 | + GooglePlacesTextInputProps & RefAttributes<any> |
| 175 | +>; |
| 176 | + |
| 177 | +export default GooglePlacesTextInput; |
0 commit comments