Skip to content

Commit a69f9d4

Browse files
committed
Add programatic rejectAll and the button for example app
1 parent 9c28f0e commit a69f9d4

File tree

7 files changed

+51
-0
lines changed

7 files changed

+51
-0
lines changed

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

Lines changed: 12 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,16 @@ fun campaignsEnvFrom(rawValue: String?): CampaignsEnv? =
1416
else -> { null }
1517
}
1618

19+
fun campaignTypeFrom(rawValue: String?): CampaignType =
20+
when (rawValue) {
21+
"GDPR" -> GDPR
22+
"CCPA" -> CCPA
23+
"usnat" -> USNAT
24+
"ios14" -> GLOBALCMP
25+
"preferences" -> PREFERENCES
26+
else -> { CampaignType.UNKNOWN }
27+
}
28+
1729
data class SPCampaign(
1830
val rawTargetingParam: ReadableMap?,
1931
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
@@ -159,6 +159,12 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN
159159
}
160160
}
161161

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

example/src/App.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ export default function App() {
114114
consentManager.current?.loadGDPRPrivacyManager(config.gdprPMId);
115115
}, []);
116116

117+
const onRejectAllGDPRPMPress = useCallback(() => {
118+
setSDKStatus(SDKStatus.Networking);
119+
consentManager.current?.rejectAll(SPCampaignType.Gdpr);
120+
}, []);
121+
117122
const onUSNATPMPress = useCallback(() => {
118123
setSDKStatus(SDKStatus.Networking);
119124
consentManager.current?.loadUSNatPrivacyManager(config.usnatPMId);
@@ -194,6 +199,11 @@ export default function App() {
194199
onPress={onGDPRPMPress}
195200
disabled={disable || config.campaigns.gdpr === undefined}
196201
/>
202+
<Button
203+
title="Reject All GDPR"
204+
onPress={onRejectAllGDPRPMPress}
205+
disabled={disable || config.campaigns.gdpr === undefined}
206+
/>
197207
<Button
198208
title="Load USNAT PM"
199209
onPress={onUSNATPMPress}

ios/RNSourcepointCmp.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ import React
9999
}
100100
}
101101

102+
public func rejectAll(_ campaignType: String) {
103+
consentManager?.rejectAll(campaignType: SPCampaignType(rawValue: campaignType))
104+
}
105+
102106
weak var rootViewController: UIViewController? {
103107
UIApplication.shared.delegate?.window??.rootViewController
104108
}

ios/ReactNativeCmp.mm

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

126+
- (void)rejectAll:(nonnull NSString *)campaignType {
127+
[sdk rejectAll:campaignType];
128+
}
129+
126130
// MARK: SPDelegate
127131
- (void)onAction:(RNAction*)action {
128132
[self emitOnAction: [action toDictionary]];

src/NativeReactNativeCmp.ts

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

16+
export const enum SPCampaignType {
17+
Gdpr = "GDPR",
18+
Ccpa = "CCPA",
19+
UsNat = "usnat",
20+
IOS14 = "ios14",
21+
Preferences = "preferences",
22+
GlobalCmp = "globalcmp",
23+
}
24+
1625
export const enum SPMessageLanguage {
1726
ALBANIAN = 'sq',
1827
ARABIC = 'ar',
@@ -228,6 +237,7 @@ export interface Spec extends TurboModule {
228237
legIntCategories: string[],
229238
callback: (consent: GDPRConsent) => void
230239
): void;
240+
rejectAll(campaignType: SPCampaignType): void;
231241

232242
readonly onAction: EventEmitter<SPAction>;
233243
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
} from './NativeReactNativeCmp';
1011
import ReactNativeCmp, { SPMessageLanguage } from './NativeReactNativeCmp';
1112
import type { EventEmitter } from 'react-native/Libraries/Types/CodegenTypes';
@@ -78,6 +79,10 @@ export default class SPConsentManager implements Spec {
7879
ReactNativeCmp.postDeleteCustomConsentGDPR(vendors, categories, legIntCategories, callback);
7980
}
8081

82+
rejectAll(campaignType: SPCampaignType) {
83+
ReactNativeCmp.rejectAll(campaignType)
84+
}
85+
8186
onAction: EventEmitter<SPAction> = ReactNativeCmp.onAction;
8287
onSPUIReady: EventEmitter<void> = ReactNativeCmp.onSPUIReady;
8388
onSPUIFinished: EventEmitter<void> = ReactNativeCmp.onSPUIFinished;

0 commit comments

Comments
 (0)