Skip to content

Commit 69689c9

Browse files
authored
feat: implement new architecture support for iOS (#225)
1 parent 0dad847 commit 69689c9

File tree

11 files changed

+1372
-724
lines changed

11 files changed

+1372
-724
lines changed

.npmignore

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,29 @@ sample/
44
# Android build artifacts and libs
55
android/libs/
66
android/build/
7+
android/src/test/
78
android/.gradle/
89
android/local.properties
10+
android/.idea/
11+
android/.kotlin/
12+
android/gradlew
13+
android/gradlew.bat
14+
android/gradle.properties
15+
android/gradle/
916

1017
# iOS build artifacts
1118
ios/build/
12-
ios/Pods/
13-
ios/Podfile.lock
14-
15-
# Build directories
16-
build/
17-
dist/
19+
ios/RNMParticle.xcodeproj/xcuserdata/
20+
ios/RNMParticle.xcodeproj/xcshareddata/
21+
ios/RNMParticle.xcodeproj/project.xcworkspace/
1822

1923
# Dependencies
2024
node_modules/
2125

2226
# IDE files
2327
.idea/
2428
.vscode/
29+
.trunk/
2530
*.iml
2631
*.iws
2732

@@ -32,6 +37,7 @@ Thumbs.db
3237
# Git
3338
.git/
3439
.github/
40+
.gitignore
3541

3642
# Logs
3743
*.log
@@ -47,19 +53,14 @@ yarn-error.log*
4753

4854
# Heavy binary files
4955
*.jar
50-
*.aar
51-
*.so
52-
*.dylib
53-
*.dll
5456

5557
# Development files
5658
package-lock.json
5759
yarn.lock
5860
tsconfig.json
5961
release.sh
60-
61-
# Development and test files
62-
**/*.test.ts
63-
**/*.test.tsx
64-
**/*.spec.ts
65-
**/*.spec.tsx
62+
dev-link.sh
63+
.prettierrc.js
64+
.eslintrc.js
65+
metro.config.js
66+
ONBOARDING.md

ios/RNMParticle.xcodeproj/project.pbxproj

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

99
/* Begin PBXBuildFile section */
10-
B39BCD8E2E2A06D700FC90B8 /* RNMPRokt.m in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD8A2E2A06D700FC90B8 /* RNMPRokt.m */; };
1110
B39BCD8F2E2A06D700FC90B8 /* RoktEventManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD8C2E2A06D700FC90B8 /* RoktEventManager.m */; };
12-
B39BCD902E2A06D700FC90B8 /* RoktWidgetManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD8D2E2A06D700FC90B8 /* RoktWidgetManager.m */; };
13-
DBDF24DC1E007EB1000F3D73 /* RNMParticle.m in Sources */ = {isa = PBXBuildFile; fileRef = DBDF24DB1E007EB1000F3D73 /* RNMParticle.m */; };
11+
B39BCD962E30562400FC90B8 /* RoktLayoutManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD932E30562400FC90B8 /* RoktLayoutManager.m */; };
12+
B39BCD972E30562400FC90B8 /* RNMPRokt.mm in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD922E30562400FC90B8 /* RNMPRokt.mm */; };
13+
B39BCD982E30562400FC90B8 /* RNMParticle.mm in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD912E30562400FC90B8 /* RNMParticle.mm */; };
14+
B39BCD992E30562400FC90B8 /* RoktNativeLayoutComponentView.mm in Sources */ = {isa = PBXBuildFile; fileRef = B39BCD952E30562400FC90B8 /* RoktNativeLayoutComponentView.mm */; };
1415
DBDF24DD1E007EB1000F3D73 /* RNMParticle.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBDF24DA1E007EB1000F3D73 /* RNMParticle.h */; };
1516
/* End PBXBuildFile section */
1617

@@ -29,13 +30,15 @@
2930

