Giter Club home page Giter Club logo

react-ios-pwa-prompt's Introduction

React-iOS-PWA-prompt

npm version Gzip file size

Polyfilling PWAs for iOS

A React component that provides a customisable Progressive Web App (PWA) prompt telling the user to 'Add to Home Screen'. The prompt behaviour is baked in to Android devices, yet iOS is still lagging behind. This component aims to provide a simple way to provide this functionality on iOS for websites that are PWA-ready. The prompt styles closely match iOS designs for both light and dark UI modes to appear native to the user.



Features

  • ๐Ÿ›  Fully configurable, set how many times you want to see it, and after how many page visits.
  • ๐Ÿ“ƒ PWA available offline? In full screen mode? Customise the content of your prompts message through props.
  • โšก๏ธ Efficient. Very little overhead for non-iOS devices and does as little work as needed for each page load.
  • ๐ŸŒ• Light & dark mode available depending on user's settings.

Usage

  1. Add react-ios-pwa-prompt as a dependency using pnpm add react-ios-pwa-prompt.

  2. Import into your project:

import PWAPrompt from 'react-ios-pwa-prompt'
  1. Render the component:
<PWAPrompt />
  1. Add optional props to configure:
Prop Description Default Value
timesToShow Number of consecutive visits to show the prompt 2
promptOnVisit On which visit should the first prompt be shown? 2
delay Pass an integer in ms to add a delay to the prompt 1000
onClose Callback function for once the prompt is dismisseed () => undefined
copyTitle The title of the prompt Add to Home Screen
copySubtitle The subtitle of the prompt String(window.location.href)
copyDescription The description of the prompt This website has app functionality. Add it to your home screen to use it in fullscreen and while offline.
copyShareStep The Share button copy Press the 'Share' button on the menu bar below
copyAddToHomescreenStep The Add To Homescreen button copy Press 'Add to Home Screen'
appIconPath Path to an icon or favicon to be shown as the app icon https://s2.googleusercontent.com/s2/favicons?domain=${window.location.origin}
isShown Can be set to true to manually show the prompt undefined
<PWAPrompt promptOnVisit={1} timesToShow={1} copyClosePrompt="Close" />
  1. Create your own trigger rules You can easily set your own trigger conditions if you don't like the consecutive page loads approach. For example:
const [shouldShowPWAPrompt, setShouldShowPWAPrompt] = useState(false)

useEffect(() => {
    // 20% chance of popping up
    setShouldShowPWAPrompt(Math.random() < 0.2)
}, [])

return (
    <PWAPrompt isShown={shouldShowPWAPrompt} />
)

react-ios-pwa-prompt's People

Contributors

chrisdancee avatar dependabot[bot] avatar fastfedora avatar hiramhuang avatar kffl avatar konradhalo avatar moecre avatar tannerkrewson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-ios-pwa-prompt's Issues

Add possibility to translate every prompt string

Currently, we can translate the title and body of the prompt, but texts used for steps description are not translatable. I am talking about these two:
1) Press the 'Share' button
2) Press 'Add to Home Screen'

It would be great to pass them to a component as props like title and body of the prompt and set defaults to what you guys have in the code already.

Thanks.

Misc. visual feedback

Hi, very nice plugin / package. Saved me for a lot of work :)
A few suggestions on ux and ui:

  1. Have a bit more contrast on the text, at least the text for the steps.
  2. The Share and Add icons in the steps look very clickable. During a quick user test they tried clicking the icons in the popup instead of the share button below (on mobile). Maybe move them after the text could help? Maybe direct the user to the real share button somehow? Not sure.
  3. For debugging and testing it would be useful with a prop that forces it to show, no matter OS or state.

Again, great work, and if you add a donate button somewhere, I'm sure people will use it ;)

Cheers,
Nix

Open prop for manual prompt

Greetings, nice work, clean and beautiful.

I think i don't know how to work with this...
I've read the document, even the code of the module itself, but i don't get it. how am i supposed to open this manually?
I have an "Add to homescreen" button in my profile menu, it works fine for any device except ios as you know, i want to open it for ios manually yet i can't.
I thought maybe an open property (Like Material UI compoents) would be nice and easy to use...

Does not work with SSR

I get a "ReferenceError: window is not defined" when I try to import PWAPrompt from 'react-ios-pwa-prompt';

I believe this an issue with SSR in next.js. Is it possible to execute deviceCheck() after the component has been mounted?

Thanks.

Export logic for determining whether the prompt should be shown

If this logic is exported, developers can implement code-splitting for this component and thus avoid loading any additional data (the prompt, icons, and styles) unless it is actually needed.

For example:

import React, { Suspense } from 'react';
import { shouldShowPrompt } from 'react-ios-pwa-prompt';

const LazyPWAPrompt = React.lazy(() => import('react-ios-pwa-prompt'));

