Skip to content

Commit b6f4de7

Browse files
committed
iOS New architecture support
1 parent a2de9ea commit b6f4de7

File tree

15 files changed

+1381
-708
lines changed

15 files changed

+1381
-708
lines changed

android/src/main/java/com/mparticle/react/rokt/MPRoktModuleImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,6 @@ class MPRoktModuleImpl(
249249

250250
companion object {
251251
const val MAX_LISTENERS = 5
252-
const val MODULE_NAME = "MPRokt"
252+
const val MODULE_NAME = "RNMPRokt"
253253
}
254254
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.mparticle.react
2+
3+
import com.facebook.react.bridge.ReactApplicationContext
4+
import com.facebook.react.bridge.ReactContextBaseJavaModule
5+
import com.facebook.react.bridge.ReadableMap
6+
7+
abstract class NativeMPRoktSpec(reactContext: ReactApplicationContext) :
8+
ReactContextBaseJavaModule(reactContext) {
9+
10+
companion object {
11+
private const val MODULE_NAME = "RNMPRokt"
12+
}
13+
14+
override fun getName(): String {
15+
return MODULE_NAME
16+
}
17+
18+
abstract fun selectPlacements(
19+
identifier: String,
20+
attributes: ReadableMap?,
21+
placeholders: ReadableMap?,
22+
roktConfig: ReadableMap?,
23+
fontFilesMap: ReadableMap?
24+
)
25+
}

android/src/oldarch/java/com/mparticle/react/NativeMParticleSpec.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ abstract class NativeMParticleSpec(reactContext: ReactApplicationContext) :
1010
ReactContextBaseJavaModule(reactContext) {
1111

1212
companion object {
13-
private const val MODULE_NAME = "MPRokt"
13+
private const val MODULE_NAME = "RNMParticle"
1414
}
1515

1616
override fun getName(): String {

android/src/oldarch/java/com/mparticle/react/rokt/MPRoktModule.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package com.mparticle.react.rokt
22

33
import com.facebook.react.bridge.ReactApplicationContext
4-
import com.facebook.react.bridge.ReactContextBaseJavaModule
54
import com.facebook.react.bridge.ReactMethod
65
import com.facebook.react.bridge.ReadableMap
76
import com.facebook.react.uimanager.NativeViewHierarchyManager
87
import com.facebook.react.uimanager.UIManagerModule
98
import com.mparticle.MParticle
109
import com.mparticle.WrapperSdk
10+
import com.mparticle.react.NativeMPRoktSpec
1111
import com.mparticle.rokt.RoktEmbeddedView
1212
import java.lang.ref.WeakReference
1313

1414
class MPRoktModule(
1515
private val reactContext: ReactApplicationContext,
16-
) : ReactContextBaseJavaModule(reactContext) {
16+
) : NativeMPRoktSpec(reactContext) {
1717
init {
1818
MParticle.getInstance()?.setWrapperSdk(WrapperSdk.WrapperSdkReactNative, "")
1919
}
@@ -23,7 +23,7 @@ class MPRoktModule(
2323
override fun getName(): String = impl.getName()
2424

2525
@ReactMethod
26-
fun selectPlacements(
26+
override fun selectPlacements(
2727
identifier: String,
2828
attributes: ReadableMap?,
2929
placeholders: ReadableMap?,

ios/RNMParticle.xcodeproj/project.pbxproj

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
DBDF24DC1E007EB1000F3D73 /* RNMParticle.m in Sources */ = {isa = PBXBuildFile; fileRef = DBDF24DB1E007EB1000F3D73 /* RNMParticle.m */; };
10+
B39BCD832E27536600FC90B8 /* RoktNativeLayoutManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD822E27536600FC90B8 /* RoktNativeLayoutManager.m */; };
11+
B39BCD842E27536600FC90B8 /* RNMParticle.mm in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD802E27536600FC90B8 /* RNMParticle.mm */; };
12+
B39BCD852E27536600FC90B8 /* RNMPRokt.mm in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD812E27536600FC90B8 /* RNMPRokt.mm */; };
13+
B39BCD882E27551C00FC90B8 /* RoktNativeLayoutComponentView.mm in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD872E27551C00FC90B8 /* RoktNativeLayoutComponentView.mm */; };
1114
DBDF24DD1E007EB1000F3D73 /* RNMParticle.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBDF24DA1E007EB1000F3D73 /* RNMParticle.h */; };
1215
DBDF24DE1E007EB1000F3D74 /* RoktEventManager.m in Sources */ = {isa = PBXBuildFile; fileRef = DBDF24DD1E007EB1000F3D74 /* RoktEventManager.m */; };
13-
DBDF24DF1E007EB1000F3D74 /* RoktEventManager.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBDF24DC1E007EB1000F3D74 /* RoktEventManager.h */; };
14-
DBDF24E01E007EB1000F3D75 /* RNMPRokt.m in Sources */ = {isa = PBXBuildFile; fileRef = DBDF24DE1E007EB1000F3D75 /* RNMPRokt.m */; };
15-
DBDF24E11E007EB1000F3D75 /* RNMPRokt.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBDF24DD1E007EB1000F3D75 /* RNMPRokt.h */; };
1616
/* End PBXBuildFile section */
1717

