Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}

Expand All @@ -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
Expand Down
19 changes: 15 additions & 4 deletions plugin/__tests__/withRNOrientationAppDelegate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
14 changes: 9 additions & 5 deletions plugin/src/withRNOrientationAppDelegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}

Expand Down