3031
/* Begin PBXFileReference section */
3132
B39BCD892E2A06D700FC90B8 /* RNMPRokt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNMPRokt.h; sourceTree = "<group>"; };
32-
B39BCD8A2E2A06D700FC90B8 /* RNMPRokt.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNMPRokt.m; sourceTree = "<group>"; };
3333
B39BCD8B2E2A06D700FC90B8 /* RoktEventManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RoktEventManager.h; sourceTree = "<group>"; };
3434
B39BCD8C2E2A06D700FC90B8 /* RoktEventManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoktEventManager.m; sourceTree = "<group>"; };
35-
B39BCD8D2E2A06D700FC90B8 /* RoktWidgetManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoktWidgetManager.m; sourceTree = "<group>"; };
35+
B39BCD912E30562400FC90B8 /* RNMParticle.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RNMParticle.mm; sourceTree = "<group>"; };
36+
B39BCD922E30562400FC90B8 /* RNMPRokt.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RNMPRokt.mm; sourceTree = "<group>"; };
37+
B39BCD932E30562400FC90B8 /* RoktLayoutManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoktLayoutManager.m; sourceTree = "<group>"; };
38+
B39BCD942E30562400FC90B8 /* RoktNativeLayoutComponentView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RoktNativeLayoutComponentView.h; sourceTree = "<group>"; };
39+
B39BCD952E30562400FC90B8 /* RoktNativeLayoutComponentView.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RoktNativeLayoutComponentView.mm; sourceTree = "<group>"; };
3640
DBDF24D71E007EB1000F3D73 /* libRNMParticle.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNMParticle.a; sourceTree = BUILT_PRODUCTS_DIR; };
3741
DBDF24DA1E007EB1000F3D73 /* RNMParticle.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNMParticle.h; sourceTree = "<group>"; };
38-
DBDF24DB1E007EB1000F3D73 /* RNMParticle.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNMParticle.m; sourceTree = "<group>"; };
3942
/* End PBXFileReference section */
4043

4144
/* Begin PBXFrameworksBuildPhase section */
@@ -68,13 +71,15 @@
6871
DBDF24D91E007EB1000F3D73 /* RNMParticle */ = {
6972
isa = PBXGroup;
7073
children = (
74+
B39BCD912E30562400FC90B8 /* RNMParticle.mm */,
75+
B39BCD922E30562400FC90B8 /* RNMPRokt.mm */,
76+
B39BCD932E30562400FC90B8 /* RoktLayoutManager.m */,
77+
B39BCD942E30562400FC90B8 /* RoktNativeLayoutComponentView.h */,
78+
B39BCD952E30562400FC90B8 /* RoktNativeLayoutComponentView.mm */,
7179
B39BCD892E2A06D700FC90B8 /* RNMPRokt.h */,
72-
B39BCD8A2E2A06D700FC90B8 /* RNMPRokt.m */,
7380
B39BCD8B2E2A06D700FC90B8 /* RoktEventManager.h */,
7481
B39BCD8C2E2A06D700FC90B8 /* RoktEventManager.m */,
75-
B39BCD8D2E2A06D700FC90B8 /* RoktWidgetManager.m */,
7682
DBDF24DA1E007EB1000F3D73 /* RNMParticle.h */,
77-
DBDF24DB1E007EB1000F3D73 /* RNMParticle.m */,
7883
);
7984
path = RNMParticle;
8085
sourceTree = "<group>";
@@ -137,10 +142,11 @@
137142
isa = PBXSourcesBuildPhase;
138143
buildActionMask = 2147483647;
139144
files = (
140-
DBDF24DC1E007EB1000F3D73 /* RNMParticle.m in Sources */,
141-
B39BCD8E2E2A06D700FC90B8 /* RNMPRokt.m in Sources */,
145+
B39BCD962E30562400FC90B8 /* RoktLayoutManager.m in Sources */,
146+
B39BCD972E30562400FC90B8 /* RNMPRokt.mm in Sources */,
147+
B39BCD982E30562400FC90B8 /* RNMParticle.mm in Sources */,
148+
B39BCD992E30562400FC90B8 /* RoktNativeLayoutComponentView.mm in Sources */,
142149
B39BCD8F2E2A06D700FC90B8 /* RoktEventManager.m in Sources */,
143-
B39BCD902E2A06D700FC90B8 /* RoktWidgetManager.m in Sources */,
144150
);
145151
runOnlyForDeploymentPostprocessing = 0;
146152
};

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 & 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 *)placeholders
65+
roktConfig:(JS::NativeMPRokt::RoktConfigType &)roktConfig
66+
fontFilesMap:(NSDictionary *)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 != nullptr && 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)