Skip to content

Commit 5fe901c

Browse files
authored
Merge pull request #24 from SourcePointUSA/DIA-5675-programmatic-reject-all-feature
DIA-5675 Add programatic `rejectAll` and the button for example app
2 parents d773ed2 + d0dab5a commit 5fe901c

File tree

7 files changed

+50
-0
lines changed

7 files changed

+50
-0
lines changed

android/src/main/java/com/sourcepoint/reactnativecmp/RNSourcepointCmpTypes.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import com.sourcepoint.cmplibrary.model.CampaignsEnv.*
66
import com.sourcepoint.cmplibrary.model.exposed.ActionType
77
import com.sourcepoint.cmplibrary.model.exposed.ActionType.*
88
import com.sourcepoint.cmplibrary.model.exposed.TargetingParam
9+
import com.sourcepoint.cmplibrary.data.network.util.CampaignType
10+
import com.sourcepoint.cmplibrary.data.network.util.CampaignType.*
911

1012
fun campaignsEnvFrom(rawValue: String?): CampaignsEnv? =
1113
when (rawValue) {
@@ -14,6 +16,15 @@ fun campaignsEnvFrom(rawValue: String?): CampaignsEnv? =
1416
else -> { null }
1517
}
1618

19+
fun campaignTypeFrom(rawValue: String?): CampaignType =
20+
when (rawValue) {
21+
"gdpr" -> GDPR
22+
"usnat" -> USNAT
23+
"globalcmp" -> GLOBALCMP
24+
"preferences" -> PREFERENCES
25+
else -> { CampaignType.UNKNOWN }
26+
}
27+
1728
data class SPCampaign(
1829
val rawTargetingParam: ReadableMap?,
1930
val supportLegacyUSPString: Boolean,

android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN
158158
}
159159
}
160160

161+
override fun rejectAll(campaignType: String) {
162+
runOnMainThread {
163+
spConsentLib?.rejectAll(campaignTypeFrom(campaignType))
164+
}
165+
}
166+
161167
companion object {
162168
const val NAME = "ReactNativeCmp"
163169
}

example/src/App.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { LaunchArguments } from 'react-native-launch-arguments';
1111

1212
import SPConsentManager, {
1313
SPCampaignEnvironment,
14+
SPCampaignType,
1415
SPMessageLanguage,
1516
} from '@sourcepoint/react-native-cmp';
1617
import type { GDPRConsent, SPCampaigns, SPUserData } from '@sourcepoint/react-native-cmp';
@@ -122,6 +123,11 @@ export default function App() {
122123
consentManager.current?.loadGDPRPrivacyManager(config.gdprPMId);
123124
}, []);
124125

126+
const onRejectAllGDPRPMPress = useCallback(() => {
127+
setSDKStatus(SDKStatus.Networking);
128+
consentManager.current?.rejectAll(SPCampaignType.Gdpr);
129+
}, []);
130+
125131
const onUSNATPMPress = useCallback(() => {
126132
setSDKStatus(SDKStatus.Networking);
127133
consentManager.current?.loadUSNatPrivacyManager(config.usnatPMId);
@@ -202,6 +208,11 @@ export default function App() {
202208
onPress={onGDPRPMPress}
203209
disabled={disable || config.campaigns.gdpr === undefined}
204210
/>
211+
<Button
212+
title="Reject All GDPR"
213+
onPress={onRejectAllGDPRPMPress}
214+
disabled={disable || config.campaigns.gdpr === undefined}
215+
/>
205216
<Button
206217
title="Load USNAT PM"
207218
onPress={onUSNATPMPress}

ios/RNSourcepointCmp.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ import React
109109
}
110110
}
111111

112+
public func rejectAll(_ campaignType: String) {
113+
consentManager?.rejectAll(campaignType: SPCampaignType(rawValue: campaignType == "gdpr" ? "GDPR" : campaignType ))
114+
}
115+
112116
weak var rootViewController: UIViewController? {
113117
UIApplication.shared.delegate?.window??.rootViewController
114118
}

ios/ReactNativeCmp.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ - (void)postDeleteCustomConsentGDPR:(NSArray *)vendors
128128
[sdk postDeleteCustomConsentGDPR:vendors :categories :legIntCategories :callback];
129129
}
130130

131+
- (void)rejectAll:(nonnull NSString *)campaignType {
132+
[sdk rejectAll:campaignType];
133+
}
134+
131135
// MARK: SPDelegate
132136
- (void)onAction:(RNAction*)action {
133137
[self emitInternalOnAction: [action stringifiedJson]];

src/NativeReactNativeCmp.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ export const enum SPCampaignEnvironment {
1313
Stage = 'Stage',
1414
}
1515

16+
export const enum SPCampaignType {
17+
Gdpr = "gdpr",
18+
UsNat = "usnat",
19+
IOS14 = "ios14",
20+
Preferences = "preferences",
21+
GlobalCmp = "globalcmp",
22+
}
23+
1624
export const enum SPMessageLanguage {
1725
ALBANIAN = 'sq',
1826
ARABIC = 'ar',
@@ -233,6 +241,7 @@ export interface Spec extends TurboModule {
233241
legIntCategories: string[],
234242
callback: (consent: GDPRConsent) => void
235243
): void;
244+
rejectAll(campaignType: SPCampaignType): void;
236245

237246
readonly internalOnAction: EventEmitter<string>;
238247
readonly onSPUIReady: EventEmitter<void>;

src/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
SPAction,
77
SPBuildOptions,
88
GDPRConsent,
9+
SPCampaignType,
910
SPError
1011
} from './NativeReactNativeCmp';
1112
import ReactNativeCmp, { SPMessageLanguage } from './NativeReactNativeCmp';
@@ -104,4 +105,8 @@ export default class SPConsentManager implements Spec {
104105
) {
105106
ReactNativeCmp.postDeleteCustomConsentGDPR(vendors, categories, legIntCategories, callback);
106107
}
108+
109+
rejectAll(campaignType: SPCampaignType) {
110+
ReactNativeCmp.rejectAll(campaignType)
111+
}
107112
}

0 commit comments

Comments
 (0)