All Projects → AppAndFlow → react-native-google-autocomplete

AppAndFlow / react-native-google-autocomplete

Licence: MIT license
A react-native component with render props around the Google Autocomplete Api

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-native-google-autocomplete

zero
📦 A zero config scripts library
Stars: ✭ 17 (-83.5%)
Mutual labels:  rollup
vue-frag-plugin
Webpack/Rollup/Vite plugin to add multiple root-node support to Vue 2 SFCs
Stars: ✭ 37 (-64.08%)
Mutual labels:  rollup
rollup-plugin-swc
Rollup plugin to compile bundles with the SWC.
Stars: ✭ 59 (-42.72%)
Mutual labels:  rollup
manager
OVHcloud Control Panel
Stars: ✭ 153 (+48.54%)
Mutual labels:  rollup
rollup-jest-boilerplate
🎉 Full featured boilerplate for building JavaScript libraries the modern way
Stars: ✭ 81 (-21.36%)
Mutual labels:  rollup
npm-es-modules
Breakdown of 7 different ways to use ES modules with npm today.
Stars: ✭ 67 (-34.95%)
Mutual labels:  rollup
rollup-plugin-jscc
Conditional compilation and compile-time variable replacement for Rollup
Stars: ✭ 52 (-49.51%)
Mutual labels:  rollup
react-sheltr
Shared element transition helper components for React
Stars: ✭ 33 (-67.96%)
Mutual labels:  render-props
fly-helper
It's a Tool library, method collection
Stars: ✭ 21 (-79.61%)
Mutual labels:  rollup
r1cs-tutorial
Tutorial for writing constraints in the `arkworks` framework
Stars: ✭ 74 (-28.16%)
Mutual labels:  rollup
render-props
Easily and reliably support Render Props, Component Injection, and Function as a Child
Stars: ✭ 82 (-20.39%)
Mutual labels:  render-props
react-treefold
A renderless tree component for your hierarchical React views
Stars: ✭ 37 (-64.08%)
Mutual labels:  render-props
rocket
The modern web setup for static sites with a sprinkle of JavaScript
Stars: ✭ 169 (+64.08%)
Mutual labels:  rollup
magic-scroll
Apple Magic Mouse scrolling effect for normal mouses
Stars: ✭ 43 (-58.25%)
Mutual labels:  rollup
rollup-loader
Rollup does what it can do, and let Webpack finish the job.
Stars: ✭ 86 (-16.5%)
Mutual labels:  rollup
squeezy
1 kB React component for accessible accordions / collapse UI
Stars: ✭ 31 (-69.9%)
Mutual labels:  render-props
vue-methods-promise
Let Vue methods support return Promise
Stars: ✭ 35 (-66.02%)
Mutual labels:  rollup
rollup-plugin-tagged-template
Use plain HTML files as tagged templates.
Stars: ✭ 24 (-76.7%)
Mutual labels:  rollup
ts-react-boilerplate
Chrome extension boilerplate with TypeScript and React
Stars: ✭ 53 (-48.54%)
Mutual labels:  rollup
unplugin-vue
✨ Transform Vue 3 SFC to JavaScript. Supports Vite, esbuild, Rollup and Webpack.
Stars: ✭ 38 (-63.11%)
Mutual labels:  rollup

React-Native-Google-Autocomplete

Using render props to make google autocomplete work nicely with any design.

Installation

yarn add react-native-google-autocomplete

Props

Props Descriptions
apiKey Your api key get from https://developers.google.com/places/documentation
debounce optional - default 300
language optional - default en
queryTypes optional - default address - https://developers.google.com/places/web-service/autocomplete#place_types
minLength optional - default 2 - this is the min length of the term search before start
components optional - A grouping of places to which you would like to restrict your results.
radius optional - The distance (in meters) within which to return place results.
lat optional - The latitude. If provide lng is required
lng optional - The longitue. If provide lat is required

Render Props

Props Descriptions
inputValue A string you can put to your input for controlled input
handleTextChange most important function this is the callback for the text change just put it inside your TextInput
locationResults The array result
fetchDetails Http call when you have the place_id, good when you want to get more info after click an item
isSearching Boolean if search is on
clearSearch Clear the search result, can be nice when you have a clear button next to your text input

*(clearSearch was previously clearSearchs)

Results

The locationResults give you this. The maximum result set by Google is 5 location by query.

export interface GoogleLocationResult {
  description: string;
  id: string;
  matched_substrings: Array<{
    length: number;
    offset: number;
  }>;
  place_id: string;
  reference: string;
  structured_formatting: {
    main_text: string;
    secondary_text: string;
    main_text_matched_substrings: Array<{
      length: number;
    }>;
  };
  terms: Array<{
    offset: number;
    value: string;
  }>;
  types: string[];
}

When call the fetchDetails this is what you got

export interface GoogleLocationDetailResult {
  adr_address: string;
  formatted_address: string;
  icon: string;
  id: string;
  name: string;
  place_id: string;
  scope: string;
  reference: string;
  url: string;
  utc_offset: number;
  vicinity: string;
  types: string[];
  geometry: {
    location: {
      lat: number;
      lng: number;
    };
    viewport: {
      [type: string]: {
        lat: number;
        lng: number;
      };
    };
  };
  address_components: Array<{
    long_name: string;
    short_name: string;
    types: string[];
  }>;
}

Examples

import { GoogleAutoComplete } from 'react-native-google-autocomplete';

function MyComponent() {
  return (
    <GoogleAutoComplete apiKey="YOUR API KEY" debounce={300}>
      {({ inputValue, handleTextChange, locationResults, fetchDetails }) => (
        <React.Fragment>
          <TextInput
            style={{
              height: 40,
              width: 300,
              borderWidth: 1,
              paddingHorizontal: 16,
            }}
            value={inputValue}
            onChangeText={handleTextChange}
            placeholder="Location..."
          />
          <ScrollView style={{ maxHeight: 100 }}>
            {locationResults.map((el, i) => (
              <LocationItem
                {...el}
                fetchDetails={fetchDetails}
                key={String(i)}
              />
            ))}
          </ScrollView>
        </React.Fragment>
      )}
    </GoogleAutoComplete>
  );
}

Typings

You can import both result typing if you need for flow or typescript.

import { GoogleLocationDetailResult, GoogleLocationResult } from 'react-native-google-autocomplete';

Restrict by country

If you want to restrict the search by country you can add this as a props components="country:ca". This here would example restrict it to Canada only.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].