Skip to content

Commit 1c1bf91

Browse files
committed
feat: update component, example and readme
1 parent fb23a1d commit 1c1bf91

19 files changed

+11369
-139
lines changed

README.md

Lines changed: 128 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,145 @@
1-
# react-native-google-places-textinput
1+
# React Native Google Places TextInput
22

3-
A customizable React Native component for Google Places Autocomplete TextInput using Places API (New)
3+
A customizable React Native TextInput component for Google Places Autocomplete using the Places API (New)
4+
5+
## Features
6+
7+
- 🎨 Fully customizable UI
8+
- 🌍 RTL support
9+
- ⌨️ Debounced search
10+
- 🔄 Loading indicators
11+
- 📱 Keyboard-aware
12+
- 🎯 TypeScript support
13+
- 🔍 Custom place types filtering
14+
- 🌐 Multi-language support
415

516
## Installation
617

7-
```sh
18+
```bash
819
npm install react-native-google-places-textinput
20+
# or
21+
yarn add react-native-google-places-textinput
922
```
1023

24+
## Prerequisites
25+
26+
- Get a Google Places API key from the [Google Cloud Console](https://console.cloud.google.com/)
27+
- Enable Places API (New) in your Google Cloud Project
28+
1129
## Usage
1230

31+
```javascript
32+
import GooglePlacesTextInput from 'react-native-google-places-textinput';
1333

14-
```js
15-
import { multiply } from 'react-native-google-places-textinput';
34+
const YourComponent = () => {
35+
const handlePlaceSelect = (place) => {
36+
if (place) {
37+
console.log('Selected place:', place);
38+
}
39+
};
1640

17-
// ...
41+
// Example with custom styles
42+
const customStyles = {
43+
container: {
44+
width: '100%',
45+
marginHorizontal: 0,
46+
},
47+
input: {
48+
height: 45,
49+
borderColor: '#ccc',
50+
borderRadius: 8,
51+
},
52+
suggestionsContainer: {
53+
backgroundColor: '#ffffff',
54+
maxHeight: 250,
55+
},
56+
suggestionItem: {
57+
padding: 15,
58+
},
59+
suggestionText: {
60+
main: {
61+
fontSize: 16,
62+
color: '#333',
63+
},
64+
secondary: {
65+
fontSize: 14,
66+
color: '#666',
67+
}
68+
},
69+
loadingIndicator: {
70+
color: '#999',
71+
},
72+
placeholder: {
73+
color: '#999',
74+
}
75+
};
1876

19-
const result = await multiply(3, 7);
77+
return (
78+
<GooglePlacesTextInput
79+
apiKey="YOUR_GOOGLE_PLACES_API_KEY"
80+
placeHolderText="Search for a place"
81+
onPlaceSelect={handlePlaceSelect}
82+
languageCode="en"
83+
style={customStyles}
84+
/>
85+
);
86+
};
2087
```
2188

89+
## Props
90+
91+
| Prop | Type | Required | Default | Description |
92+
|------|------|----------|---------|-------------|
93+
| apiKey | string | Yes | - | Your Google Places API key |
94+
| value | string | No | '' | Initial input value |
95+
| placeHolderText | string | No | - | Placeholder text for input |
96+
| languageCode | string | No | - | Language code (e.g., 'en', 'fr') |
97+
| includedRegionCodes | string[] | No | - | Array of region codes to filter results |
98+
| types | string[] | No | [] | Array of place types to filter |
99+
| biasPrefixText | string | No | - | Text to prepend to search query |
100+
| minCharsToFetch | number | No | 1 | Minimum characters before fetching |
101+
| onPlaceSelect | (place: Place \| null) => void | Yes | - | Callback when place is selected |
102+
| debounceDelay | number | No | 200 | Delay before triggering search |
103+
| showLoadingIndicator | boolean | No | true | Show/hide loading indicator |
104+
| style | StyleProp | No | {} | Custom styles object |
105+
106+
## Methods
107+
108+
The component exposes the following methods through refs:
109+
110+
- `clear()`: Clears the input and suggestions
111+
- `focus()`: Focuses the input field
112+
113+
```javascript
114+
const inputRef = useRef(null);
115+
116+
// Usage
117+
inputRef.current?.clear();
118+
inputRef.current?.focus();
119+
```
120+
121+
## Styling
122+
123+
The component accepts a `style` prop with the following structure:
124+
125+
```typescript
126+
type Styles = {
127+
container?: ViewStyle;
128+
input?: TextStyle;
129+
suggestionsContainer?: ViewStyle;
130+
suggestionItem?: ViewStyle;
131+
suggestionText?: {
132+
main?: TextStyle;
133+
secondary?: TextStyle;
134+
};
135+
loadingIndicator?: {
136+
color?: string;
137+
};
138+
placeholder?: {
139+
color?: string;
140+
};
141+
}
142+
```
22143
23144
## Contributing
24145

