diff --git a/plugin/__tests__/__snapshots__/withRNOrientationAppDelegate.spec.ts.snap b/plugin/__tests__/__snapshots__/withRNOrientationAppDelegate.spec.ts.snap index 5dd10bb..ccc4a04 100644 --- a/plugin/__tests__/__snapshots__/withRNOrientationAppDelegate.spec.ts.snap +++ b/plugin/__tests__/__snapshots__/withRNOrientationAppDelegate.spec.ts.snap @@ -77,7 +77,7 @@ exports[`withRNOrientationAppDelegate updates the AppDelegate.mm with both heade " `; -exports[`withRNOrientationAppDelegate updates the AppDelegate52.swift with the method implementation having override when sdk is < 53 1`] = ` +exports[`withRNOrientationAppDelegate updates the AppDelegate52.swift with the method implementation having public override when sdk is <= 52 1`] = ` "import UIKit import React import React_RCTAppDelegate @@ -95,9 +95,9 @@ class AppDelegate: RCTAppDelegate { return super.application(application, didFinishLaunchingWithOptions: launchOptions) } -// React Native Orientation Director @generated begin @react-native-orientation-director/supportedInterfaceOrientationsFor-implementation - expo prebuild (DO NOT MODIFY) sync-d346ef386403083e8a91af1cd77a5a77312aacfb +// React Native Orientation Director @generated begin @react-native-orientation-director/supportedInterfaceOrientationsFor-implementation - expo prebuild (DO NOT MODIFY) sync-147d50248b7b55d1acbe02fc03ff4cde90a30975 - override func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { + public override func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { return OrientationDirector.getSupportedInterfaceOrientationsForWindow() } @@ -118,7 +118,88 @@ class AppDelegate: RCTAppDelegate { " `; -exports[`withRNOrientationAppDelegate updates the AppDelegate53.swift with the method implementation without override when sdk is >= 53 1`] = ` +exports[`withRNOrientationAppDelegate updates the AppDelegate53.swift with the method implementation having public override when sdk is greater than or equal to 54 1`] = ` +"import Expo +import React +import ReactAppDependencyProvider + +@UIApplicationMain +public class AppDelegate: ExpoAppDelegate { + var window: UIWindow? + + var reactNativeDelegate: ExpoReactNativeFactoryDelegate? + var reactNativeFactory: RCTReactNativeFactory? + + public override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil + ) -> Bool { + let delegate = ReactNativeDelegate() + let factory = ExpoReactNativeFactory(delegate: delegate) + delegate.dependencyProvider = RCTAppDependencyProvider() + + reactNativeDelegate = delegate + reactNativeFactory = factory + bindReactNativeFactory(factory) + +#if os(iOS) || os(tvOS) + window = UIWindow(frame: UIScreen.main.bounds) + factory.startReactNative( + withModuleName: "main", + in: window, + launchOptions: launchOptions) +#endif + + return super.application(application, didFinishLaunchingWithOptions: launchOptions) + } +// React Native Orientation Director @generated begin @react-native-orientation-director/supportedInterfaceOrientationsFor-implementation - expo prebuild (DO NOT MODIFY) sync-147d50248b7b55d1acbe02fc03ff4cde90a30975 + + public override func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { + return OrientationDirector.getSupportedInterfaceOrientationsForWindow() + } + +// React Native Orientation Director @generated end @react-native-orientation-director/supportedInterfaceOrientationsFor-implementation + + // Linking API + public override func application( + _ app: UIApplication, + open url: URL, + options: [UIApplication.OpenURLOptionsKey: Any] = [:] + ) -> Bool { + return super.application(app, open: url, options: options) || RCTLinkingManager.application(app, open: url, options: options) + } + + // Universal Links + public override func application( + _ application: UIApplication, + continue userActivity: NSUserActivity, + restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void + ) -> Bool { + let result = RCTLinkingManager.application(application, continue: userActivity, restorationHandler: restorationHandler) + return super.application(application, continue: userActivity, restorationHandler: restorationHandler) || result + } +} + +class ReactNativeDelegate: ExpoReactNativeFactoryDelegate { + // Extension point for config-plugins + + override func sourceURL(for bridge: RCTBridge) -> URL? { + // needed to return the correct URL for expo-dev-client. + bridge.bundleURL ?? bundleURL() + } + + override func bundleURL() -> URL? { +#if DEBUG + return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: ".expo/.virtual-metro-entry") +#else + return Bundle.main.url(forResource: "main", withExtension: "jsbundle") +#endif + } +} +" +`; + +exports[`withRNOrientationAppDelegate updates the AppDelegate53.swift with the method implementation without public override when sdk is equal to 53 1`] = ` "import Expo import React import ReactAppDependencyProvider diff --git a/plugin/__tests__/withRNOrientationAppDelegate.spec.ts b/plugin/__tests__/withRNOrientationAppDelegate.spec.ts index 6da7db6..4e6a657 100644 --- a/plugin/__tests__/withRNOrientationAppDelegate.spec.ts +++ b/plugin/__tests__/withRNOrientationAppDelegate.spec.ts @@ -19,25 +19,36 @@ describe('withRNOrientationAppDelegate', function () { expect(result).toMatchSnapshot(); }); - it('updates the AppDelegate52.swift with the method implementation having override when sdk is < 53', async function () { + it('updates the AppDelegate52.swift with the method implementation having public override when sdk is <= 52', async function () { const appDelegatePath = path.join( __dirname, './fixtures/AppDelegate52.swift' ); const appDelegate = await fs.promises.readFile(appDelegatePath, 'utf-8'); - const result = swiftFileUpdater(appDelegate, '52'); + const result = swiftFileUpdater(appDelegate, '52.0.0'); expect(result).toMatchSnapshot(); }); - it('updates the AppDelegate53.swift with the method implementation without override when sdk is >= 53', async function () { + it('updates the AppDelegate53.swift with the method implementation without public override when sdk is equal to 53', async function () { const appDelegatePath = path.join( __dirname, './fixtures/AppDelegate53.swift' ); const appDelegate = await fs.promises.readFile(appDelegatePath, 'utf-8'); - const result = swiftFileUpdater(appDelegate, '53'); + const result = swiftFileUpdater(appDelegate, '53.0.0'); + expect(result).toMatchSnapshot(); + }); + + it('updates the AppDelegate53.swift with the method implementation having public override when sdk is greater than or equal to 54', async function () { + const appDelegatePath = path.join( + __dirname, + './fixtures/AppDelegate53.swift' + ); + const appDelegate = await fs.promises.readFile(appDelegatePath, 'utf-8'); + + const result = swiftFileUpdater(appDelegate, '54.0.0'); expect(result).toMatchSnapshot(); }); }); diff --git a/plugin/src/withRNOrientationAppDelegate.ts b/plugin/src/withRNOrientationAppDelegate.ts index ddbcd90..d1207ee 100644 --- a/plugin/src/withRNOrientationAppDelegate.ts +++ b/plugin/src/withRNOrientationAppDelegate.ts @@ -83,17 +83,21 @@ export function swiftFileUpdater( return ''; } - const sdkVersionAsNumber = Number(_sdkVersion); - if (Number.isNaN(sdkVersionAsNumber)) { + const rawMajor = _sdkVersion.split('.').at(0); + if (!rawMajor) { return ''; } - if (sdkVersionAsNumber >= 53) { + const major = Number(rawMajor); + if (Number.isNaN(major)) { return ''; } - // Older SDK versions need the override keyword - return 'override'; + if (major === 53) { + return ''; + } + + return 'public override'; } }