Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions GooglePlacesAutocomplete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ interface GooglePlacesAutocompleteProps {
}

export type GooglePlacesAutocompleteRef = {
setAddressTextAndQuery(address: string): void;
setAddressText(address: string): void;
getAddressText(): string;
getCurrentLocation(): void;
Expand Down
26 changes: 26 additions & 0 deletions GooglePlacesAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
}, [props.predefinedPlaces]);

useImperativeHandle(ref, () => ({
setAddressTextAndQuery:(address) => {
setStateText(address);
_handleAddressTextAndQuery(address);
},
setAddressText: (address) => {
setStateText(address);
},
Expand Down Expand Up @@ -563,6 +567,28 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
}
};

const _handleAddressTextAndQuery = async (address) => {

// Use Promise to ensure that the query is completed before logging addresses
await new Promise((resolve) => {
// Trigger the query to fetch autocomplete results based on the entered address
_request(address);

// Wait for a short delay to ensure the query is completed and results are available
setTimeout(() => {
resolve(dataSource);
}, 500); // Adjust the delay as needed
});

if (_results.length > 0) {
// Get the first item from _results
const firstResult = _results[0];

// Trigger the onPress function with the first result
_onPress(firstResult);
}
};

const _getRowLoader = () => {
return <ActivityIndicator animating={true} size='small' />;
};
Expand Down