Skip to content

Commit ca74af2

Browse files
authored
add custom input example (#651)
1 parent 6832c88 commit ca74af2

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

README.md

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
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.
5+
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.
66

77
## Preview
88

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

2021
```
@@ -172,6 +173,43 @@ export default GooglePlacesInput;
172173

173174
</details>
174175

176+
**Use a custom Text Input Component**
177+
178+
<details>
179+
<summary>Click to expand</summary>
180+
181+
This is an example using the Text Input from [`react-native-elements`](https://reactnativeelements.com/docs/input).
182+
183+
```js
184+
import React from 'react';
185+
import { Text, View, Image } from 'react-native';
186+
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
187+
import { Input } from 'react-native-elements';
188+
189+
const GOOGLE_PLACES_API_KEY = 'YOUR_GOOGLE_API_KEY';
190+
191+
const GooglePlacesInput = () => {
192+
return (
193+
<GooglePlacesAutocomplete
194+
query={{
195+
key: GOOGLE_PLACES_API_KEY,
196+
language: 'en', // language of the results
197+
}}
198+
onPress={(data, details) => console.log(data, details)}
199+
textInputProps={{
200+
InputComp: Input,
201+
leftIcon: { type: 'font-awesome', name: 'chevron-left' },
202+
errorStyle: { color: 'red' },
203+
}}
204+
/>
205+
);
206+
};
207+
208+
export default GooglePlacesInput;
209+
```
210+
211+
</details>
212+
175213
## Props
176214

177215
_This list is a work in progress. PRs welcome!_
@@ -364,7 +402,7 @@ The `requestUrl` prop takes an object with two properties: `useOnPlatform` and `
364402
365403
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.
366404
367-
`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.
405+
`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.
368406
369407
### Example:
370408
@@ -385,8 +423,9 @@ const GooglePlacesInput = () => {
385423
language: 'en',
386424
}}
387425
requestUrl={{
388-
useOnPlatform: "web", // or "all"
389-
url: "https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api", // or any proxy server that hits https://maps.googleapis.com/maps/api
426+
useOnPlatform: 'web', // or "all"
427+
url:
428+
'https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api', // or any proxy server that hits https://maps.googleapis.com/maps/api
390429
}}
391430
/>
392431
);

0 commit comments

Comments
 (0)