Skip to content

Commit 933e55c

Browse files
committed
feat: integrate new architecture support in JS layer
- Added support for TurboModules in the Rokt module. - Refactored RoktLayoutView and related components to utilize new architecture. - Updated NativeModules usage to leverage dynamic module loading. - Enhanced sample app to demonstrate new Rokt placement selection methods. - Introduced new codegen specifications for improved type safety and structure.
1 parent 5524a9a commit 933e55c

File tree

13 files changed

+443
-150
lines changed

13 files changed

+443
-150
lines changed

ios/RNMParticle/RNMPRokt.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ + (void)load {
4141
RCTRegisterModule(self);
4242
}
4343

44+
- (dispatch_queue_t)methodQueue
45+
{
46+
return self.bridge.uiManager.methodQueue;
47+
}
48+
49+
- (void)setMethodQueue:(dispatch_queue_t)methodQueue
50+
{
51+
// No-op setter to satisfy TurboModule requirements
52+
// We always return the UI manager's method queue
53+
}
54+
4455
RCT_EXPORT_METHOD(selectPlacements:(NSString *) identifer attributes:(NSDictionary *)attributes placeholders:(NSDictionary * _Nullable)placeholders roktConfig:(NSDictionary * _Nullable)roktConfig fontFilesMap:(NSDictionary * _Nullable)fontFilesMap)
4556
{
4657
NSMutableDictionary *finalAttributes = [self convertToMutableDictionaryOfStrings:attributes];
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22
#import <React/RCTViewManager.h>
33
#import <mParticle_Apple_SDK/MPRokt.h>
44

5-
@interface RoktNativeWidgetManager : RCTViewManager
5+
@interface RoktLayoutViewManager : RCTViewManager
66
@end
77

8-
@implementation RoktNativeWidgetManager
8+
@implementation RoktLayoutViewManager
99

10-
RCT_EXPORT_MODULE(RoktNativeLayout)
10+
RCT_EXPORT_MODULE(RoktLegacyLayout)
1111

1212
- (UIView *)view
1313
{
1414
return [[MPRoktEmbeddedView alloc] init];
1515
}
1616

17+
+ (BOOL)requiresMainQueueSetup
18+
{
19+
return YES;
20+
}
21+
1722
@end

js/codegenSpecs/NativeMParticle.ts

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
import type { TurboModule } from 'react-native';
2+
import { TurboModuleRegistry } from 'react-native';
3+
4+
export type CustomAttributes = { [key: string]: string | number | boolean };
5+
export type UserAttributes = {
6+
[key: string]: string | string[] | number | boolean | null;
7+
};
8+
export type UserIdentities = { [key: string]: string };
9+
10+
export interface Product {
11+
name: string;
12+
sku: string;
13+
price: number;
14+
quantity?: number;
15+
brand?: string;
16+
couponCode?: string;
17+
position?: number;
18+
category?: string;
19+
variant?: string;
20+
customAttributes?: CustomAttributes;
21+
}
22+
23+
export interface TransactionAttributes {
24+
transactionId: string;
25+
affiliation?: string;
26+
revenue?: number;
27+
shipping?: number;
28+
tax?: number;
29+
couponCode?: string;
30+
}
31+
32+
export interface Promotion {
33+
id: string;
34+
name: string;
35+
creative: string;
36+
position: string;
37+
}
38+
39+
export interface Impression {
40+
impressionListName: string;
41+
products: Product[];
42+
}
43+
44+
export interface CommerceEvent {
45+
productActionType?: number;
46+
promotionActionType?: number;
47+
products?: Product[];
48+
transactionAttributes?: TransactionAttributes;
49+
promotions?: Promotion[];
50+
impressions?: Impression[];
51+
screenName?: string;
52+
currency?: string;
53+
customAttributes?: CustomAttributes;
54+
checkoutOptions?: string;
55+
productActionListName?: string;
56+
productActionListSource?: string;
57+
checkoutStep?: number;
58+
nonInteractive?: boolean;
59+
shouldUploadEvent?: boolean;
60+
}
61+
62+
export interface Event {
63+
category?: string;
64+
duration?: number;
65+
endTime?: number;
66+
info?: CustomAttributes;
67+
name?: string;
68+
startTime?: number;
69+
type?: number;
70+
shouldUploadEvent?: boolean;
71+
customFlags?: { [key: string]: string };
72+
}
73+
74+
export interface GDPRConsent {
75+
consented?: boolean;
76+
document?: string | null;
77+
timestamp?: number;
78+
location?: string | null;
79+
hardwareId?: string | null;
80+
}
81+
82+
export interface CCPAConsent {
83+
consented?: boolean;
84+
document?: string | null;
85+
timestamp?: number;
86+
location?: string | null;
87+
hardwareId?: string | null;
88+
}
89+
90+
export type AttributionResult = {
91+
[key: string]: {
92+
[key: string]: string | number | boolean;
93+
};
94+
};
95+
96+
// Error type for callbacks
97+
export interface CallbackError {
98+
message: string;
99+
code?: number;
100+
httpCode?: number;
101+
responseCode?: number; // iOS only
102+
mpid?: string;
103+
errors?: string;
104+
}
105+
106+
export type IdentityRequest = { [key: number]: string };
107+
108+
export interface AliasRequest {
109+
sourceMpid?: string;
110+
destinationMpid?: string;
111+
startTime?: number;
112+
endTime?: number;
113+
}
114+
115+
export interface IdentityResult {
116+
userId: string;
117+
previousUserId: string;
118+
}
119+
120+
export interface Spec extends TurboModule {
121+
upload(): void;
122+
setUploadInterval(uploadInterval: number): void;
123+
logEvent(
124+
eventName: string,
125+
eventType: number,
126+
attributes: CustomAttributes | null
127+
): void;
128+
logMPEvent(event: Event): void;
129+
logCommerceEvent(commerceEvent: CommerceEvent): void;
130+
logScreenEvent(
131+
screenName: string,
132+
attributes: CustomAttributes | null,
133+
shouldUploadEvent: boolean
134+
): void;
135+
setATTStatus(status: number): void;
136+
setATTStatusWithCustomTimestamp(status: number, timestamp: number): void;
137+
setOptOut(optOut: boolean): void;
138+
getOptOut(callback: (result: boolean) => void): void;
139+
addGDPRConsentState(consent: GDPRConsent, purpose: string): void;
140+
removeGDPRConsentStateWithPurpose(purpose: string): void;
141+
setCCPAConsentState(consent: CCPAConsent): void;
142+
removeCCPAConsentState(): void;
143+
isKitActive(kitId: number, callback: (result: boolean) => void): void;
144+
getAttributions(callback: (result: AttributionResult) => void): void;
145+
logPushRegistration(token: string, senderId: string): void;
146+
getSession(callback: (result: string | null) => void): void;
147+
setLocation(latitude: number, longitude: number): void;
148+
149+
// User Methods
150+
setUserAttribute(mpid: string, key: string, value: string): void;
151+
setUserAttributeArray(mpid: string, key: string, value: Array<string>): void;
152+
getUserAttributes(
153+
mpid: string,
154+
callback: (
155+
error: CallbackError | null,
156+
result: UserAttributes | null
157+
) => void
158+
): void;
159+
setUserTag(mpid: string, tag: string): void;
160+
incrementUserAttribute(mpid: string, key: string, value: number): void;
161+
removeUserAttribute(mpid: string, key: string): void;
162+
getUserIdentities(
163+
mpid: string,
164+
callback: (
165+
error: CallbackError | null,
166+
result: UserIdentities | null
167+
) => void
168+
): void;
169+
getFirstSeen(mpid: string, callback: (result: string) => void): void;
170+
getLastSeen(mpid: string, callback: (result: string) => void): void;
171+
172+
// Identity Methods
173+
getCurrentUserWithCompletion(
174+
callback: (error: CallbackError | null, userId: string | null) => void
175+
): void;
176+
identify(
177+
identityRequest: IdentityRequest,
178+
callback: (
179+
error: CallbackError | null,
180+
userId: string | null,
181+
previousUserId: string | null
182+
) => void
183+
): void;
184+
login(
185+
identityRequest: IdentityRequest,
186+
callback: (
187+
error: CallbackError | null,
188+
userId: string | null,
189+
previousUserId: string | null
190+
) => void
191+
): void;
192+
logout(
193+
identityRequest: IdentityRequest,
194+
callback: (
195+
error: CallbackError | null,
196+
userId: string | null,
197+
previousUserId: string | null
198+
) => void
199+
): void;
200+
modify(
201+
identityRequest: IdentityRequest,
202+
callback: (
203+
error: CallbackError | null,
204+
userId: string | null,
205+
previousUserId: string | null
206+
) => void
207+
): void;
208+
aliasUsers(
209+
aliasRequest: AliasRequest,
210+
callback: (success: boolean, message?: string) => void
211+
): void;
212+
}
213+
214+
export default TurboModuleRegistry.getEnforcing<Spec>('RNMParticle');
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { TurboModule } from 'react-native';
2+
import { TurboModuleRegistry } from 'react-native';
3+
4+
type ColorMode = string;
5+
6+
type CacheConfig = {
7+
readonly cacheDurationInSeconds?: number;
8+
readonly cacheAttributes?: { [key: string]: string };
9+
};
10+
11+
type RoktConfigType = {
12+
readonly colorMode?: ColorMode;
13+
readonly cacheConfig?: CacheConfig;
14+
};
15+
16+
export interface Spec extends TurboModule {
17+
selectPlacements(
18+
identifier: string,
19+
attributes?: { [key: string]: string },
20+
placeholders?: { [key: string]: number | null },
21+
roktConfig?: RoktConfigType,
22+
fontFilesMap?: { [key: string]: string }
23+
): void;
24+
}
25+
26+
export default TurboModuleRegistry.getEnforcing<Spec>('RNMPRokt');
File renamed without changes.

0 commit comments

Comments
 (0)