react-native-google-places-autocomplete 2.5.2 → 2.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -395,6 +395,8 @@ interface GooglePlacesAutocompleteProps {
395
395
  keyboardShouldPersistTaps?: 'never' | 'always' | 'handled';
396
396
  /** use the ListEmptyComponent prop when no autocomplete results are found. */
397
397
  listEmptyComponent?: JSX.Element | React.ComponentType<{}>;
398
+ /** use the ListLoaderComponent prop when no results are loading. */
399
+ listLoaderComponent?: JSX.Element | React.ComponentType<{}>;
398
400
  listHoverColor?: string;
399
401
  listUnderlayColor?: string;
400
402
  listViewDisplayed?: 'auto' | boolean;
@@ -84,10 +84,15 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
84
84
  }
85
85
  };
86
86
 
87
- const buildRowsFromResults = (results) => {
87
+ const buildRowsFromResults = (results, text) => {
88
88
  let res = [];
89
-
90
- if (results.length === 0 || props.predefinedPlacesAlwaysVisible === true) {
89
+ const shouldDisplayPredefinedPlaces = text
90
+ ? results.length === 0 && text.length === 0
91
+ : results.length === 0;
92
+ if (
93
+ shouldDisplayPredefinedPlaces ||
94
+ props.predefinedPlacesAlwaysVisible === true
95
+ ) {
91
96
  res = [
92
97
  ...props.predefinedPlaces.filter((place) => place?.description.length),
93
98
  ];
@@ -140,6 +145,7 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
140
145
  props.listViewDisplayed === 'auto' ? false : props.listViewDisplayed,
141
146
  );
142
147
  const [url] = useState(getRequestUrl(props.requestUrl));
148
+ const [listLoaderDisplayed, setListLoaderDisplayed] = useState(false);
143
149
 
144
150
  const inputRef = useRef();
145
151
 
@@ -409,9 +415,11 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
409
415
  request.ontimeout = props.onTimeout;
410
416
  request.onreadystatechange = () => {
411
417
  if (request.readyState !== 4) {
418
+ setListLoaderDisplayed(true);
412
419
  return;
413
420
  }
414
421
 
422
+ setListLoaderDisplayed(false);
415
423
  if (request.status === 200) {
416
424
  const responseJSON = JSON.parse(request.responseText);
417
425
 
@@ -490,9 +498,11 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
490
498
  request.ontimeout = props.onTimeout;
491
499
  request.onreadystatechange = () => {
492
500
  if (request.readyState !== 4) {
501
+ setListLoaderDisplayed(true);
493
502
  return;
494
503
  }
495
504
 
505
+ setListLoaderDisplayed(false);
496
506
  if (request.status === 200) {
497
507
  const responseJSON = JSON.parse(request.responseText);
498
508
  if (typeof responseJSON.predictions !== 'undefined') {
@@ -506,7 +516,7 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
506
516
  : responseJSON.predictions;
507
517
 
508
518
  _results = results;
509
- setDataSource(buildRowsFromResults(results));
519
+ setDataSource(buildRowsFromResults(results, text));
510
520
  // }
511
521
  }
512
522
  if (typeof responseJSON.error_message !== 'undefined') {
@@ -779,7 +789,9 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
779
789
  ItemSeparatorComponent={_renderSeparator}
780
790
  renderItem={({ item, index }) => _renderRow(item, index)}
781
791
  ListEmptyComponent={
782
- stateText.length > props.minLength && props.listEmptyComponent
792
+ listLoaderDisplayed
793
+ ? props.listLoaderComponent
794
+ : stateText.length > props.minLength && props.listEmptyComponent
783
795
  }
784
796
  ListHeaderComponent={
785
797
  props.renderHeaderComponent &&
@@ -874,6 +886,7 @@ GooglePlacesAutocomplete.propTypes = {
874
886
  isRowScrollable: PropTypes.bool,
875
887
  keyboardShouldPersistTaps: PropTypes.oneOf(['never', 'always', 'handled']),
876
888
  listEmptyComponent: PropTypes.func,
889
+ listLoaderComponent: PropTypes.func,
877
890
  listHoverColor: PropTypes.string,
878
891
  listUnderlayColor: PropTypes.string,
879
892
  // Must write it this way: https://stackoverflow.com/a/54290946/7180620
@@ -955,4 +968,6 @@ GooglePlacesAutocomplete.defaultProps = {
955
968
  timeout: 20000,
956
969
  };
957
970
 
971
+ GooglePlacesAutocomplete.displayName = 'GooglePlacesAutocomplete';
972
+
958
973
  export default { GooglePlacesAutocomplete };
package/README.md CHANGED
@@ -6,10 +6,23 @@
6
6
 
7
7
  **Customizable Google Places autocomplete component for iOS and Android React-Native apps**
8
8
 
9
- Version 2 of this library is now available. See more in the [releases](https://github.com/FaridSafi/react-native-google-places-autocomplete/releases/tag/v2.0.0) section.
10
-
11
- # :warning: Maintainers Wanted ![Maintainers Wanted](https://img.shields.io/badge/Maintainers-Wanted-green)
12
- We are in need of more people or companies willing to help. If you have enough time and knowledge, and want to become a maintainer, please open a new issue.
9
+ ## Sponsor
10
+
11
+ <p align="center">
12
+ <br/>
13
+ <a href="https://bit.ly/3rneTTI" target="_blank">
14
+ <img src="https://raw.githubusercontent.com/FaridSafi/react-native-google-places-autocomplete/master/Assets/expensify-logo.png">
15
+ </a>
16
+ <br>
17
+ <p align="center">
18
+ The financial management super app for expenses, corporate cards, and more.
19
+ </p>
20
+ <a href="https://bit.ly/3rneTTI" target="_blank">
21
+ <p align="center">
22
+ Click to learn more
23
+ </p>
24
+ </a>
25
+ </p>
13
26
 
14
27
  ## Preview
15
28
 
@@ -221,52 +234,53 @@ export default GooglePlacesInput;
221
234
 
222
235
  _This list is a work in progress. PRs welcome!_
223
236
 
224
- | Prop Name | type | description | default value | Options |
225
- | ----------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ---------------------------------------------------------- |
226
- | autoFillOnNotFound | boolean | displays the result from autocomplete if the place details api return not found | false | true \| false |
227
- | currentLocation | boolean | Will add a 'Current location' button at the top of the predefined places list | false | true \| false |
228
- | currentLocationLabel | string | change the display label for the current location button | Current Location | Any string |
229
- | debounce | number | debounce the requests (in ms) | 0 | |
230
- | disableScroll | boolean | disable scroll on the results list | | |
231
- | enableHighAccuracyLocation | boolean | use GPS or not. If set to true, a GPS position will be requested. If set to false, a WIFI location will be requested. use GPS or not. If set to true, a GPS position will be requested. If set to false, a WIFI location will be requested. | true | |
232
- | enablePoweredByContainer | boolean | show "powered by Google" at the bottom of the search results list | true | |
233
- | fetchDetails | boolean | get more place details about the selected option from the Place Details API | false | |
234
- | filterReverseGeocodingByTypes | array | filter the reverse geocoding results by types - ['locality', 'administrative_area_level_3'] if you want to display only cities | | |
235
- | GooglePlacesDetailsQuery | object | "query" object for the Google Place Details API (when you press on a suggestion) | | |
236
- | GooglePlacesSearchQuery | object | "query" object for the Google Places Nearby API (when you use current location to find nearby places) | `{ rankby: 'distance', type: 'restaurant' }` | |
237
- | GoogleReverseGeocodingQuery | object | "query" object for the Google Geocode API (when you use current location to get the current address) | | |
238
- | isRowScrollable | boolean | enable/disable horizontal scrolling of a list result https://reactnative.dev/docs/scrollview#scrollenabled | true |
239
- |inbetweenCompo|React.ReactNode|Insert a ReactNode in between the search bar and the search results Flatlist
240
- | keepResultsAfterBlur | boolean | show list of results after blur | false | true \| false |
241
- | keyboardShouldPersistTaps | string | Determines when the keyboard should stay visible after a tap https://reactnative.dev/docs/scrollview#keyboardshouldpersisttaps | 'always' | 'never' \| 'always' \| 'handled' |
242
- | listEmptyComponent | function | use FlatList's ListEmptyComponent prop when no autocomplete results are found. | | |
243
- | listHoverColor | string | underlay color of the list result when hovered (web only) | '#ececec' | |
244
- | listUnderlayColor | string | underlay color of the list result when pressed https://reactnative.dev/docs/touchablehighlight#underlaycolor | '#c8c7cc' | |
245
- | listViewDisplayed | string | override the default behavior of showing the list (results) view | 'auto' | 'auto' \| true \| false |
246
- | minLength | number | minimum length of text to trigger a search | 0 | |
247
- | nearbyPlacesAPI | string | which API to use for current location | 'GooglePlacesSearch' | 'none' \| 'GooglePlacesSearch' \| 'GoogleReverseGeocoding' |
248
- | numberOfLines | number | number of lines (android - multiline must be set to true) https://reactnative.dev/docs/textinput#numberoflines | 1 | |
249
- | onFail | function | returns if an unspecified error comes back from the API | | |
250
- | onNotFound | function | returns if the Google Places Details API returns a 'not found' code (when you press a suggestion). | | |
251
- | onPress | function | returns when after a suggestion is selected | | |
252
- | onTimeout | function | callback when a request timeout | `()=>console.warn('google places autocomplete: request timeout')` | |
253
- | placeholder | string | placeholder text https://reactnative.dev/docs/textinput#placeholder | 'Search' | |
254
- | predefinedPlaces | array | Allows you to show pre-defined places (e.g. home, work) | | |
255
- | predefinedPlacesAlwaysVisible | boolean | Shows predefined places at the top of the search results | false | |
256
- | preProcess | function | do something to the text of the search input before a search request is sent | | |
257
- | query | object | "query" object for the Google Places Autocomplete API (link) | `{ key: 'missing api key', language: 'en', types: 'geocode' }` | |
258
- | renderDescription | function | determines the data passed to each renderRow (search result) | | |
259
- | renderHeaderComponent | function | use the `ListHeaderComponent` from `FlatList` when showing autocomplete results | | |
260
- | renderLeftButton | function | add a component to the left side of the Text Input | | |
261
- | renderRightButton | function | add a component to the right side of the Text Input | | |
262
- | renderRow | function | custom component to render each result row (use this to show an icon beside each result). `data` and `index` will be passed as input parameters | | |
263
- | requestUrl | object | used to set the request url for the library | | |
264
- | returnKeyType | string | the return key text https://reactnative.dev/docs/textinput#returnkeytype | 'search' | |
265
- | styles | object | See styles section below | | |
266
- | suppressDefaultStyles | boolean | removes all default styling from the library | false | true \| false |
267
- | textInputHide | boolean | Hide the Search input | false | true \| false |
268
- | textInputProps | object | define props for the [textInput](https://reactnative.dev/docs/textinput), or provide a custom input component | | |
269
- | timeout | number | how many ms until the request will timeout | 20000 | |
237
+ | Prop Name | type | description | default value | Options |
238
+ | ----------------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ---------------------------------------------------------- |
239
+ | autoFillOnNotFound | boolean | displays the result from autocomplete if the place details api return not found | false | true \| false |
240
+ | currentLocation | boolean | Will add a 'Current location' button at the top of the predefined places list | false | true \| false |
241
+ | currentLocationLabel | string | change the display label for the current location button | Current Location | Any string |
242
+ | debounce | number | debounce the requests (in ms) | 0 | |
243
+ | disableScroll | boolean | disable scroll on the results list | | |
244
+ | enableHighAccuracyLocation | boolean | use GPS or not. If set to true, a GPS position will be requested. If set to false, a WIFI location will be requested. use GPS or not. If set to true, a GPS position will be requested. If set to false, a WIFI location will be requested. | true | |
245
+ | enablePoweredByContainer | boolean | show "powered by Google" at the bottom of the search results list | true | |
246
+ | fetchDetails | boolean | get more place details about the selected option from the Place Details API | false | |
247
+ | filterReverseGeocodingByTypes | array | filter the reverse geocoding results by types - ['locality', 'administrative_area_level_3'] if you want to display only cities | | |
248
+ | GooglePlacesDetailsQuery | object | "query" object for the Google Place Details API (when you press on a suggestion) | | |
249
+ | GooglePlacesSearchQuery | object | "query" object for the Google Places Nearby API (when you use current location to find nearby places) | `{ rankby: 'distance', type: 'restaurant' }` | |
250
+ | GoogleReverseGeocodingQuery | object | "query" object for the Google Geocode API (when you use current location to get the current address) | | |
251
+ | isRowScrollable | boolean | enable/disable horizontal scrolling of a list result https://reactnative.dev/docs/scrollview#scrollenabled | true |
252
+ | inbetweenCompo | React.ReactNode | Insert a ReactNode in between the search bar and the search results Flatlist |
253
+ | keepResultsAfterBlur | boolean | show list of results after blur | false | true \| false |
254
+ | keyboardShouldPersistTaps | string | Determines when the keyboard should stay visible after a tap https://reactnative.dev/docs/scrollview#keyboardshouldpersisttaps | 'always' | 'never' \| 'always' \| 'handled' |
255
+ | listEmptyComponent | function | use FlatList's ListEmptyComponent prop when no autocomplete results are found. | | |
256
+ | listLoaderComponent | function | show this component while results are loading. | | |
257
+ | listHoverColor | string | underlay color of the list result when hovered (web only) | '#ececec' | |
258
+ | listUnderlayColor | string | underlay color of the list result when pressed https://reactnative.dev/docs/touchablehighlight#underlaycolor | '#c8c7cc' | |
259
+ | listViewDisplayed | string | override the default behavior of showing the list (results) view | 'auto' | 'auto' \| true \| false |
260
+ | minLength | number | minimum length of text to trigger a search | 0 | |
261
+ | nearbyPlacesAPI | string | which API to use for current location | 'GooglePlacesSearch' | 'none' \| 'GooglePlacesSearch' \| 'GoogleReverseGeocoding' |
262
+ | numberOfLines | number | number of lines (android - multiline must be set to true) https://reactnative.dev/docs/textinput#numberoflines | 1 | |
263
+ | onFail | function | returns if an unspecified error comes back from the API | | |
264
+ | onNotFound | function | returns if the Google Places Details API returns a 'not found' code (when you press a suggestion). | | |
265
+ | onPress | function | returns when after a suggestion is selected | | |
266
+ | onTimeout | function | callback when a request timeout | `()=>console.warn('google places autocomplete: request timeout')` | |
267
+ | placeholder | string | placeholder text https://reactnative.dev/docs/textinput#placeholder | 'Search' | |
268
+ | predefinedPlaces | array | Allows you to show pre-defined places (e.g. home, work) | | |
269
+ | predefinedPlacesAlwaysVisible | boolean | Shows predefined places at the top of the search results | false | |
270
+ | preProcess | function | do something to the text of the search input before a search request is sent | | |
271
+ | query | object | "query" object for the Google Places Autocomplete API (link) | `{ key: 'missing api key', language: 'en', types: 'geocode' }` | |
272
+ | renderDescription | function | determines the data passed to each renderRow (search result) | | |
273
+ | renderHeaderComponent | function | use the `ListHeaderComponent` from `FlatList` when showing autocomplete results | | |
274
+ | renderLeftButton | function | add a component to the left side of the Text Input | | |
275
+ | renderRightButton | function | add a component to the right side of the Text Input | | |
276
+ | renderRow | function | custom component to render each result row (use this to show an icon beside each result). `data` and `index` will be passed as input parameters | | |
277
+ | requestUrl | object | used to set the request url for the library | | |
278
+ | returnKeyType | string | the return key text https://reactnative.dev/docs/textinput#returnkeytype | 'search' | |
279
+ | styles | object | See styles section below | | |
280
+ | suppressDefaultStyles | boolean | removes all default styling from the library | false | true \| false |
281
+ | textInputHide | boolean | Hide the Search input | false | true \| false |
282
+ | textInputProps | object | define props for the [textInput](https://reactnative.dev/docs/textinput), or provide a custom input component | | |
283
+ | timeout | number | how many ms until the request will timeout | 20000 | |
270
284
 
271
285
  ## Methods
272
286
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-google-places-autocomplete",
3
- "version": "2.5.2",
3
+ "version": "2.5.4",
4
4
  "description": "Customizable Google Places autocomplete component for iOS and Android React-Native apps",
5
5
  "main": "GooglePlacesAutocomplete.js",
6
6
  "types": "GooglePlacesAutocomplete.d.ts",