react-native-google-places-autocomplete 2.5.5 → 2.5.6
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.
- package/GooglePlacesAutocomplete.js +48 -31
- package/package.json +3 -2
|
@@ -9,6 +9,7 @@ import React, {
|
|
|
9
9
|
useImperativeHandle,
|
|
10
10
|
useRef,
|
|
11
11
|
useState,
|
|
12
|
+
useCallback,
|
|
12
13
|
} from 'react';
|
|
13
14
|
import {
|
|
14
15
|
ActivityIndicator,
|
|
@@ -84,36 +85,46 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
|
|
|
84
85
|
}
|
|
85
86
|
};
|
|
86
87
|
|
|
87
|
-
const buildRowsFromResults = (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
88
|
+
const buildRowsFromResults = useCallback(
|
|
89
|
+
(results, text) => {
|
|
90
|
+
let res = [];
|
|
91
|
+
const shouldDisplayPredefinedPlaces = text
|
|
92
|
+
? results.length === 0 && text.length === 0
|
|
93
|
+
: results.length === 0;
|
|
94
|
+
if (
|
|
95
|
+
shouldDisplayPredefinedPlaces ||
|
|
96
|
+
props.predefinedPlacesAlwaysVisible === true
|
|
97
|
+
) {
|
|
98
|
+
res = [
|
|
99
|
+
...props.predefinedPlaces.filter(
|
|
100
|
+
(place) => place?.description.length,
|
|
101
|
+
),
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
if (props.currentLocation === true && hasNavigator()) {
|
|
105
|
+
res.unshift({
|
|
106
|
+
description: props.currentLocationLabel,
|
|
107
|
+
isCurrentLocation: true,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
105
110
|
}
|
|
106
|
-
}
|
|
107
111
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
res = res.map((place) => ({
|
|
113
|
+
...place,
|
|
114
|
+
isPredefinedPlace: true,
|
|
115
|
+
}));
|
|
112
116
|
|
|
113
|
-
|
|
114
|
-
|
|
117
|
+
return [...res, ...results];
|
|
118
|
+
},
|
|
119
|
+
[
|
|
120
|
+
props.currentLocation,
|
|
121
|
+
props.currentLocationLabel,
|
|
122
|
+
props.predefinedPlaces,
|
|
123
|
+
props.predefinedPlacesAlwaysVisible,
|
|
124
|
+
],
|
|
125
|
+
);
|
|
115
126
|
|
|
116
|
-
const getRequestUrl = (requestUrl) => {
|
|
127
|
+
const getRequestUrl = useCallback((requestUrl) => {
|
|
117
128
|
if (requestUrl) {
|
|
118
129
|
if (requestUrl.useOnPlatform === 'all') {
|
|
119
130
|
return requestUrl.url;
|
|
@@ -127,7 +138,7 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
|
|
|
127
138
|
} else {
|
|
128
139
|
return 'https://maps.googleapis.com/maps/api';
|
|
129
140
|
}
|
|
130
|
-
};
|
|
141
|
+
}, []);
|
|
131
142
|
|
|
132
143
|
const getRequestHeaders = (requestUrl) => {
|
|
133
144
|
return requestUrl?.headers || {};
|
|
@@ -144,11 +155,15 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
|
|
|
144
155
|
const [listViewDisplayed, setListViewDisplayed] = useState(
|
|
145
156
|
props.listViewDisplayed === 'auto' ? false : props.listViewDisplayed,
|
|
146
157
|
);
|
|
147
|
-
const [url] = useState(getRequestUrl(props.requestUrl));
|
|
158
|
+
const [url, setUrl] = useState(getRequestUrl(props.requestUrl));
|
|
148
159
|
const [listLoaderDisplayed, setListLoaderDisplayed] = useState(false);
|
|
149
160
|
|
|
150
161
|
const inputRef = useRef();
|
|
151
162
|
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
setUrl(getRequestUrl(props.requestUrl));
|
|
165
|
+
}, [getRequestUrl, props.requestUrl]);
|
|
166
|
+
|
|
152
167
|
useEffect(() => {
|
|
153
168
|
// This will load the search results after the query object ref gets changed
|
|
154
169
|
_handleChangeText(stateText);
|
|
@@ -157,10 +172,11 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
|
|
|
157
172
|
};
|
|
158
173
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
159
174
|
}, [props.query]);
|
|
175
|
+
|
|
160
176
|
useEffect(() => {
|
|
161
177
|
// Update dataSource if props.predefinedPlaces changed
|
|
162
178
|
setDataSource(buildRowsFromResults([]));
|
|
163
|
-
}, [props.predefinedPlaces]);
|
|
179
|
+
}, [buildRowsFromResults, props.predefinedPlaces]);
|
|
164
180
|
|
|
165
181
|
useImperativeHandle(ref, () => ({
|
|
166
182
|
setAddressText: (address) => {
|
|
@@ -561,6 +577,7 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
|
|
|
561
577
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
562
578
|
const debounceData = useMemo(() => debounce(_request, props.debounce), [
|
|
563
579
|
props.query,
|
|
580
|
+
url,
|
|
564
581
|
]);
|
|
565
582
|
|
|
566
583
|
const _onChangeText = (text) => {
|
|
@@ -888,8 +905,8 @@ GooglePlacesAutocomplete.propTypes = {
|
|
|
888
905
|
inbetweenCompo: PropTypes.object,
|
|
889
906
|
isRowScrollable: PropTypes.bool,
|
|
890
907
|
keyboardShouldPersistTaps: PropTypes.oneOf(['never', 'always', 'handled']),
|
|
891
|
-
listEmptyComponent: PropTypes.
|
|
892
|
-
listLoaderComponent: PropTypes.
|
|
908
|
+
listEmptyComponent: PropTypes.element,
|
|
909
|
+
listLoaderComponent: PropTypes.element,
|
|
893
910
|
listHoverColor: PropTypes.string,
|
|
894
911
|
listUnderlayColor: PropTypes.string,
|
|
895
912
|
// Must write it this way: https://stackoverflow.com/a/54290946/7180620
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-google-places-autocomplete",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.6",
|
|
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",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"lint": "eslint . && prettier --write .",
|
|
9
|
-
"release": "npx release-it"
|
|
9
|
+
"release": "npx release-it",
|
|
10
|
+
"prettier": "prettier --write ."
|
|
10
11
|
},
|
|
11
12
|
"author": "Farid from Safi",
|
|
12
13
|
"license": "MIT",
|