File tree 4 files changed +34
-17
lines changed
4 files changed +34
-17
lines changed Original file line number Diff line number Diff line change @@ -38,14 +38,15 @@ import PWAPrompt from 'react-ios-pwa-prompt'
38
38
39
39
4 . Add optional props to configure:
40
40
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)
49
50
50
51
```
51
52
<PWAPrompt promptOnVisit={1} timesToShow={3}>
Original file line number Diff line number Diff line change @@ -6,13 +6,16 @@ import HomeScreenIcon from "./HomeScreenIcon";
6
6
import styles from "./PWAPrompt.styles.scss" ;
7
7
8
8
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
+ } ) => {
16
19
useEffect ( ( ) => {
17
20
if ( delay ) {
18
21
setTimeout ( ( ) => setVisibility ( true ) , delay ) ;
@@ -28,6 +31,15 @@ const PWAPrompt = ({
28
31
29
32
const dismissPrompt = ( ) => {
30
33
setVisibility ( false ) ;
34
+ if ( permanentlyHideOnDismiss ) {
35
+ localStorage . setItem (
36
+ "iosPwaPrompt" ,
37
+ JSON . stringify ( {
38
+ ...promptData ,
39
+ visits : maxVisits
40
+ } )
41
+ ) ;
42
+ }
31
43
} ;
32
44
33
45
return (
@@ -49,7 +61,7 @@ const PWAPrompt = ({
49
61
{ copyTitle || `Add to Home Screen` }
50
62
</ p >
51
63
< button className = { styles . pwaPromptCancel } onClick = { dismissPrompt } >
52
- { copyClosePrompt || ' Cancel' }
64
+ { copyClosePrompt || " Cancel" }
53
65
</ button >
54
66
</ div >
55
67
< div className = { styles . pwaPromptBody } >
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ const deviceCheck = () => {
15
15
export default ( {
16
16
timesToShow = 1 ,
17
17
promptOnVisit = 1 ,
18
+ permanentlyHideOnDismiss = true ,
18
19
copyTitle = undefined ,
19
20
copyBody = undefined ,
20
21
copyAddHomeButtonLabel = undefined ,
@@ -51,6 +52,9 @@ export default ({
51
52
copyAddHomeButtonLabel = { copyAddHomeButtonLabel }
52
53
copyShareButtonLabel = { copyShareButtonLabel }
53
54
copyClosePrompt = { copyClosePrompt }
55
+ permanentlyHideOnDismiss = { permanentlyHideOnDismiss }
56
+ promptData = { promptData }
57
+ maxVisits = { timesToShow + promptOnVisit }
54
58
/>
55
59
) ;
56
60
}
You can’t perform that action at this time.
0 commit comments