Skip to content

Commit 91d4a30

Browse files
authored
fix: expo plugin breaking due to override keyword needing to be public in version 54 (#95)
1 parent 83d7f3f commit 91d4a30

File tree

3 files changed

+109
-13
lines changed

3 files changed

+109
-13
lines changed

plugin/__tests__/__snapshots__/withRNOrientationAppDelegate.spec.ts.snap

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ exports[`withRNOrientationAppDelegate updates the AppDelegate.mm with both heade
7777
"
7878
`;
7979
80-
exports[`withRNOrientationAppDelegate updates the AppDelegate52.swift with the method implementation having override when sdk is < 53 1`] = `
80+
exports[`withRNOrientationAppDelegate updates the AppDelegate52.swift with the method implementation having public override when sdk is <= 52 1`] = `
8181
"import UIKit
8282
import React
8383
import React_RCTAppDelegate
@@ -95,9 +95,9 @@ class AppDelegate: RCTAppDelegate {
9595
9696
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
9797
}
98-
// React Native Orientation Director @generated begin @react-native-orientation-director/supportedInterfaceOrientationsFor-implementation - expo prebuild (DO NOT MODIFY) sync-d346ef386403083e8a91af1cd77a5a77312aacfb
98+
// React Native Orientation Director @generated begin @react-native-orientation-director/supportedInterfaceOrientationsFor-implementation - expo prebuild (DO NOT MODIFY) sync-147d50248b7b55d1acbe02fc03ff4cde90a30975
9999
100-
override func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
100+
public override func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
101101
return OrientationDirector.getSupportedInterfaceOrientationsForWindow()
102102
}
103103
@@ -118,7 +118,88 @@ class AppDelegate: RCTAppDelegate {
118118
"
119119
`;
120120
121-
exports[`withRNOrientationAppDelegate updates the AppDelegate53.swift with the method implementation without override when sdk is >= 53 1`] = `
121+
exports[`withRNOrientationAppDelegate updates the AppDelegate53.swift with the method implementation having public override when sdk is greater than or equal to 54 1`] = `
122+
"import Expo
123+
import React
124+
import ReactAppDependencyProvider
125+
126+
@UIApplicationMain
127+
public class AppDelegate: ExpoAppDelegate {
128+
var window: UIWindow?
129+
130+
var reactNativeDelegate: ExpoReactNativeFactoryDelegate?
131+
var reactNativeFactory: RCTReactNativeFactory?
132+
133+
public override func application(
134+
_ application: UIApplication,
135+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
136+
) -> Bool {
137+
let delegate = ReactNativeDelegate()
138+
let factory = ExpoReactNativeFactory(delegate: delegate)
139+
delegate.dependencyProvider = RCTAppDependencyProvider()
140+
141+
reactNativeDelegate = delegate
142+
reactNativeFactory = factory
143+
bindReactNativeFactory(factory)
144+
145+
#if os(iOS) || os(tvOS)
146+
window = UIWindow(frame: UIScreen.main.bounds)
147+
factory.startReactNative(
148+
withModuleName: "main",
149+
in: window,
150+
launchOptions: launchOptions)
151+
#endif
152+
153+
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
154+
}
155+
// React Native Orientation Director @generated begin @react-native-orientation-director/supportedInterfaceOrientationsFor-implementation - expo prebuild (DO NOT MODIFY) sync-147d50248b7b55d1acbe02fc03ff4cde90a30975
156+
157+
public override func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
158+
return OrientationDirector.getSupportedInterfaceOrientationsForWindow()
159+
}
160+
161+
// React Native Orientation Director @generated end @react-native-orientation-director/supportedInterfaceOrientationsFor-implementation
162+
163+
// Linking API
164+
public override func application(
165+
_ app: UIApplication,
166+
open url: URL,
167+
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
168+
) -> Bool {
169+
return super.application(app, open: url, options: options) || RCTLinkingManager.application(app, open: url, options: options)
170+
}
171+
172+
// Universal Links
173+
public override func application(
174+
_ application: UIApplication,
175+
continue userActivity: NSUserActivity,
176+
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
177+
) -> Bool {
178+
let result = RCTLinkingManager.application(application, continue: userActivity, restorationHandler: restorationHandler)
179+
return super.application(application, continue: userActivity, restorationHandler: restorationHandler) || result
180+
}
181+
}
182+
183+
class ReactNativeDelegate: ExpoReactNativeFactoryDelegate {
184+
// Extension point for config-plugins
185+
186+
override func sourceURL(for bridge: RCTBridge) -> URL? {
187+
// needed to return the correct URL for expo-dev-client.
188+
bridge.bundleURL ?? bundleURL()
189+
}
190+
191+
override func bundleURL() -> URL? {
192+
#if DEBUG
193+
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: ".expo/.virtual-metro-entry")
194+
#else
195+
return Bundle.main.url(forResource: "main", withExtension: "jsbundle")
196+
#endif
197+
}
198+
}
199+
"
200+
`;
201+
202+
exports[`withRNOrientationAppDelegate updates the AppDelegate53.swift with the method implementation without public override when sdk is equal to 53 1`] = `
122203
"import Expo
123204
import React
124205
import ReactAppDependencyProvider

plugin/__tests__/withRNOrientationAppDelegate.spec.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,36 @@ describe('withRNOrientationAppDelegate', function () {
1919
expect(result).toMatchSnapshot();
2020
});
2121

22-
it('updates the AppDelegate52.swift with the method implementation having override when sdk is < 53', async function () {
22+
it('updates the AppDelegate52.swift with the method implementation having public override when sdk is <= 52', async function () {
2323
const appDelegatePath = path.join(
2424
__dirname,
2525
'./fixtures/AppDelegate52.swift'
2626
);
2727
const appDelegate = await fs.promises.readFile(appDelegatePath, 'utf-8');
2828

29-
const result = swiftFileUpdater(appDelegate, '52');
29+
const result = swiftFileUpdater(appDelegate, '52.0.0');
3030
expect(result).toMatchSnapshot();
3131
});
3232

33-
it('updates the AppDelegate53.swift with the method implementation without override when sdk is >= 53', async function () {
33+
it('updates the AppDelegate53.swift with the method implementation without public override when sdk is equal to 53', async function () {
3434
const appDelegatePath = path.join(
3535
__dirname,
3636
'./fixtures/AppDelegate53.swift'
3737
);
3838
const appDelegate = await fs.promises.readFile(appDelegatePath, 'utf-8');
3939

40-
const result = swiftFileUpdater(appDelegate, '53');
40+
const result = swiftFileUpdater(appDelegate, '53.0.0');
41+
expect(result).toMatchSnapshot();
42+
});
43+
44+
it('updates the AppDelegate53.swift with the method implementation having public override when sdk is greater than or equal to 54', async function () {
45+
const appDelegatePath = path.join(
46+
__dirname,
47+
'./fixtures/AppDelegate53.swift'
48+
);
49+
const appDelegate = await fs.promises.readFile(appDelegatePath, 'utf-8');
50+
51+
const result = swiftFileUpdater(appDelegate, '54.0.0');
4152
expect(result).toMatchSnapshot();
4253
});
4354
});

plugin/src/withRNOrientationAppDelegate.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,21 @@ export function swiftFileUpdater(
8383
return '';
8484
}
8585

86-
const sdkVersionAsNumber = Number(_sdkVersion);
87-
if (Number.isNaN(sdkVersionAsNumber)) {
86+
const rawMajor = _sdkVersion.split('.').at(0);
87+
if (!rawMajor) {
8888
return '';
8989
}
9090

91-
if (sdkVersionAsNumber >= 53) {
91+
const major = Number(rawMajor);
92+
if (Number.isNaN(major)) {
9293
return '';
9394
}
9495

95-
// Older SDK versions need the override keyword
96-
return 'override';
96+
if (major === 53) {
97+
return '';
98+
}
99+
100+
return 'public override';
97101
}
98102
}
99103

0 commit comments

Comments
 (0)