-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New places api support #47085
base: main
Are you sure you want to change the base?
New places api support #47085
Changes from all commits
04ea3a8
6425853
4836de6
4692371
43d5dba
67cc635
9a75de7
0e52dc9
ae0ef58
b396dd8
0c07e99
4379632
18d79b0
8f05d04
0ad4459
2a070f6
5b133e8
805eb47
f9e2ddc
4b60132
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,6 @@ function AddressSearch( | |
lat: 'addressLat', | ||
lng: 'addressLng', | ||
}, | ||
resultTypes = 'address', | ||
shouldSaveDraft = false, | ||
value, | ||
locationBias, | ||
|
@@ -99,26 +98,25 @@ function AddressSearch( | |
const containerRef = useRef<View>(null); | ||
const query = useMemo( | ||
() => ({ | ||
language: preferredLocale, | ||
types: resultTypes, | ||
components: isLimitedToUSA ? 'country:us' : undefined, | ||
...(locationBias && {locationbias: locationBias}), | ||
languageCode: preferredLocale, | ||
includedRegionCodes: isLimitedToUSA ? ['us'] : undefined, | ||
...(locationBias && {locationBias}), | ||
}), | ||
[preferredLocale, resultTypes, isLimitedToUSA, locationBias], | ||
[preferredLocale, isLimitedToUSA, locationBias], | ||
); | ||
const shouldShowCurrentLocationButton = canUseCurrentLocation && searchValue.trim().length === 0 && isFocused; | ||
const saveLocationDetails = (autocompleteData: GooglePlaceData, details: GooglePlaceDetail | null) => { | ||
const addressComponents = details?.address_components; | ||
const addressComponents = details?.addressComponents; | ||
if (!addressComponents) { | ||
// When there are details, but no address_components, this indicates that some predefined options have been passed | ||
// to this component which don't match the usual properties coming from auto-complete. In that case, only a limited | ||
// amount of data massaging needs to happen for what the parent expects to get from this function. | ||
if (details) { | ||
onPress?.({ | ||
address: autocompleteData.description ?? '', | ||
lat: details.geometry.location.lat ?? 0, | ||
lng: details.geometry.location.lng ?? 0, | ||
name: details.name, | ||
lat: details.location?.latitude ?? details.geometry.location?.lat ?? 0, | ||
lng: details.location?.longitude ?? details.geometry.location?.lng ?? 0, | ||
name: autocompleteData?.structured_formatting?.main_text ?? details?.name ?? '', | ||
}); | ||
} | ||
return; | ||
|
@@ -138,27 +136,27 @@ function AddressSearch( | |
country: countryPrimary, | ||
} = GooglePlacesUtils.getAddressComponents(addressComponents, { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
street_number: 'long_name', | ||
route: 'long_name', | ||
subpremise: 'long_name', | ||
locality: 'long_name', | ||
sublocality: 'long_name', | ||
street_number: 'longText', | ||
route: 'longText', | ||
subpremise: 'longText', | ||
locality: 'longText', | ||
sublocality: 'longText', | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
postal_town: 'long_name', | ||
postal_town: 'longText', | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
postal_code: 'long_name', | ||
postal_code: 'longText', | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
administrative_area_level_1: 'short_name', | ||
administrative_area_level_1: 'shortText', | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
administrative_area_level_2: 'long_name', | ||
country: 'short_name', | ||
administrative_area_level_2: 'longText', | ||
country: 'shortText', | ||
}); | ||
|
||
// The state's iso code (short_name) is needed for the StatePicker component but we also | ||
// need the state's full name (long_name) when we render the state in a TextInput. | ||
// need the state's full name (longText) when we render the state in a TextInput. | ||
const {administrative_area_level_1: longStateName} = GooglePlacesUtils.getAddressComponents(addressComponents, { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
administrative_area_level_1: 'long_name', | ||
administrative_area_level_1: 'longText', | ||
}); | ||
|
||
// Make sure that the order of keys remains such that the country is always set above the state. | ||
|
@@ -176,7 +174,7 @@ function AddressSearch( | |
|
||
const values = { | ||
street: `${streetNumber} ${streetName}`.trim(), | ||
name: details.name ?? '', | ||
name: autocompleteData?.structured_formatting?.main_text ?? details?.name ?? '', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
// Autocomplete returns any additional valid address fragments (e.g. Apt #) as subpremise. | ||
street2: subpremise, | ||
// Make sure country is updated first, since city and state will be reset if the country changes | ||
|
@@ -189,9 +187,9 @@ function AddressSearch( | |
city: locality || postalTown || sublocality || cityAutocompleteFallback, | ||
zipCode, | ||
|
||
lat: details.geometry.location.lat ?? 0, | ||
lng: details.geometry.location.lng ?? 0, | ||
address: autocompleteData.description || details.formatted_address || '', | ||
lat: details.location?.latitude ?? details.geometry.location?.lat ?? 0, | ||
lng: details.location?.longitude ?? details.geometry.location?.lng ?? 0, | ||
address: autocompleteData.description || details.formattedAddress || '', | ||
}; | ||
|
||
// If the address is not in the US, use the full length state name since we're displaying the address's | ||
|
@@ -213,9 +211,9 @@ function AddressSearch( | |
|
||
// Some edge-case addresses may lack both street_number and route in the API response, resulting in an empty "values.street" | ||
// We are setting up a fallback to ensure "values.street" is populated with a relevant value | ||
if (!values.street && details.adr_address) { | ||
if (!values.street && details.adrFormatAddress) { | ||
const streetAddressRegex = /<span class="street-address">([^<]*)<\/span>/; | ||
const adrAddress = details.adr_address.match(streetAddressRegex); | ||
const adrAddress = details.adrFormatAddress.match(streetAddressRegex); | ||
const streetAddressFallback = adrAddress ? adrAddress?.[1] : null; | ||
if (streetAddressFallback) { | ||
values.street = streetAddressFallback; | ||
|
@@ -480,6 +478,8 @@ function AddressSearch( | |
} | ||
placeholder="" | ||
listViewDisplayed | ||
fields={CONST.GOOGLE_PLACES_API.FIELDS_MASK} | ||
isNewPlacesAPI | ||
> | ||
<LocationErrorMessage | ||
onClose={() => setLocationErrorCode(null)} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
details.name
isn't the same as it was in the old API, the format here isplaces/<id>
so not really good to use here. The next closest thing isdetails?. shortFormattedAddress
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this context, the
details.name
is not used from old API. Instead, it indicates a predefined option i.e. saved places in our app. So, I think we need to keepdetails.name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what you mean, can you show me? The way I understand this code, the value in
autocompleteData.structured_formatting.main_text
in the new API is most similar todetails.name
from the old api. However,details.name
is no longer a good fallback, as in the new API, it does not contain a short version of the address, but something else entirelyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please find the test video that demonstrates the use of
predefined
places. This is the reason why I think we need to keepdetails.name
.47085-predefined-places.mp4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm ok. Can you take a look at how this is utilized when changing your address on the profile settings page as well? I wonder if we need different values in the two places.