Skip to content

Commit 7617445

Browse files
all: add modulemap for swift module
1 parent c2882b7 commit 7617445

File tree

4 files changed

+142
-7
lines changed

4 files changed

+142
-7
lines changed

ios/RNBatch.modulemap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
framework module RNBatch {
2+
3+
umbrella header "RNBatch.h"
4+
5+
export *
6+
module * { export * }
7+
}

plugin/src/__tests__/withReactNativeBatchAppDelegate.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { appDelegateExpectedFixture, appDelegateFixture } from '../fixtures/appDelegate';
2+
import { swift_appDelegateExpectedFixture, swift_appDelegateFixture } from '../fixtures/swift_appDelegate';
23
import { modifyAppDelegate } from '../ios/withReactNativeBatchAppDelegate';
34

45
describe(modifyAppDelegate, () => {
@@ -8,3 +9,11 @@ describe(modifyAppDelegate, () => {
89
expect(result).toEqual(appDelegateExpectedFixture);
910
});
1011
});
12+
13+
describe(modifyAppDelegate, () => {
14+
it('should modify the swift_AppDelegate', () => {
15+
const result = modifyAppDelegate(swift_appDelegateFixture);
16+
17+
expect(result).toEqual(swift_appDelegateExpectedFixture);
18+
});
19+
});
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
export const swift_appDelegateFixture = `import React
2+
import Expo
3+
4+
@main
5+
public class AppDelegate: ExpoAppDelegate {
6+
public override func application(
7+
_ application: UIApplication,
8+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
9+
) -> Bool {
10+
self.moduleName = "main"
11+
self.initialProps = [:]
12+
13+
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
14+
}
15+
16+
public override func bundleURL() -> URL? {
17+
#if DEBUG
18+
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: ".expo/.virtual-metro-entry")
19+
#else
20+
return Bundle.main.url(forResource: "main", withExtension: "jsbundle")
21+
#endif
22+
}
23+
24+
// Linking API
25+
public override func application(
26+
_ app: UIApplication,
27+
open url: URL,
28+
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
29+
) -> Bool {
30+
return super.application(app, open: url, options: options) || RCTLinkingManager.application(app, open: url, options: options)
31+
}
32+
33+
// Universal Links
34+
public override func application(
35+
_ application: UIApplication,
36+
continue userActivity: NSUserActivity,
37+
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
38+
) -> Bool {
39+
let result = RCTLinkingManager.application(application, continue: userActivity, restorationHandler: restorationHandler)
40+
return super.application(application, continue: userActivity, restorationHandler: restorationHandler) || result
41+
}
42+
}`;
43+
44+
export const swift_appDelegateExpectedFixture = `import React
45+
46+
import RNBatch
47+
import Expo
48+
49+
@main
50+
public class AppDelegate: ExpoAppDelegate {
51+
public override func application(
52+
_ application: UIApplication,
53+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
54+
) -> Bool {
55+
RNBatch.start()
56+
57+
self.moduleName = "main"
58+
self.initialProps = [:]
59+
60+
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
61+
}
62+
63+
public override func bundleURL() -> URL? {
64+
#if DEBUG
65+
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: ".expo/.virtual-metro-entry")
66+
#else
67+
return Bundle.main.url(forResource: "main", withExtension: "jsbundle")
68+
#endif
69+
}
70+
71+
// Linking API
72+
public override func application(
73+
_ app: UIApplication,
74+
open url: URL,
75+
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
76+
) -> Bool {
77+
return super.application(app, open: url, options: options) || RCTLinkingManager.application(app, open: url, options: options)
78+
}
79+
80+
// Universal Links
81+
public override func application(
82+
_ application: UIApplication,
83+
continue userActivity: NSUserActivity,
84+
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
85+
) -> Bool {
86+
let result = RCTLinkingManager.application(application, continue: userActivity, restorationHandler: restorationHandler)
87+
return super.application(application, continue: userActivity, restorationHandler: restorationHandler) || result
88+
}
89+
}`;
Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,39 @@
11
import { ConfigPlugin, withAppDelegate } from '@expo/config-plugins';
22

3-
const DID_FINISH_LAUNCHING_WITH_OPTIONS_DECLARATION =
3+
// MARK : - Objectif-c
4+
5+
const DID_FINISH_LAUNCHING_WITH_OPTIONS_OBJC_DECLARATION =
46
'- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions\n{';
7+
const IMPORT_OBJC_BATCH = '\n\n#import <RNBatchPush/RNBatch.h>\n';
8+
const REGISTER_OBJC_BATCH = '\n [RNBatch start];\n';
9+
10+
export const modifyObjCDelegate = (contents: string): string => {
11+
return modifyDelegate(contents, IMPORT_OBJC_BATCH, DID_FINISH_LAUNCHING_WITH_OPTIONS_OBJC_DECLARATION, REGISTER_OBJC_BATCH);
12+
};
513

6-
const IMPORT_BATCH = '\n\n#import <RNBatchPush/RNBatch.h>\n';
7-
const REGISTER_BATCH = '\n [RNBatch start];\n';
14+
// MARK : - Swift
15+
16+
const DID_FINISH_LAUNCHING_WITH_OPTIONS_SWIFT_DECLARATION = `@main
17+
public class AppDelegate: ExpoAppDelegate {
18+
public override func application(
19+
_ application: UIApplication,
20+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
21+
) -> Bool {`;
22+
const IMPORT_SWIFT_BATCH = '\n\nimport RNBatch\n';
23+
const REGISTER_SWIFT_BATCH = '\n RNBatch.start()\n';
24+
25+
export const modifySwiftDelegate = (contents: string): string => {
26+
return modifyDelegate(contents, IMPORT_SWIFT_BATCH, DID_FINISH_LAUNCHING_WITH_OPTIONS_SWIFT_DECLARATION, REGISTER_SWIFT_BATCH);
27+
};
828

9-
export const modifyAppDelegate = (contents: string) => {
10-
contents = contents.replace('\n', IMPORT_BATCH);
29+
// MARK : - Common
1130

12-
const [beforeDeclaration, afterDeclaration] = contents.split(DID_FINISH_LAUNCHING_WITH_OPTIONS_DECLARATION);
31+
export const modifyDelegate = (contents: string, importBatch: string, declaration: string, register: string): string => {
32+
contents = contents.replace('\n', importBatch);
1333

14-
const newAfterDeclaration = DID_FINISH_LAUNCHING_WITH_OPTIONS_DECLARATION.concat(REGISTER_BATCH).concat(afterDeclaration);
34+
const [beforeDeclaration, afterDeclaration] = contents.split(declaration);
35+
36+
const newAfterDeclaration = declaration.concat(register).concat(afterDeclaration);
1537

1638
contents = beforeDeclaration.concat(newAfterDeclaration);
1739
return contents;
@@ -23,3 +45,11 @@ export const withReactNativeBatchAppDelegate: ConfigPlugin<object | void> = conf
2345
return config;
2446
});
2547
};
48+
49+
export const modifyAppDelegate = (content: string): string => {
50+
return isObjCDelegate(content) ? modifyObjCDelegate(content) : modifySwiftDelegate(content);
51+
};
52+
53+
const isObjCDelegate = (content: string): boolean => {
54+
return content.includes('@interface AppDelegate () <RCTBridgeDelegate>');
55+
};

0 commit comments

Comments
 (0)