function App() {
    const options = {
        timesToShow: 1,
        promptOnVisit: 2,
    };

    return (
        <>
            {shouldShowPrompt(options) && (
                <Suspense fallback={null}>
                    <LazyPWAPrompt {...options} />
                </Suspense>
            )}
        </>
    );
}

@chrisdancee If this sounds like a good idea, I'll open a PR!

iOS 14 detection

Hello everyone! I have to say, this library has great look and feel with superb attention to detail.

I was giving it a try this week and realized that it doesn't detect iOS 14 properly. The prompt uses pre-13 icons and is not influenced by the os's theme, take a look:

iOS14-prompt-ss_04

I've prepared a little demo to demonstrate this issue: https://react-ios-pwa-prompt-example.netlify.app (source)

Does not support iOS 14 styles

iOS 14 styles look slightly different. They don't use transparency, or blur filters, and have no margin at the prompt edges. The prompt should be update to support these styles.

Match iOS13 styles for prompt header

iOS13 released a new header style for the sharing options. This style could be matched for the prompt. Including the favicon, site name and the close button.

image

detect iPad in iOS 13

navigator.platform for iPad in iOS13 reports as "MacIntel". This is one hack to detect it by checking for touch screen

navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1

Override Color Values?

On the current iOS 13 Dark mode, the PWA prompt has very poor contrast (see screenshot attached). Would it possible to override these color values? Traditional CSS overrides aren't working because you're using StyledComponents.

Screen Shot 2020-04-15 at 2 02 32 AM

Component appears as Anonymous and does not work

Imported the component per the provided instructions, but it does not function at all.

On react components inspection I can see an 'Anonymous' component instead of PWAPrompt.

Does not fire on iOS (iPhone / iPad) or on a faked user agent.

ReferenceError: document is not defined

Love how you have come up with this solution to the problem of adding to home screen with IOS devices. I guess Apple really does not like the PWA as they could potentially be taking away that cash cow of revenue from their app store. But I am having a slight issue with it. Go easy on me. Newbee ;)

I am using this in a Next project.

npm i react-ios-pwa-prompt

then

import PWAPrompt from 'react-ios-pwa-prompt'

then put it in with my index,js code

     '<PWAPrompt />'

the '' are only there to show what I had coded...it would not show up in query otherwise.
getting this in response:

Server Error
ReferenceError: document is not defined

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
s
file:///C:/Users/jscha/Desktop/swim/node_modules/react-ios-pwa-prompt/dist/react-ios-pwa-prompt.js (1:2222)
v
file:///C:/Users/jscha/Desktop/swim/node_modules/react-ios-pwa-prompt/dist/react-ios-pwa-prompt.js (1:3463)
l
file:///C:/Users/jscha/Desktop/swim/node_modules/react-ios-pwa-prompt/dist/react-ios-pwa-prompt.js (1:2161)
e.exports
file:///C:/Users/jscha/Desktop/swim/node_modules/react-ios-pwa-prompt/dist/react-ios-pwa-prompt.js (1:3795)
Object.
file:///C:/Users/jscha/Desktop/swim/node_modules/react-ios-pwa-prompt/dist/react-ios-pwa-prompt.js (1:1410)
r
file:///C:/Users/jscha/Desktop/swim/node_modules/react-ios-pwa-prompt/dist/react-ios-pwa-prompt.js (1:432)
Module.
file:///C:/Users/jscha/Desktop/swim/node_modules/react-ios-pwa-prompt/dist/react-ios-pwa-prompt.js (1:12225)
r
file:///C:/Users/jscha/Desktop/swim/node_modules/react-ios-pwa-prompt/dist/react-ios-pwa-prompt.js (1:432)

file:///C:/Users/jscha/Desktop/swim/node_modules/react-ios-pwa-prompt/dist/react-ios-pwa-prompt.js (1:1237)

file:///C:/Users/jscha/Desktop/swim/node_modules/react-ios-pwa-prompt/dist/react-ios-pwa-prompt.js (1:1246)

Any advice?

Cheers Joel

Add tests

Tests should be added to detect any issues with code contributions

Should be able to dismiss permanently

It was raised that a user should be able to dismiss the prompt indefinitely (for example if they're not interested, or if they have installed the app as a PWA).

Why so complex classNames?

There is no way to customizate it out of component. I'm building PWA App that is forced to landscape mode via styles.

Could extra styles be given via props?

iOS Chrome and Firefox display prompt

Hey, great project, looks great on the devices I've tested it on.

I thought it was worth noting though that Apple only allows the "Add to Homescreen" feature when using Safari.

The prompt, however, displays on iOS Chrome and Firefox as well which could be confusing for a user as they won't be able to install the PWA without switching to Safari first.

A couple of options:

a) only show the prompt in Safari
b) add the ability to provide different copy depending on the browser

cheers

Add promptOniPad prop

A suggestion was made by @chown9835 to add a promptOnIpad prop in order to hide the prompt for iPad users. Seems like it could be a useful feature.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.