Skip to content

Commit 9efc79a

Browse files
committed
Adds permanent dismiss functionality
1 parent 1ffca75 commit 9efc79a

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ import PWAPrompt from 'react-ios-pwa-prompt'
3838

3939
4. Add optional props to configure:
4040

41-
- `timesToShow`: pass an integer to configure how many times to show the prompt, will default to 1
42-
- `promptOnVisit`: pass an integer for the when to start showing the prompt, will default to 1 (the first page visit)
43-
- `delay`: pass an integer in ms to add a delay to the prompt
44-
- `copyTitle`: pass a string to customise the title of the prompt
45-
- `copyBody`: pass a string to customise the body of the prompt
46-
- `copyAddHomeButtonLabel`: pass a string to customise label of add to home instruction
47-
- `copyShareButtonLabel`: pass a string to customise label of share button
48-
- `copyClosePrompt`: pass a string to customise label of close button
41+
- `timesToShow`: pass an integer to configure how many times to show the prompt. Defaults to 1.
42+
- `promptOnVisit`: pass an integer for the when to start showing the prompt Defaults to 1 (the first page visit).
43+
- `delay`: pass an integer in ms to add a delay to the prompt. Defaults to 1 second.
44+
- `copyTitle`: pass a string to customise the title of the prompt.
45+
- `copyBody`: pass a string to customise the body of the prompt.
46+
- `copyAddHomeButtonLabel`: pass a string to customise label of add to home instruction.
47+
- `copyShareButtonLabel`: pass a string to customise label of share button.
48+
- `copyClosePrompt`: pass a string to customise label of close button.
49+
- `permanentlyHideOnDismiss`: pass a boolean to configure whether to never show the prompt again once dismissed. Defaults to true (hide forever)
4950

5051
```
5152
<PWAPrompt promptOnVisit={1} timesToShow={3}>

dist/react-ios-pwa-prompt.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/PWAPrompt.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import HomeScreenIcon from "./HomeScreenIcon";
66
import styles from "./PWAPrompt.styles.scss";
77

88
const PWAPrompt = ({
9-
delay,
10-
copyTitle,
11-
copyBody,
12-
copyAddHomeButtonLabel,
13-
copyShareButtonLabel,
14-
copyClosePrompt
15-
}) => {
9+
delay,
10+
copyTitle,
11+
copyBody,
12+
copyAddHomeButtonLabel,
13+
copyShareButtonLabel,
14+
copyClosePrompt,
15+
permanentlyHideOnDismiss,
16+
promptData,
17+
maxVisits
18+
}) => {
1619
useEffect(() => {
1720
if (delay) {
1821
setTimeout(() => setVisibility(true), delay);
@@ -28,6 +31,15 @@ const PWAPrompt = ({
2831

2932
const dismissPrompt = () => {
3033
setVisibility(false);
34+
if (permanentlyHideOnDismiss) {
35+
localStorage.setItem(
36+
"iosPwaPrompt",
37+
JSON.stringify({
38+
...promptData,
39+
visits: maxVisits
40+
})
41+
);
42+
}
3143
};
3244

3345
return (
@@ -49,7 +61,7 @@ const PWAPrompt = ({
4961
{copyTitle || `Add to Home Screen`}
5062
</p>
5163
<button className={styles.pwaPromptCancel} onClick={dismissPrompt}>
52-
{copyClosePrompt || 'Cancel'}
64+
{copyClosePrompt || "Cancel"}
5365
</button>
5466
</div>
5567
<div className={styles.pwaPromptBody}>

src/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const deviceCheck = () => {
1515
export default ({
1616
timesToShow = 1,
1717
promptOnVisit = 1,
18+
permanentlyHideOnDismiss = true,
1819
copyTitle = undefined,
1920
copyBody = undefined,
2021
copyAddHomeButtonLabel = undefined,
@@ -51,6 +52,9 @@ export default ({
5152
copyAddHomeButtonLabel={copyAddHomeButtonLabel}
5253
copyShareButtonLabel={copyShareButtonLabel}
5354
copyClosePrompt={copyClosePrompt}
55+
permanentlyHideOnDismiss={permanentlyHideOnDismiss}
56+
promptData={promptData}
57+
maxVisits={timesToShow + promptOnVisit}
5458
/>
5559
);
5660
}

0 commit comments

Comments
 (0)