From 028a1c615fcf97882aa413ecf911496cea1132b6 Mon Sep 17 00:00:00 2001 From: Thomson Thomas Date: Fri, 18 Jul 2025 14:37:22 +1000 Subject: [PATCH] feat: add RoktEventManager support and integrate event listeners in sample app --- ios/RNMParticle.xcodeproj/project.pbxproj | 17 ++++++++++ js/index.d.ts | 10 +++++- js/index.js | 3 +- js/rokt/rokt.ts | 3 ++ sample/index.js | 41 +++++++++++++++++++---- 5 files changed, 66 insertions(+), 8 deletions(-) diff --git a/ios/RNMParticle.xcodeproj/project.pbxproj b/ios/RNMParticle.xcodeproj/project.pbxproj index 88cabcc..f2551e4 100644 --- a/ios/RNMParticle.xcodeproj/project.pbxproj +++ b/ios/RNMParticle.xcodeproj/project.pbxproj @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + B39BCD8E2E2A06D700FC90B8 /* RNMPRokt.m in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD8A2E2A06D700FC90B8 /* RNMPRokt.m */; }; + B39BCD8F2E2A06D700FC90B8 /* RoktEventManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD8C2E2A06D700FC90B8 /* RoktEventManager.m */; }; + B39BCD902E2A06D700FC90B8 /* RoktWidgetManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD8D2E2A06D700FC90B8 /* RoktWidgetManager.m */; }; DBDF24DC1E007EB1000F3D73 /* RNMParticle.m in Sources */ = {isa = PBXBuildFile; fileRef = DBDF24DB1E007EB1000F3D73 /* RNMParticle.m */; }; DBDF24DD1E007EB1000F3D73 /* RNMParticle.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBDF24DA1E007EB1000F3D73 /* RNMParticle.h */; }; /* End PBXBuildFile section */ @@ -25,6 +28,11 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + B39BCD892E2A06D700FC90B8 /* RNMPRokt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNMPRokt.h; sourceTree = ""; }; + B39BCD8A2E2A06D700FC90B8 /* RNMPRokt.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNMPRokt.m; sourceTree = ""; }; + B39BCD8B2E2A06D700FC90B8 /* RoktEventManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RoktEventManager.h; sourceTree = ""; }; + B39BCD8C2E2A06D700FC90B8 /* RoktEventManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoktEventManager.m; sourceTree = ""; }; + B39BCD8D2E2A06D700FC90B8 /* RoktWidgetManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoktWidgetManager.m; sourceTree = ""; }; DBDF24D71E007EB1000F3D73 /* libRNMParticle.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNMParticle.a; sourceTree = BUILT_PRODUCTS_DIR; }; DBDF24DA1E007EB1000F3D73 /* RNMParticle.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNMParticle.h; sourceTree = ""; }; DBDF24DB1E007EB1000F3D73 /* RNMParticle.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNMParticle.m; sourceTree = ""; }; @@ -60,6 +68,11 @@ DBDF24D91E007EB1000F3D73 /* RNMParticle */ = { isa = PBXGroup; children = ( + B39BCD892E2A06D700FC90B8 /* RNMPRokt.h */, + B39BCD8A2E2A06D700FC90B8 /* RNMPRokt.m */, + B39BCD8B2E2A06D700FC90B8 /* RoktEventManager.h */, + B39BCD8C2E2A06D700FC90B8 /* RoktEventManager.m */, + B39BCD8D2E2A06D700FC90B8 /* RoktWidgetManager.m */, DBDF24DA1E007EB1000F3D73 /* RNMParticle.h */, DBDF24DB1E007EB1000F3D73 /* RNMParticle.m */, ); @@ -106,6 +119,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = DBDF24CE1E007EB1000F3D73; @@ -124,6 +138,9 @@ buildActionMask = 2147483647; files = ( DBDF24DC1E007EB1000F3D73 /* RNMParticle.m in Sources */, + B39BCD8E2E2A06D700FC90B8 /* RNMPRokt.m in Sources */, + B39BCD8F2E2A06D700FC90B8 /* RoktEventManager.m in Sources */, + B39BCD902E2A06D700FC90B8 /* RoktWidgetManager.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/js/index.d.ts b/js/index.d.ts index 93afa54..eb21126 100644 --- a/js/index.d.ts +++ b/js/index.d.ts @@ -1,4 +1,10 @@ -import { Rokt, CacheConfig, IRoktConfig, ColorMode } from './rokt/rokt'; +import { + Rokt, + CacheConfig, + IRoktConfig, + ColorMode, + RoktEventManager, +} from './rokt/rokt'; import RoktLayoutView, { RoktLayoutViewProps } from './rokt/rokt-layout-view'; // ******** Types ******** @@ -391,6 +397,7 @@ export { ColorMode, RoktLayoutView, RoktLayoutViewProps, + RoktEventManager, }; // Default export @@ -436,6 +443,7 @@ declare const _default: { Rokt: typeof Rokt; CacheConfig: typeof CacheConfig; RoktLayoutView: typeof RoktLayoutView; + RoktEventManager: typeof RoktEventManager; }; export default _default; diff --git a/js/index.js b/js/index.js index a243849..40ca01c 100644 --- a/js/index.js +++ b/js/index.js @@ -1,7 +1,7 @@ 'use strict'; import { NativeModules } from 'react-native'; -import { Rokt, CacheConfig } from './rokt/rokt'; +import { Rokt, CacheConfig, RoktEventManager } from './rokt/rokt'; import RoktLayoutView from './rokt/rokt-layout-view'; // ******** Constants ******** @@ -703,6 +703,7 @@ const MParticle = { Rokt, CacheConfig, RoktLayoutView, + RoktEventManager, upload, // Methods setUploadInterval, diff --git a/js/rokt/rokt.ts b/js/rokt/rokt.ts index 74ca574..28599eb 100644 --- a/js/rokt/rokt.ts +++ b/js/rokt/rokt.ts @@ -68,5 +68,8 @@ class RoktConfig implements IRoktConfig { this.cacheConfig = cacheConfig; } } +const { RoktEventManager } = NativeModules; + +export { RoktEventManager }; export type ColorMode = 'light' | 'dark' | 'system'; diff --git a/sample/index.js b/sample/index.js index f3055e5..9f08730 100644 --- a/sample/index.js +++ b/sample/index.js @@ -6,17 +6,21 @@ import React, { Component } from 'react'; import { - AppRegistry, - StyleSheet, - Text, - View, - Button, - Platform, findNodeHandle, ScrollView + AppRegistry, + StyleSheet, + Text, + Button, + Platform, + findNodeHandle, + ScrollView, + NativeEventEmitter, } from 'react-native'; import MParticle from 'react-native-mparticle'; const { RoktLayoutView } = MParticle; +const eventManagerEmitter = new NativeEventEmitter(MParticle.RoktEventManager); + export default class MParticleSample extends Component { constructor(props) { super(props); @@ -123,6 +127,31 @@ export default class MParticleSample extends Component { componentDidMount() { MParticle.getSession(session => this.setState({ session })) + if (eventManagerEmitter) { + // Save subscriptions so we can remove them later + this.roktCallbackListener = eventManagerEmitter.addListener( + 'RoktCallback', + data => { + console.log('roktCallback received: ' + data.callbackValue); + }, + ); + + this.roktEventsListener = eventManagerEmitter.addListener('RoktEvents', data => { + console.log(`*** ROKT EVENT *** ${JSON.stringify(data)}`); + }); + } else { + console.warn('RoktEventManager not available, skipping event listeners'); + } + } + + componentWillUnmount() { + // Remove event listeners to avoid duplicate subscriptions + if (this.roktCallbackListener) { + this.roktCallbackListener.remove(); + } + if (this.roktEventsListener) { + this.roktEventsListener.remove(); + } } _toggleOptOut() {