|
5 | 5 | #elif defined(__has_include) && __has_include(<mParticle_Apple_SDK_NoLocation/mParticle.h>) |
6 | 6 | #import <mParticle_Apple_SDK_NoLocation/mParticle.h> |
7 | 7 | #else |
8 | | - #import "mParticle.h" |
| 8 | + #import <mParticle_Apple_SDK/Include/mParticle.h> |
9 | 9 | #endif |
10 | 10 | #if defined(__has_include) && __has_include(<mParticle_Apple_SDK/mParticle_Apple_SDK-Swift.h>) |
11 | 11 | #import <mParticle_Apple_SDK/mParticle_Apple_SDK-Swift.h> |
|
21 | 21 | #import <React/RCTBridge.h> |
22 | 22 | #import "RoktEventManager.h" |
23 | 23 |
|
| 24 | +#ifdef RCT_NEW_ARCH_ENABLED |
| 25 | +#import "RoktNativeLayoutComponentView.h" |
| 26 | +#import <RNMParticle/RNMParticle.h> |
| 27 | +#endif // RCT_NEW_ARCH_ENABLED |
| 28 | + |
24 | 29 | @interface RNMPRokt () |
25 | 30 |
|
26 | 31 | @property (nonatomic, nullable) RoktEventManager *eventManager; |
@@ -52,15 +57,43 @@ - (void)setMethodQueue:(dispatch_queue_t)methodQueue |
52 | 57 | // We always return the UI manager's method queue |
53 | 58 | } |
54 | 59 |
|
| 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 |
55 | 87 | RCT_EXPORT_METHOD(selectPlacements:(NSString *) identifer attributes:(NSDictionary *)attributes placeholders:(NSDictionary * _Nullable)placeholders roktConfig:(NSDictionary * _Nullable)roktConfig fontFilesMap:(NSDictionary * _Nullable)fontFilesMap) |
56 | 88 | { |
57 | 89 | NSMutableDictionary *finalAttributes = [self convertToMutableDictionaryOfStrings:attributes]; |
58 | 90 | MPRoktConfig *config = [self buildRoktConfigFromDict:roktConfig]; |
| 91 | +#endif |
59 | 92 |
|
60 | 93 | // Create callback implementation |
61 | 94 | MPRoktEventCallback *callbacks = [[MPRoktEventCallback alloc] init]; |
62 | 95 |
|
63 | | - __weak typeof(self) weakSelf = self; |
| 96 | + __weak __typeof__(self) weakSelf = self; |
64 | 97 |
|
65 | 98 | callbacks.onLoad = ^{ |
66 | 99 | [self.eventManager onRoktCallbackReceived:@"onLoad"]; |
@@ -88,7 +121,6 @@ - (void)setMethodQueue:(dispatch_queue_t)methodQueue |
88 | 121 |
|
89 | 122 | [self subscribeViewEvents:identifer]; |
90 | 123 |
|
91 | | - // TODO: Add placeholders and fontFilesMap |
92 | 124 | [[[MParticle sharedInstance] rokt] selectPlacements:identifer |
93 | 125 | attributes:finalAttributes |
94 | 126 | embeddedViews:nativePlaceholders |
@@ -176,25 +208,32 @@ - (NSMutableDictionary *)getNativePlaceholders:(NSDictionary *)placeholders view |
176 | 208 | NSMutableDictionary *nativePlaceholders = [[NSMutableDictionary alloc]initWithCapacity:placeholders.count]; |
177 | 209 |
|
178 | 210 | 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]]) { |
182 | 214 | RCTLogError(@"Cannot find RoktNativeWidgetComponentView with tag #%@", key); |
183 | 215 | continue; |
184 | 216 | } |
185 | | - nativePlaceholders[key] = wrapperView.roktEmbeddedView;*/ |
186 | | -//#else |
| 217 | + nativePlaceholders[key] = wrapperView.roktEmbeddedView; |
| 218 | +#else |
187 | 219 | MPRoktEmbeddedView *view = viewRegistry[[placeholders objectForKey:key]]; |
188 | 220 | if (!view || ![view isKindOfClass:[MPRoktEmbeddedView class]]) { |
189 | 221 | RCTLogError(@"Cannot find RoktEmbeddedView with tag #%@", key); |
190 | 222 | continue; |
191 | 223 | } |
192 | 224 |
|
193 | 225 | nativePlaceholders[key] = view; |
194 | | -//#endif // RCT_NEW_ARCH_ENABLED |
| 226 | +#endif // RCT_NEW_ARCH_ENABLED |
195 | 227 | } |
196 | 228 |
|
197 | 229 | return nativePlaceholders; |
198 | 230 | } |
199 | 231 |
|
| 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 | + |
200 | 239 | @end |
0 commit comments