@@ -12,6 +12,7 @@ export interface Props {
1212
1313export interface State {
1414 isSubscribed : boolean ;
15+ unSubscribedWhenNotificationDisabled : boolean ;
1516 isLocationShared : boolean ;
1617 provideUserConsent : boolean ;
1718 requireUserConsent : boolean ;
@@ -26,6 +27,7 @@ class OSButtons extends React.Component<Props, State> {
2627
2728 this . state = {
2829 isSubscribed : subscribeFields . isSubscribed ,
30+ unSubscribedWhenNotificationDisabled : true ,
2931 isLocationShared : true ,
3032 provideUserConsent : false ,
3133 requireUserConsent : false ,
@@ -42,7 +44,7 @@ class OSButtons extends React.Component<Props, State> {
4244 createSubscribeFields ( ) {
4345 const { subscribeFields, loggingFunction } = this . props ;
4446 const { isSubscribed } = subscribeFields ;
45- const { isLocationShared } = this . state ;
47+ const { unSubscribedWhenNotificationDisabled , isLocationShared } = this . state ;
4648 const color = '#D45653' ;
4749 const elements = [ ] ;
4850
@@ -54,6 +56,16 @@ class OSButtons extends React.Component<Props, State> {
5456 OneSignal . disablePush ( isSubscribed ) ;
5557 }
5658 ) ;
59+
60+ const unsubscribeWhenNotificationsAreDisabledButton = renderButtonView (
61+ unSubscribedWhenNotificationDisabled ? "Unsubscribe When Notifications Disabled" : "Subscribe when notification disabled" ,
62+ color ,
63+ ( ) => {
64+ loggingFunction ( `Is application unsubscribed when notification disabled: ${ unSubscribedWhenNotificationDisabled } ` ) ;
65+ OneSignal . unsubscribeWhenNotificationsAreDisabled ( unSubscribedWhenNotificationDisabled ) ;
66+ this . setState ( { unSubscribedWhenNotificationDisabled : ! unSubscribedWhenNotificationDisabled } ) ;
67+ }
68+ ) ;
5769
5870 const promptForPush = renderButtonView (
5971 "Prompt for Push" ,
@@ -90,7 +102,7 @@ class OSButtons extends React.Component<Props, State> {
90102 }
91103 ) ;
92104
93- elements . push ( subscribedButton , locationShared , setLocationShared , promptLocationButton ) ;
105+ elements . push ( subscribedButton , unsubscribeWhenNotificationsAreDisabledButton , locationShared , setLocationShared , promptLocationButton ) ;
94106
95107 if ( Platform . OS === 'ios' ) {
96108 elements . push ( promptForPush ) ;
0 commit comments