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

ionic-react-pwa-install

v1.0.2

Published

[![npm package][npm-badge]][npm] ![npm][npm-downloads]

Downloads

1

Readme

Ionic React PWA Install

npm package npm

Install handler for Ionic React PWA applications.

Installing a PWA applications (i.e. add to home screen) are handled differently by the different browser applications and devices being used. Currently Chrome, Edge and Samsung browsers support this natively and this can be captured and handled via the beforeinstallpromptevent. On iOS devices, Firefox Mobile or Opera mobile the application has to be install manually via the browser menu options. This can make it very hard to develop a consistent experience for users a PWA application using different browsers and applications.

A number PWA helper packages have been developed to alleviate this situation and this one is intended to support Ionic PWA application installations.

What this package does

This package provides a simple way to add a installer for Ionic PWA applications. It provides:

  • information if this applications natively supports a PWA installation
  • an interface function to call the installer or display instructions on how to do this.

Demo and Example

To view the demo visit - https://ionic-react-pwa-demo.netlify.com.

To see the demo source code see - https://github.com/drffej/ionic-react-pwa-install-demo.

Installation

To use the package, this assumes you will be using Ionic as the UI

$ npm i --save ionic-react-pwa-install 

Usage

  1. Import IonicPWAInstallProvider and useIonicPWAInstall
  2. Wrap your App with the IonicPWAInstallProvider.
  3. useIonicPWAInstall returns the following interface:
type IonicPWAInstallInterface = {
  isSupported: boolean;  // returns true if platform specific installer is supported
  isInstalled: boolean;  // returns true if application is running as an app windows
  platform : string  // returns platform type one of 'native', 'other', 'firefox', 'idevice', 'opera'
  pwaInstall : () => Promise<boolean> | null   // call the platform specific installer or display instructions
}
  1. Use the supported and isInstalled ( from useReactPWAInstall) functions to determine whether to show the appropriate Install button (or banner,popup,etc...)
  2. Call pwaInstall depending on the value of supported and isInstalled .
import { useIonicPWAInstall, IonicPWAInstallProvider}  from 'ionic-react-pwa-install'
const App: React.FC = () => {
  
  const { isSupported, isInstalled, platform, pwaInstall, pwaManualInstall} = useIonicPWAInstall()!

  return (
    <IonApp>
      <IonPage>
        <IonHeader>
          <IonToolbar>
            <IonTitle>Ionic PWA Demo</IonTitle>
          </IonToolbar>
        </IonHeader>
        <IonContent class="ion-padding">
          <h1>PWA Data</h1>
          <p>Is install prompt available? { isSupported ? 'true' : 'false'}</p> 
          <p>Is installed? {isInstalled ? 'true' : 'false'}</p>
          <p>Platform? {platform}</p>
          {(isSupported && !isInstalled) &&
          
            <IonButton onClick={pwaInstall}>Install supported</IonButton>
          }
        </IonContent>
      </IonPage>
    </IonApp>
)};

const container = document.getElementById('root');
const root = createRoot(container!);
root.render(
  <React.StrictMode>
   <IonicPWAInstallProvider>
      <App />
   </IonicPWAInstallProvider>
  </React.StrictMode>
);

Interface Details

  • IonicPWAInstallProvider: Context provider, required.
  • useIonicPWAInstall: React hook that provides pwaInstall, iSupported, isInstalled and platform
  • isSupported: Helper to decide if the install button should be shown to the user. Returns true in 2 cases:
  • isInstalled: Helper to decide if the install button should be shown to the user. Returns true if the user is currently visiting the site from the installed 'standalone' app.
  • platform : Help to decide what platform is being used
  • pwaInstall: Will open the installation dialog according to the user's platform. This function returns a promise. The promise is returns False if the user cancels the native installation process. The promise returns True when the native installation was successful. For manual installs, it will open instructions to show to how to manually install the PWA application

The following logic can be used to help decide what dialog box to call

isSupported | isInstalled | platform | Action :-------------|:--------------|:-----------|:------ TRUE | FALSE | native | Native installation available via pwaInstall. TRUE | TRUE | native | Site running as standalone app, no action. TRUE | FALSE | pwasafari, firefox or idevice or opera | Manual installation available, display instructions via pwaInstall.

Further Reading

For more information see this guide about how to promote PWA installation from an Ionic PWA. See pwa is installable on the criteria to get the installation prompt.

Acknowledgements

A lot of the package ideas and some of the code is based on the react-pwa-install package. See https://github.com/zoltangy/react-pwa-install for details.

The main differences are:

  • Uses Typescript
  • Uses Vite as the bundler
  • Use Ionic UI instead of material UI
  • Exposes the platform type