Skip to content

Commit 028a1c6

Browse files
committed
feat: add RoktEventManager support and integrate event listeners in sample app
1 parent a4f9322 commit 028a1c6

File tree

5 files changed

+66
-8
lines changed

5 files changed

+66
-8
lines changed

ios/RNMParticle.xcodeproj/project.pbxproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
B39BCD8E2E2A06D700FC90B8 /* RNMPRokt.m in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD8A2E2A06D700FC90B8 /* RNMPRokt.m */; };
11+
B39BCD8F2E2A06D700FC90B8 /* RoktEventManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD8C2E2A06D700FC90B8 /* RoktEventManager.m */; };
12+
B39BCD902E2A06D700FC90B8 /* RoktWidgetManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD8D2E2A06D700FC90B8 /* RoktWidgetManager.m */; };
1013
DBDF24DC1E007EB1000F3D73 /* RNMParticle.m in Sources */ = {isa = PBXBuildFile; fileRef = DBDF24DB1E007EB1000F3D73 /* RNMParticle.m */; };
1114
DBDF24DD1E007EB1000F3D73 /* RNMParticle.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBDF24DA1E007EB1000F3D73 /* RNMParticle.h */; };
1215
/* End PBXBuildFile section */
@@ -25,6 +28,11 @@
2528
/* End PBXCopyFilesBuildPhase section */
2629

2730
/* Begin PBXFileReference section */
31+
B39BCD892E2A06D700FC90B8 /* RNMPRokt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNMPRokt.h; sourceTree = "<group>"; };
32+
B39BCD8A2E2A06D700FC90B8 /* RNMPRokt.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNMPRokt.m; sourceTree = "<group>"; };
33+
B39BCD8B2E2A06D700FC90B8 /* RoktEventManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RoktEventManager.h; sourceTree = "<group>"; };
34+
B39BCD8C2E2A06D700FC90B8 /* RoktEventManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoktEventManager.m; sourceTree = "<group>"; };
35+
B39BCD8D2E2A06D700FC90B8 /* RoktWidgetManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoktWidgetManager.m; sourceTree = "<group>"; };
2836
DBDF24D71E007EB1000F3D73 /* libRNMParticle.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNMParticle.a; sourceTree = BUILT_PRODUCTS_DIR; };
2937
DBDF24DA1E007EB1000F3D73 /* RNMParticle.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNMParticle.h; sourceTree = "<group>"; };
3038
DBDF24DB1E007EB1000F3D73 /* RNMParticle.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNMParticle.m; sourceTree = "<group>"; };
@@ -60,6 +68,11 @@
6068
DBDF24D91E007EB1000F3D73 /* RNMParticle */ = {
6169
isa = PBXGroup;
6270
children = (
71+
B39BCD892E2A06D700FC90B8 /* RNMPRokt.h */,
72+
B39BCD8A2E2A06D700FC90B8 /* RNMPRokt.m */,
73+
B39BCD8B2E2A06D700FC90B8 /* RoktEventManager.h */,
74+
B39BCD8C2E2A06D700FC90B8 /* RoktEventManager.m */,
75+
B39BCD8D2E2A06D700FC90B8 /* RoktWidgetManager.m */,
6376
DBDF24DA1E007EB1000F3D73 /* RNMParticle.h */,
6477
DBDF24DB1E007EB1000F3D73 /* RNMParticle.m */,
6578
);
@@ -106,6 +119,7 @@
106119
developmentRegion = English;
107120
hasScannedForEncodings = 0;
108121
knownRegions = (
122+
English,
109123
en,
110124
);
111125
mainGroup = DBDF24CE1E007EB1000F3D73;
@@ -124,6 +138,9 @@
124138
buildActionMask = 2147483647;
125139
files = (
126140
DBDF24DC1E007EB1000F3D73 /* RNMParticle.m in Sources */,
141+
B39BCD8E2E2A06D700FC90B8 /* RNMPRokt.m in Sources */,
142+
B39BCD8F2E2A06D700FC90B8 /* RoktEventManager.m in Sources */,
143+
B39BCD902E2A06D700FC90B8 /* RoktWidgetManager.m in Sources */,
127144
);
128145
runOnlyForDeploymentPostprocessing = 0;
129146
};