1818
/* Begin PBXCopyFilesBuildPhase section */
@@ -29,13 +29,16 @@
2929
/* End PBXCopyFilesBuildPhase section */
3030

3131
/* Begin PBXFileReference section */
32+
B39BCD802E27536600FC90B8 /* RNMParticle.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RNMParticle.mm; sourceTree = "<group>"; };
33+
B39BCD812E27536600FC90B8 /* RNMPRokt.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RNMPRokt.mm; sourceTree = "<group>"; };
34+
B39BCD822E27536600FC90B8 /* RoktNativeLayoutManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoktNativeLayoutManager.m; sourceTree = "<group>"; };
35+
B39BCD862E27551C00FC90B8 /* RoktNativeLayoutComponentView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RoktNativeLayoutComponentView.h; sourceTree = "<group>"; };
36+
B39BCD872E27551C00FC90B8 /* RoktNativeLayoutComponentView.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RoktNativeLayoutComponentView.mm; sourceTree = "<group>"; };
3237
DBDF24D71E007EB1000F3D73 /* libRNMParticle.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNMParticle.a; sourceTree = BUILT_PRODUCTS_DIR; };
3338
DBDF24DA1E007EB1000F3D73 /* RNMParticle.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNMParticle.h; sourceTree = "<group>"; };
34-
DBDF24DB1E007EB1000F3D73 /* RNMParticle.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNMParticle.m; sourceTree = "<group>"; };
3539
DBDF24DC1E007EB1000F3D74 /* RoktEventManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RoktEventManager.h; sourceTree = "<group>"; };
3640
DBDF24DD1E007EB1000F3D74 /* RoktEventManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoktEventManager.m; sourceTree = "<group>"; };
3741
DBDF24DD1E007EB1000F3D75 /* RNMPRokt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNMPRokt.h; sourceTree = "<group>"; };
38-
DBDF24DE1E007EB1000F3D75 /* RNMPRokt.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNMPRokt.m; sourceTree = "<group>"; };
3942
/* End PBXFileReference section */
4043

