npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-google-address-validation

v1.2.7

Published

Provides a workflow to collect and validate user addresses using Google's Places and Address Validation APIs in React Native

Downloads

52

Readme

React Native Google Address Validation

React Native component for user address input, auto complete, and address validation using Google's Places and Address Valdation API's

Getting Started

Installation

yarn add react-native-google-address-validation

or

npm install react-native-google-address-validation --save

Acquire Google API keys

You need a Google Places API Key and a Google Address Validation API Key. Enable Web services for both (not IOS or Android). You can generate one key that has access to both API's, or two separate keys, whichever works best for your project.

Usage

Wrap your root component in the ReactNativeGoogleAddressValidationPortalProvider from react-native-google-address-validation.

It's required for the autocomplete to function correctly on both IOS and Android.

import { ReactNativeGoogleAddressValidationPortalProvider } from "react-native-google-address-validation";
import App from "./src/App";

export default function App() {
  return (
    <ReactNativeGoogleAddressValidationPortalProvider>
      <App />
    </ReactNativeGoogleAddressValidationPortalProvider>
  );
}

Basic Example

Once you have the provider in place wrapping your app, you can use the AddressValidation component anywhere you want in your app, though it will look best if it's the primary focus on the screen.

import {
  AddressValidation,
  Address,
} from "react-native-google-address-validation";

export const UserInputAddressScreen = () => {
  const [address, setAddress] =
    useState <
    Address >
    {
      streetOne: "",
      streetTwo: "",
      locality: "",
      administrativeArea: "",
      postalCode: "",
      regionCode: "US",
    };

  return (
    <StyledAddressForm
      address={{
        streetOne: address.streetOne,
        streetTwo: address.streetTwo ?? "",
        locality: address.city,
        administrativeArea: address.state,
        postalCode: address.postalCode,
        regionCode: address.regionCode,
      }}
      onChange={(updatedAddress) => setAddress(updatedAddress)}
      onFinish={(confirmedAddress) => console.log(confirmedAddress)}
      googlePlacesApiKey={GOOGLE_PLACES_KEY}
      googleAddressValidationApiKey={GOOGLE_ADDRESS_VALIDATION_KEY}
    />
  );
};

One thing to remember here, is that the onChange returns an in-progress address, which has a regionCode, see type Address. Once the address has been validated by Google and confirmed by the user, it becomes type FormattedAddress with a country instead of a region code, which could be formatted by google differently than a strict region code.

Customization

Styles and content can be customized so that colors of the workflow match your app's theme and tone. You can see all available props here

import {
  AddressValidation,
  Address,
} from "react-native-google-address-validation";

export const UserInputAddressScreen = () => {
  const [address, setAddress] =
    useState <
    Address >
    {
      streetOne: "",
      streetTwo: "",
      locality: "",
      administrativeArea: "",
      postalCode: "",
      regionCode: "US",
    };

  return (
    <StyledAddressForm
      address={{
        streetOne: address.streetOne,
        streetTwo: address.streetTwo ?? "",
        locality: address.city,
        administrativeArea: address.state,
        postalCode: address.postalCode,
        regionCode: address.regionCode,
      }}
      onChange={(updatedAddress) => setAddress(updatedAddress)}
      onFinish={(confirmedAddress) => console.log(confirmedAddress)}
      googlePlacesApiKey={GOOGLE_PLACES_KEY}
      googleAddressValidationApiKey={GOOGLE_ADDRESS_VALIDATION_KEY}
      regionCodes={["US"]}
      // label & content customization
      streetOneLabel="Home sweet home"
      streetOnePlaceholder="Your home street address"
      streetTwoLabel="Line 2 of your home address"
      streetTwoPlaceholder="The Planet Hoth"
      localityLabel="City or Munucipality"
      localityPlaceholder="Tosche Station"
      administrativeAreaLabel="State/Region"
      administrativeAreaPlaceholder="The Northlands"
      postalCodeLabel="Zip code"
      postalCodePlaceholder="zip zip zip"
      regionCodeLabel="Country/Nation"
      continueLabel="Tatooine"
      // Theming Options
      primaryColor="royalblue"
      successColor="green"
      dangerColor="crimson"
      warningColor="orange"
      backgroundColor="#FFF"
      textColor="#000"
      textLightColor="#FFF"
      disabledColor="grey"
      neutralColor="#e6e6e6"
      placeholderColor="#E6E6E6"
    />
  );
};

The region codes filter enables the ability to choose which countries show up in the country dropdown. It is optional, not including it (see basic example) will have ALL the countries in the country/region dropdown.

Screenshots

Images of this library in use in production

Address Form

address form

Address Auto Completion

address auto completion

Address Confirmation

address confirmation