Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.sourcepoint.reactnativecmp

import android.view.View
import com.facebook.react.bridge.Arguments.createMap
import com.facebook.react.bridge.Callback
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
Expand All @@ -21,6 +20,8 @@ import com.sourcepoint.reactnativecmp.arguments.BuildOptions
import com.sourcepoint.reactnativecmp.arguments.toList
import com.sourcepoint.reactnativecmp.consents.RNSPGDPRConsent
import com.sourcepoint.reactnativecmp.consents.RNSPUserData
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

data class SPLoadMessageParams(val authId: String?) {
constructor(fromReadableMap: ReadableMap?) : this(authId = fromReadableMap?.getString("authId"))
Expand Down Expand Up @@ -139,8 +140,8 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN
vendors: ReadableArray,
categories: ReadableArray,
legIntCategories: ReadableArray,
callback: Callback)
{
callback: Callback
) {
runOnMainThread {
spConsentLib?.deleteCustomConsentTo(
vendors.toList(),
Expand All @@ -162,17 +163,17 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN
}

override fun onAction(view: View, consentAction: ConsentAction): ConsentAction {
emitOnAction(createMap().apply {
putString("actionType", RNSourcepointActionType.from(consentAction.actionType).name)
putString("customActionId", consentAction.customActionId)
})
emitInternalOnAction(Json.encodeToString(mapOf(
"actionType" to RNSourcepointActionType.from(consentAction.actionType).name,
"customActionId" to consentAction.customActionId
)))
return consentAction
}

override fun onConsentReady(consent: SPConsents) {}

override fun onError(error: Throwable) {
emitOnError(createMap().apply { putString("description", error.message) })
emitInternalOnError(Json.encodeToString(mapOf("description" to error.message)))
}

override fun onNoIntentActivitiesFound(url: String) {}
Expand Down
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ PODS:
- React-logger (= 0.79.2)
- React-perflogger (= 0.79.2)
- React-utils (= 0.79.2)
- ReactNativeCmp (1.0.8):
- ReactNativeCmp (1.0.9-beta.2):
- ConsentViewController (= 7.12.1)
- DoubleConversion
- glog
Expand Down Expand Up @@ -1989,11 +1989,11 @@ SPEC CHECKSUMS:
ReactAppDependencyProvider: 04d5eb15eb46be6720e17a4a7fa92940a776e584
ReactCodegen: c63eda03ba1d94353fb97b031fc84f75a0d125ba
ReactCommon: 76d2dc87136d0a667678668b86f0fca0c16fdeb0
ReactNativeCmp: 332f0bc3333fc115006179d18a0dc7809d8e1c5f
ReactNativeCmp: d79d97ff49c3e5ca3aa5f8a6608dbe06a30e7c7a
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
SPMobileCore: 220d109e404cb17169f7e26f2a34c6022b80079a
Yoga: c758bfb934100bb4bf9cbaccb52557cee35e8bdf

PODFILE CHECKSUM: decdc7519d77aa5eae65b167fa59bcfce25e15d2

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
11 changes: 10 additions & 1 deletion ios/RNSourcepointCmp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,18 @@ import React
self.customActionId = customActionId
}

@objc public func toDictionary() -> [String: Any] {
func toDictionary() -> [String: Any] {
["actionType": type.description, "customActionId": customActionId]
}

@objc public func stringifiedJson() -> String {
if let jsonData = try? JSONSerialization.data(withJSONObject: toDictionary()),
let jsonString = String(data: jsonData, encoding: .utf8) {
return jsonString
} else {
return "{\"actionType\":\"unknown\"}"
}
}
}

@objc public protocol ReactNativeCmpImplDelegate {
Expand Down
7 changes: 5 additions & 2 deletions ios/ReactNativeCmp.mm
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,14 @@ - (void)postDeleteCustomConsentGDPR:(NSArray *)vendors

// MARK: SPDelegate
- (void)onAction:(RNAction*)action {
[self emitOnAction: [action toDictionary]];
[self emitInternalOnAction: [action stringifiedJson]];
}

- (void)onErrorWithDescription:(NSString * _Nonnull)description {
[self emitOnError: @{ @"description": description }];
NSDictionary *dict = @{@"description": description};
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:nil];
NSString *json = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
[self emitInternalOnError: json];
}

- (void)onFinished {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sourcepoint/react-native-cmp",
"version": "1.0.8",
"version": "1.0.9-beta.2",
"description": "The official react native bridge to the native Sourcepoint SDKs",
"main": "./lib/module/index.js",
"types": "./lib/typescript/src/index.d.ts",
Expand Down
8 changes: 6 additions & 2 deletions src/NativeReactNativeCmp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ export type SPBuildOptions = {
androidDismissMessageOnBackPress?: boolean;
}

export type SPError = {
description: string;
};

export interface Spec extends TurboModule {
build(
accountId: number,
Expand Down Expand Up @@ -230,12 +234,12 @@ export interface Spec extends TurboModule {
callback: (consent: GDPRConsent) => void
): void;

readonly onAction: EventEmitter<SPAction>;
readonly internalOnAction: EventEmitter<string>;
readonly onSPUIReady: EventEmitter<void>;
readonly onSPUIFinished: EventEmitter<void>;
readonly onFinished: EventEmitter<void>;
readonly onMessageInactivityTimeout: EventEmitter<void>;
readonly onError: EventEmitter<{ description: string }>;
readonly internalOnError: EventEmitter<string>;
}

export default TurboModuleRegistry.getEnforcing<Spec>('ReactNativeCmp');
38 changes: 29 additions & 9 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
SPAction,
SPBuildOptions,
GDPRConsent,
SPError
} from './NativeReactNativeCmp';
import ReactNativeCmp, { SPMessageLanguage } from './NativeReactNativeCmp';
import type { EventEmitter } from 'react-native/Libraries/Types/CodegenTypes';
Expand All @@ -18,6 +19,32 @@ const defaultBuildOptions: SPBuildOptions = {
}

export default class SPConsentManager implements Spec {
/** intended to be used by the SDK only */
internalOnAction: EventEmitter<string> = ReactNativeCmp.internalOnAction;
/** intended to be used by the SDK only */
internalOnError: EventEmitter<string> = ReactNativeCmp.internalOnError;

onSPUIReady: EventEmitter<void> = ReactNativeCmp.onSPUIReady;
onSPUIFinished: EventEmitter<void> = ReactNativeCmp.onSPUIFinished;
onFinished: EventEmitter<void> = ReactNativeCmp.onFinished;
onMessageInactivityTimeout: EventEmitter<void> = ReactNativeCmp.onMessageInactivityTimeout;

onAction(handler: (action: SPAction) => void) {
ReactNativeCmp.internalOnAction((stringifiedAction) => {
handler(JSON.parse(stringifiedAction) as SPAction);
});
}

onError(handler: (error: SPError) => void) {
ReactNativeCmp.internalOnError((stringifiedError) => {
handler(JSON.parse(stringifiedError) as SPError);
});
}

getConstants?(): {} {
throw new Error('Method not implemented.');
}

build(
accountId: number,
propertyId: number,
Expand Down Expand Up @@ -74,14 +101,7 @@ export default class SPConsentManager implements Spec {
categories: string[],
legIntCategories: string[],
callback: (consent: GDPRConsent) => void
) {
ReactNativeCmp.postDeleteCustomConsentGDPR(vendors, categories, legIntCategories, callback);
) {
ReactNativeCmp.postDeleteCustomConsentGDPR(vendors, categories, legIntCategories, callback);
}

onAction: EventEmitter<SPAction> = ReactNativeCmp.onAction;
onSPUIReady: EventEmitter<void> = ReactNativeCmp.onSPUIReady;
onSPUIFinished: EventEmitter<void> = ReactNativeCmp.onSPUIFinished;
onFinished: EventEmitter<void> = ReactNativeCmp.onFinished;
onMessageInactivityTimeout: EventEmitter<void> = ReactNativeCmp.onMessageInactivityTimeout;
onError: EventEmitter<{ description: string }> = ReactNativeCmp.onError;
}
Loading