Skip to content

Commit df1b6b1

Browse files
committed
Add loadPreferenceCenter and the button for example app
1 parent 637057a commit df1b6b1

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN
110110
runOnMainThread { spConsentLib?.loadPrivacyManager(pmId, GLOBALCMP) }
111111
}
112112

113+
override fun loadPreferenceCenter(id: String) {
114+
runOnMainThread { spConsentLib?.loadPrivacyManager(id, PREFERENCES) }
115+
}
116+
113117
companion object {
114118
const val NAME = "ReactNativeCmp"
115119
}

example/src/App.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const config = {
3434
gdprPMId: '488393',
3535
usnatPMId: '988851',
3636
globalCmpPMId: '1323762',
37+
preferencesCenterId: '1306779',
3738
campaigns: {
3839
gdpr: {},
3940
usnat: { supportLegacyUSPString: true },
@@ -115,6 +116,11 @@ export default function App() {
115116
consentManager.current?.loadGlobalCmpPrivacyManager(config.globalCmpPMId);
116117
}, []);
117118

119+
const onPreferencesPress = useCallback(() => {
120+
setSDKStatus(SDKStatus.Networking);
121+
consentManager.current?.loadPreferenceCenter(config.preferencesCenterId);
122+
}, []);
123+
118124
const onClearDataPress = useCallback(() => {
119125
consentManager.current?.clearLocalData();
120126
consentManager.current?.build(
@@ -165,6 +171,11 @@ export default function App() {
165171
onPress={onGlobalCMPPress}
166172
disabled={disable || config.campaigns.globalcmp == undefined}
167173
/>
174+
<Button
175+
title="Load Preferences Center"
176+
onPress={onPreferencesPress}
177+
disabled={disable || config.campaigns.preferences == undefined}
178+
/>
168179
<Button title="Clear All" onPress={onClearDataPress} />
169180
<Text testID="sdkStatus" style={styles.status}>
170181
{sdkStatus}

ios/RNSourcepointCmp.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ import React
7272
consentManager?.loadGlobalCmpPrivacyManager(withId: pmId)
7373
}
7474

75+
public func loadPreferenceCenter(_ id: String)
76+
{
77+
consentManager?.loadPreferenceCenter(withId: id)
78+
}
79+
7580
weak var rootViewController: UIViewController? {
7681
UIApplication.shared.delegate?.window??.rootViewController
7782
}

ios/ReactNativeCmp.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ - (void)loadGlobalCmpPrivacyManager:(nonnull NSString *)pmId {
9494
[sdk loadGlobalCMPPrivacyManager: pmId];
9595
}
9696

97+
- (void)loadPreferenceCenter:(nonnull NSString *)id {
98+
[sdk loadPreferenceCenter: id];
99+
}
100+
101+
97102

98103
// MARK: SPDelegate
99104
- (void)onAction:(RNAction*)action {

src/NativeReactNativeCmp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export interface Spec extends TurboModule {
153153
loadGDPRPrivacyManager(pmId: string): void;
154154
loadUSNatPrivacyManager(pmId: string): void;
155155
loadGlobalCmpPrivacyManager(pmId: string): void;
156+
loadPreferenceCenter(id: string): void;
156157

157158
readonly onAction: EventEmitter<SPAction>;
158159
readonly onSPUIReady: EventEmitter<void>;

src/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export default class SPConsentManager implements Spec {
4444
ReactNativeCmp.loadGlobalCmpPrivacyManager(pmId);
4545
}
4646

47+
loadPreferenceCenter(id: string) {
48+
ReactNativeCmp.loadPreferenceCenter(id);
49+
}
50+
4751
onAction: EventEmitter<SPAction> = ReactNativeCmp.onAction;
4852
onSPUIReady: EventEmitter<void> = ReactNativeCmp.onSPUIReady;
4953
onSPUIFinished: EventEmitter<void> = ReactNativeCmp.onSPUIFinished;

0 commit comments

Comments
 (0)