Skip to content

Commit 64e908c

Browse files
committed
feat: implement new architecture support for iOS
- Updated RNMParticle and RNMPRokt to support new architecture with TurboModules. - Refactored imports and method signatures to align with new architecture standards. - Introduced RoktNativeLayoutComponentView for new architecture layout handling. - Added method implementations for better compatibility with new architecture. - Updated sample app Podfile to enable new architecture by default.
1 parent 0dad847 commit 64e908c

File tree

8 files changed

+750
-109
lines changed

8 files changed

+750
-109
lines changed

ios/RNMParticle/RNMPRokt.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
#import <Foundation/Foundation.h>
2-
#import <React/RCTBridge.h>
32

4-
@interface RNMPRokt : NSObject <RCTBridgeModule>
3+
#ifdef RCT_NEW_ARCH_ENABLED
4+
#import <RNMParticle/RNMParticle.h>
5+
#import <React/RCTBridge.h>
56

7+
@interface RNMPRokt : NSObject<NativeMPRoktSpec>
68
@property (nonatomic, weak, nullable) RCTBridge *bridge;
9+
#else
10+
11+
#import <React/RCTBridgeModule.h>
12+
@interface RNMPRokt : NSObject <RCTBridgeModule>
13+
#endif
714

815
@end

ios/RNMParticle/RNMPRokt.m

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#elif defined(__has_include) && __has_include(<mParticle_Apple_SDK_NoLocation/mParticle.h>)
66
#import <mParticle_Apple_SDK_NoLocation/mParticle.h>
77
#else
8-
#import "mParticle.h"
8+
#import <mParticle_Apple_SDK/Include/mParticle.h>
99
#endif
1010
#if defined(__has_include) && __has_include(<mParticle_Apple_SDK/mParticle_Apple_SDK-Swift.h>)
1111
#import <mParticle_Apple_SDK/mParticle_Apple_SDK-Swift.h>
@@ -21,6 +21,11 @@
2121
#import <React/RCTBridge.h>
2222
#import "RoktEventManager.h"
2323

24+
#ifdef RCT_NEW_ARCH_ENABLED
25+
#import "RoktNativeLayoutComponentView.h"
26+
#import <RNMParticle/RNMParticle.h>
27+
#endif // RCT_NEW_ARCH_ENABLED
28+
2429
@interface RNMPRokt ()
2530

2631
@property (nonatomic, nullable) RoktEventManager *eventManager;
@@ -52,15 +57,43 @@ - (void)setMethodQueue:(dispatch_queue_t)methodQueue
5257
// We always return the UI manager's method queue
5358
}
5459