js/index.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Rokt, CacheConfig, IRoktConfig, ColorMode } from './rokt/rokt';
1+
import {
2+
Rokt,
3+
CacheConfig,
4+
IRoktConfig,
5+
ColorMode,
6+
RoktEventManager,
7+
} from './rokt/rokt';
28
import RoktLayoutView, { RoktLayoutViewProps } from './rokt/rokt-layout-view';
39

410
// ******** Types ********
@@ -391,6 +397,7 @@ export {
391397
ColorMode,
392398
RoktLayoutView,
393399
RoktLayoutViewProps,
400+
RoktEventManager,
394401
};
395402

396403
// Default export
@@ -436,6 +443,7 @@ declare const _default: {
436443
Rokt: typeof Rokt;
437444
CacheConfig: typeof CacheConfig;
438445
RoktLayoutView: typeof RoktLayoutView;
446+
RoktEventManager: typeof RoktEventManager;
439447
};
440448

441449
export default _default;

js/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
import { NativeModules } from 'react-native';
4-
import { Rokt, CacheConfig } from './rokt/rokt';
4+
import { Rokt, CacheConfig, RoktEventManager } from './rokt/rokt';
55
import RoktLayoutView from './rokt/rokt-layout-view';
66

77
// ******** Constants ********
@@ -703,6 +703,7 @@ const MParticle = {
703703
Rokt,
704704
CacheConfig,
705705
RoktLayoutView,
706+
RoktEventManager,
706707

707708
upload, // Methods
708709
setUploadInterval,

js/rokt/rokt.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,8 @@ class RoktConfig implements IRoktConfig {
6868
this.cacheConfig = cacheConfig;
6969
}
7070
}
71+
const { RoktEventManager } = NativeModules;
72+
73+
export { RoktEventManager };
7174

7275
export type ColorMode = 'light' | 'dark' | 'system';

sample/index.js

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@
66

77
import React, { Component } from 'react';
88
import {
9-
AppRegistry,
10-
StyleSheet,
11-
Text,
12-
View,
13-
Button,
14-
Platform, findNodeHandle, ScrollView
9+
AppRegistry,
10+
StyleSheet,
11+
Text,
12+
Button,
13+
Platform,
14+
findNodeHandle,
15+
ScrollView,
16+
NativeEventEmitter,
1517
} from 'react-native';
1618
import MParticle from 'react-native-mparticle';
1719

1820
const { RoktLayoutView } = MParticle;
1921

22+
const eventManagerEmitter = new NativeEventEmitter(MParticle.RoktEventManager);
23+
2024
export default class MParticleSample extends Component {
2125
constructor(props) {
2226
super(props);
@@ -123,6 +127,31 @@ export default class MParticleSample extends Component {
123127

124128
componentDidMount() {
125129
MParticle.getSession(session => this.setState({ session }))
130+
if (eventManagerEmitter) {
131+
// Save subscriptions so we can remove them later
132+
this.roktCallbackListener = eventManagerEmitter.addListener(
133+
'RoktCallback',
134+
data => {
135+
console.log('roktCallback received: ' + data.callbackValue);
136+
},
137+
);
138+
139+
this.roktEventsListener = eventManagerEmitter.addListener('RoktEvents', data => {
140+
console.log(`*** ROKT EVENT *** ${JSON.stringify(data)}`);
141+
});
142+
} else {
143+
console.warn('RoktEventManager not available, skipping event listeners');
144+
}
145+
}
146+
147+
componentWillUnmount() {
148+
// Remove event listeners to avoid duplicate subscriptions
149+
if (this.roktCallbackListener) {
150+
this.roktCallbackListener.remove();
151+
}
152+
if (this.roktEventsListener) {
153+
this.roktEventsListener.remove();
154+
}
126155
}
127156

128157
_toggleOptOut() {

0 commit comments

Comments
 (0)