example/App.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import { SafeAreaView, StyleSheet, View, Text } from 'react-native';
2+
import GooglePlacesTextInput from 'react-native-google-places-textinput';
3+
4+
const App = () => {
5+
const handleBasicPlaceSelect = (place) => {
6+
console.log('Basic example selected place:', place);
7+
};
8+
9+
const handleStyledPlaceSelect = (place) => {
10+
console.log('Styled example selected place:', place);
11+
};
12+
13+
// Custom styles example
14+
const customStyles = {
15+
container: {
16+
width: '100%',
17+
paddingHorizontal: 16,
18+
},
19+
input: {
20+
height: 50,
21+
borderWidth: 1.5,
22+
borderColor: '#E0E0E0',
23+
borderRadius: 12,
24+
paddingHorizontal: 16,
25+
fontSize: 16,
26+
backgroundColor: '#F8F8F8',
27+
},
28+
suggestionsContainer: {
29+
backgroundColor: '#FFFFFF',
30+
borderRadius: 12,
31+
marginTop: 8,
32+
elevation: 3,
33+
shadowColor: '#000',
34+
shadowOffset: { width: 0, height: 2 },
35+
shadowOpacity: 0.1,
36+
shadowRadius: 8,
37+
},
38+
suggestionItem: {
39+
padding: 16,
40+
borderBottomWidth: 1,
41+
borderBottomColor: '#F0F0F0',
42+
},
43+
suggestionText: {
44+
main: {
45+
fontSize: 16,
46+
color: '#333333',
47+
fontWeight: '500',
48+
},
49+
secondary: {
50+
fontSize: 14,
51+
color: '#666666',
52+
marginTop: 4,
53+
},
54+
},
55+
loadingIndicator: {
56+
color: '#666666',
57+
},
58+
placeholder: {
59+
color: '#999999',
60+
},
61+
};
62+
63+
return (
64+
<SafeAreaView style={styles.container}>
65+
<View style={styles.section}>
66+
<Text style={styles.sectionTitle}>Basic Example</Text>
67+
<GooglePlacesTextInput
68+
apiKey="YOUR_API_KEY_HERE"
69+
placeHolderText="Search for a location"
70+
onPlaceSelect={handleBasicPlaceSelect}
71+
minCharsToFetch={2}
72+
languageCode="en"
73+
/>
74+
</View>
75+
76+
<View style={styles.section}>
77+
<Text style={styles.sectionTitle}>Styled Example</Text>
78+
<GooglePlacesTextInput
79+
apiKey="YOUR_API_KEY_HERE"
80+
placeHolderText="Find places nearby"
81+
onPlaceSelect={handleStyledPlaceSelect}
82+
style={customStyles}
83+
minCharsToFetch={2}
84+
languageCode="en"
85+
debounceDelay={300}
86+
types={['restaurant', 'cafe']}
87+
/>
88+
</View>
89+
</SafeAreaView>
90+
);
91+
};
92+
93+
const styles = StyleSheet.create({
94+
container: {
95+
flex: 1,
96+
backgroundColor: '#fff',
97+
},
98+
section: {
99+
marginVertical: 16,
100+
},
101+
sectionTitle: {
102+
fontSize: 18,
103+
fontWeight: '600',
104+
marginBottom: 12,
105+
marginLeft: 16,
106+
color: '#333333',
107+
},
108+
});
109+
110+
export default App;

example/app.json

Lines changed: 0 additions & 30 deletions
This file was deleted.

example/assets/adaptive-icon.png

-17.1 KB
Binary file not shown.

example/assets/favicon.png

-1.43 KB
Binary file not shown.

example/assets/icon.png

-21.9 KB
Binary file not shown.

example/assets/splash-icon.png

-17.1 KB
Binary file not shown.

example/babel.config.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

example/index.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

example/metro.config.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

example/package.json

Lines changed: 0 additions & 25 deletions
This file was deleted.

example/src/App.tsx

Lines changed: 0 additions & 20 deletions
This file was deleted.

example/tsconfig.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)