60+
#ifdef RCT_NEW_ARCH_ENABLED
61+
// New Architecture Implementation
62+
- (void)selectPlacements:(NSString *)identifer
63+
attributes:(NSDictionary *)attributes
64+
placeholders:(NSDictionary * _Nullable)placeholders
65+
roktConfig:(JS::NativeMPRokt::RoktConfigType &)roktConfig
66+
fontFilesMap:(NSDictionary * _Nullable)fontFilesMap
67+
{
68+
NSMutableDictionary *finalAttributes = [self convertToMutableDictionaryOfStrings:attributes];
69+
70+
// Convert JS struct to NSDictionary for internal use
71+
NSMutableDictionary *roktConfigDict = [[NSMutableDictionary alloc] init];
72+
if (roktConfig.cacheConfig().has_value()) {
73+
NSMutableDictionary *cacheConfigDict = [[NSMutableDictionary alloc] init];
74+
auto cacheConfig = roktConfig.cacheConfig().value();
75+
if (cacheConfig.cacheDurationInSeconds().has_value()) {
76+
cacheConfigDict[@"cacheDurationInSeconds"] = @(cacheConfig.cacheDurationInSeconds().value());
77+
}
78+
if (cacheConfig.cacheAttributes()) {
79+
cacheConfigDict[@"cacheAttributes"] = cacheConfig.cacheAttributes();
80+
}
81+
roktConfigDict[@"cacheConfig"] = cacheConfigDict;
82+
}
83+
84+
MPRoktConfig *config = [self buildRoktConfigFromDict:roktConfigDict];
85+
#else
86+
// Old Architecture Implementation
5587
RCT_EXPORT_METHOD(selectPlacements:(NSString *) identifer attributes:(NSDictionary *)attributes placeholders:(NSDictionary * _Nullable)placeholders roktConfig:(NSDictionary * _Nullable)roktConfig fontFilesMap:(NSDictionary * _Nullable)fontFilesMap)
5688
{
5789
NSMutableDictionary *finalAttributes = [self convertToMutableDictionaryOfStrings:attributes];
5890
MPRoktConfig *config = [self buildRoktConfigFromDict:roktConfig];
91+
#endif
5992

6093
// Create callback implementation
6194
MPRoktEventCallback *callbacks = [[MPRoktEventCallback alloc] init];
6295

63-
__weak typeof(self) weakSelf = self;
96+
__weak __typeof__(self) weakSelf = self;
6497

6598
callbacks.onLoad = ^{
6699
[self.eventManager onRoktCallbackReceived:@"onLoad"];
@@ -88,7 +121,6 @@ - (void)setMethodQueue:(dispatch_queue_t)methodQueue
88121

89122
[self subscribeViewEvents:identifer];
90123

91-
// TODO: Add placeholders and fontFilesMap
92124
[[[MParticle sharedInstance] rokt] selectPlacements:identifer
93125
attributes:finalAttributes
94126
embeddedViews:nativePlaceholders
@@ -176,25 +208,32 @@ - (NSMutableDictionary *)getNativePlaceholders:(NSDictionary *)placeholders view
176208
NSMutableDictionary *nativePlaceholders = [[NSMutableDictionary alloc]initWithCapacity:placeholders.count];
177209

178210
for(id key in placeholders){
179-
//#ifdef RCT_NEW_ARCH_ENABLED
180-
/*RoktNativeWidgetComponentView *wrapperView = (RoktNativeWidgetComponentView *)viewRegistry[[placeholders objectForKey:key]];
181-
if (!wrapperView || ![wrapperView isKindOfClass:[RoktNativeWidgetComponentView class]]) {
211+
#ifdef RCT_NEW_ARCH_ENABLED
212+
RoktNativeLayoutComponentView *wrapperView = (RoktNativeLayoutComponentView *)viewRegistry[[placeholders objectForKey:key]];
213+
if (!wrapperView || ![wrapperView isKindOfClass:[RoktNativeLayoutComponentView class]]) {
182214
RCTLogError(@"Cannot find RoktNativeWidgetComponentView with tag #%@", key);
183215
continue;
184216
}
185-
nativePlaceholders[key] = wrapperView.roktEmbeddedView;*/
186-
//#else
217+
nativePlaceholders[key] = wrapperView.roktEmbeddedView;
218+
#else
187219
MPRoktEmbeddedView *view = viewRegistry[[placeholders objectForKey:key]];
188220
if (!view || ![view isKindOfClass:[MPRoktEmbeddedView class]]) {
189221
RCTLogError(@"Cannot find RoktEmbeddedView with tag #%@", key);
190222
continue;
191223
}
192224

193225
nativePlaceholders[key] = view;
194-
//#endif // RCT_NEW_ARCH_ENABLED
226+
#endif // RCT_NEW_ARCH_ENABLED
195227
}
196228

197229
return nativePlaceholders;
198230
}
199231

232+
#ifdef RCT_NEW_ARCH_ENABLED
233+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
234+
self.bridge = params.instance.bridge;
235+
return std::make_shared<facebook::react::NativeMPRoktSpecJSI>(params);
236+
}
237+
#endif // RCT_NEW_ARCH_ENABLED
238+
200239
@end

ios/RNMParticle/RNMParticle.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#import <Foundation/Foundation.h>
2-
#import <React/RCTBridge.h>
32

3+
#ifdef RCT_NEW_ARCH_ENABLED
4+
#import <RNMParticle/RNMParticle.h>
5+
@interface RNMParticle : NSObject <NativeMParticleSpec>
6+
#else
7+
#import <React/RCTBridgeModule.h>
48
@interface RNMParticle : NSObject <RCTBridgeModule>
9+
#endif
510

611
@end

0 commit comments

Comments
 (0)