Skip to content

Commit

Permalink
add custom input example (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
bell-steven authored Nov 8, 2020
1 parent 6832c88 commit ca74af2
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**Customizable Google Places autocomplete component for iOS and Android React-Native apps**

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.
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.

## Preview

Expand All @@ -15,6 +15,7 @@ Version 2 of this library is now available. See more in the [releases](https://
```
npm install react-native-google-places-autocomplete --save
```

or

```
Expand Down Expand Up @@ -172,6 +173,43 @@ export default GooglePlacesInput;

</details>

**Use a custom Text Input Component**

<details>
<summary>Click to expand</summary>

This is an example using the Text Input from [`react-native-elements`](https://reactnativeelements.com/docs/input).

```js
import React from 'react';
import { Text, View, Image } from 'react-native';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
import { Input } from 'react-native-elements';

const GOOGLE_PLACES_API_KEY = 'YOUR_GOOGLE_API_KEY';

const GooglePlacesInput = () => {
return (
<GooglePlacesAutocomplete
query={{
key: GOOGLE_PLACES_API_KEY,
language: 'en', // language of the results
}}
onPress={(data, details) => console.log(data, details)}
textInputProps={{
InputComp: Input,
leftIcon: { type: 'font-awesome', name: 'chevron-left' },
errorStyle: { color: 'red' },
}}
/>
);
};

export default GooglePlacesInput;
```

</details>

## Props

_This list is a work in progress. PRs welcome!_
Expand Down Expand Up @@ -364,7 +402,7 @@ The `requestUrl` prop takes an object with two properties: `useOnPlatform` and `
The `url` property is used to set the url that requests will be made to. If you are using the regular google maps API, you need to make sure you are ultimately hitting https://maps.googleapis.com/maps/api.
`useOnPlatform` configures when the proxy url is used. It can be set to either `web`- will be used only when the device platform is detected as web (but not iOS or Android, or `all` - will always be used.
`useOnPlatform` configures when the proxy url is used. It can be set to either `web`- will be used only when the device platform is detected as web (but not iOS or Android, or `all` - will always be used.
### Example:
Expand All @@ -385,8 +423,9 @@ const GooglePlacesInput = () => {
language: 'en',
}}
requestUrl={{
useOnPlatform: "web", // or "all"
url: "https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api", // or any proxy server that hits https://maps.googleapis.com/maps/api
useOnPlatform: 'web', // or "all"
url:
'https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api', // or any proxy server that hits https://maps.googleapis.com/maps/api
}}
/>
);
Expand Down

0 comments on commit ca74af2

Please sign in to comment.