4144
/* Begin PBXFrameworksBuildPhase section */
@@ -68,12 +71,15 @@
6871
DBDF24D91E007EB1000F3D73 /* RNMParticle */ = {
6972
isa = PBXGroup;
7073
children = (
74+
B39BCD862E27551C00FC90B8 /* RoktNativeLayoutComponentView.h */,
75+
B39BCD872E27551C00FC90B8 /* RoktNativeLayoutComponentView.mm */,
76+
B39BCD802E27536600FC90B8 /* RNMParticle.mm */,
77+
B39BCD812E27536600FC90B8 /* RNMPRokt.mm */,
78+
B39BCD822E27536600FC90B8 /* RoktNativeLayoutManager.m */,
7179
DBDF24DA1E007EB1000F3D73 /* RNMParticle.h */,
72-
DBDF24DB1E007EB1000F3D73 /* RNMParticle.m */,
7380
DBDF24DC1E007EB1000F3D74 /* RoktEventManager.h */,
7481
DBDF24DD1E007EB1000F3D74 /* RoktEventManager.m */,
7582
DBDF24DD1E007EB1000F3D75 /* RNMPRokt.h */,
76-
DBDF24DE1E007EB1000F3D75 /* RNMPRokt.m */,
7783
);
7884
path = RNMParticle;
7985
sourceTree = "<group>";
@@ -118,6 +124,7 @@
118124
developmentRegion = English;
119125
hasScannedForEncodings = 0;
120126
knownRegions = (
127+
English,
121128
en,
122129
);
123130
mainGroup = DBDF24CE1E007EB1000F3D73;
@@ -135,9 +142,11 @@
135142
isa = PBXSourcesBuildPhase;
136143
buildActionMask = 2147483647;
137144
files = (
138-
DBDF24DC1E007EB1000F3D73 /* RNMParticle.m in Sources */,
145+
B39BCD882E27551C00FC90B8 /* RoktNativeLayoutComponentView.mm in Sources */,
146+
B39BCD832E27536600FC90B8 /* RoktNativeLayoutManager.m in Sources */,
147+
B39BCD842E27536600FC90B8 /* RNMParticle.mm in Sources */,
148+
B39BCD852E27536600FC90B8 /* RNMPRokt.mm in Sources */,
139149
DBDF24DE1E007EB1000F3D74 /* RoktEventManager.m in Sources */,
140-
DBDF24E01E007EB1000F3D75 /* RNMPRokt.m in Sources */,
141150
);
142151
runOnlyForDeploymentPostprocessing = 0;
143152
};

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
Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
@@ -34,7 +39,7 @@ @implementation RNMPRokt
3439
RCT_EXTERN void RCTRegisterModule(Class);
3540

3641
+ (NSString *)moduleName {
37-
return @"MPRokt";
42+
return @"RNMPRokt";
3843
}
3944

4045
+ (void)load {
@@ -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"];
@@ -175,25 +208,32 @@ - (NSMutableDictionary *)getNativePlaceholders:(NSDictionary *)placeholders view
175208
NSMutableDictionary *nativePlaceholders = [[NSMutableDictionary alloc]initWithCapacity:placeholders.count];
176209

177210
for(id key in placeholders){
178-
//#ifdef RCT_NEW_ARCH_ENABLED
179-
/*RoktNativeWidgetComponentView *wrapperView = (RoktNativeWidgetComponentView *)viewRegistry[[placeholders objectForKey:key]];
180-
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]]) {
181214
RCTLogError(@"Cannot find RoktNativeWidgetComponentView with tag #%@", key);
182215
continue;
183216
}
184-
nativePlaceholders[key] = wrapperView.roktEmbeddedView;*/
185-
//#else
217+
nativePlaceholders[key] = wrapperView.roktEmbeddedView;
218+
#else
186219
MPRoktEmbeddedView *view = viewRegistry[[placeholders objectForKey:key]];
187220
if (!view || ![view isKindOfClass:[MPRoktEmbeddedView class]]) {
188221
RCTLogError(@"Cannot find RoktEmbeddedView with tag #%@", key);
189222
continue;
190223
}
191224

192225
nativePlaceholders[key] = view;
193-
//#endif // RCT_NEW_ARCH_ENABLED
226+
#endif // RCT_NEW_ARCH_ENABLED
194227
}
195228

196229
return nativePlaceholders;
197230
}
198231

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
238+
199239
@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)