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
17 changes: 17 additions & 0 deletions ios/RNMParticle.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -25,6 +28,11 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
B39BCD892E2A06D700FC90B8 /* RNMPRokt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNMPRokt.h; sourceTree = "<group>"; };
B39BCD8A2E2A06D700FC90B8 /* RNMPRokt.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNMPRokt.m; sourceTree = "<group>"; };
B39BCD8B2E2A06D700FC90B8 /* RoktEventManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RoktEventManager.h; sourceTree = "<group>"; };
B39BCD8C2E2A06D700FC90B8 /* RoktEventManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoktEventManager.m; sourceTree = "<group>"; };
B39BCD8D2E2A06D700FC90B8 /* RoktWidgetManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoktWidgetManager.m; sourceTree = "<group>"; };
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 = "<group>"; };
DBDF24DB1E007EB1000F3D73 /* RNMParticle.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNMParticle.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
);
Expand Down Expand Up @@ -106,6 +119,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = DBDF24CE1E007EB1000F3D73;
Expand All @@ -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;
};
Expand Down
10 changes: 9 additions & 1 deletion js/index.d.ts
Original file line number Diff line number Diff line change
@@ -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 ********
Expand All @@ -20,7 +26,7 @@
}

export interface AttributionResult {
[key: string]: any;

Check warning on line 29 in js/index.d.ts

View workflow job for this annotation

GitHub Actions / JS Tests

Unexpected any. Specify a different type

Check warning on line 29 in js/index.d.ts

View workflow job for this annotation

GitHub Actions / JS Tests

Unexpected any. Specify a different type
}

export type CompletionCallback<T> = (result: T) => void;
Expand Down Expand Up @@ -189,7 +195,7 @@
/**
* @deprecated This method is deprecated and will be removed in a future version.
*/
setOnUserAlias(onUserAlias: any): void;

Check warning on line 198 in js/index.d.ts

View workflow job for this annotation

GitHub Actions / JS Tests

Unexpected any. Specify a different type

Check warning on line 198 in js/index.d.ts

View workflow job for this annotation

GitHub Actions / JS Tests

Unexpected any. Specify a different type
}

export declare class Identity {
Expand Down Expand Up @@ -391,6 +397,7 @@
ColorMode,
RoktLayoutView,
RoktLayoutViewProps,
RoktEventManager,
};

// Default export
Expand Down Expand Up @@ -436,6 +443,7 @@
Rokt: typeof Rokt;
CacheConfig: typeof CacheConfig;
RoktLayoutView: typeof RoktLayoutView;
RoktEventManager: typeof RoktEventManager;
};

export default _default;
3 changes: 2 additions & 1 deletion js/index.js
Original file line number Diff line number Diff line change
@@ -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 ********
Expand Down Expand Up @@ -703,6 +703,7 @@ const MParticle = {
Rokt,
CacheConfig,
RoktLayoutView,
RoktEventManager,

upload, // Methods
setUploadInterval,
Expand Down
3 changes: 3 additions & 0 deletions js/rokt/rokt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,8 @@ class RoktConfig implements IRoktConfig {
this.cacheConfig = cacheConfig;
}
}
const { RoktEventManager } = NativeModules;

export { RoktEventManager };

export type ColorMode = 'light' | 'dark' | 'system';
41 changes: 35 additions & 6 deletions sample/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down