fix(mobile): fix stupid builds oml
This commit is contained in:
3 files changed
+192
-1
No files matched your search
@@ -65,7 +65,9 @@
|
||||
}
|
||||
],
|
||||
"expo-image",
|
||||
"expo-status-bar"
|
||||
"expo-status-bar",
|
||||
"./plugins/with-ios-pod-deployment-target.js",
|
||||
"./plugins/with-ios-scene-lifecycle.js"
|
||||
],
|
||||
"experiments": {
|
||||
"typedRoutes": true
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
const { createRequire } = require("module");
|
||||
|
||||
const expoRequire = createRequire(require.resolve("expo/package.json"));
|
||||
const { withPodfile } = expoRequire("@expo/config-plugins");
|
||||
|
||||
const MARKER = "Xcode 26 rejects Pod deployment targets below iOS 15.0";
|
||||
|
||||
const DEPLOYMENT_TARGET_FIX = `
|
||||
# ${MARKER}. Resource bundles keep the podspec
|
||||
# version (AsyncStorage 13.4, RNSVG 12.4); React Native only bumps native targets.
|
||||
installer.pods_project.targets.each do |target|
|
||||
target.build_configurations.each do |build_config|
|
||||
deployment_target = build_config.build_settings['IPHONEOS_DEPLOYMENT_TARGET']
|
||||
next if deployment_target.nil?
|
||||
next unless deployment_target.to_s.match?(/\\A\\d+(?:\\.\\d+)?\\z/)
|
||||
if deployment_target.to_f < 15.1
|
||||
build_config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.1'
|
||||
end
|
||||
end
|
||||
end
|
||||
`;
|
||||
|
||||
function insertPodDeploymentTargetFix(contents) {
|
||||
if (contents.includes(MARKER)) {
|
||||
return contents;
|
||||
}
|
||||
|
||||
const call = "react_native_post_install(";
|
||||
const start = contents.indexOf(call);
|
||||
if (start === -1) {
|
||||
throw new Error(
|
||||
"Podfile is missing react_native_post_install, so the iOS deployment target fix could not be applied.",
|
||||
);
|
||||
}
|
||||
|
||||
let depth = 0;
|
||||
for (let index = start + call.length - 1; index < contents.length; index += 1) {
|
||||
const character = contents[index];
|
||||
if (character === "(") {
|
||||
depth += 1;
|
||||
} else if (character === ")") {
|
||||
depth -= 1;
|
||||
if (depth === 0) {
|
||||
const end = index + 1;
|
||||
return `${contents.slice(0, end)}\n${DEPLOYMENT_TARGET_FIX}${contents.slice(end)}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
"Podfile has an unbalanced react_native_post_install call, so the iOS deployment target fix could not be applied.",
|
||||
);
|
||||
}
|
||||
|
||||
/** Raise Pod target deployment targets to the Xcode 26 minimum. */
|
||||
function withIosPodDeploymentTarget(config) {
|
||||
return withPodfile(config, (mod) => {
|
||||
mod.modResults.contents = insertPodDeploymentTargetFix(mod.modResults.contents);
|
||||
return mod;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = withIosPodDeploymentTarget;
|
||||
module.exports.insertPodDeploymentTargetFix = insertPodDeploymentTargetFix;
|
||||
@@ -0,0 +1,125 @@
|
||||
const { createRequire } = require("module");
|
||||
|
||||
const expoRequire = createRequire(require.resolve("expo/package.json"));
|
||||
const { withAppDelegate, withInfoPlist } = expoRequire("@expo/config-plugins");
|
||||
|
||||
const WINDOW_BLOCK = `#if os(iOS) || os(tvOS)
|
||||
window = UIWindow(frame: UIScreen.main.bounds)
|
||||
factory.startReactNative(
|
||||
withModuleName: "main",
|
||||
in: window,
|
||||
launchOptions: launchOptions)
|
||||
#endif`;
|
||||
|
||||
const SCENE_DELEGATE = `
|
||||
@objc(SceneDelegate)
|
||||
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
var window: UIWindow?
|
||||
|
||||
func scene(
|
||||
_ scene: UIScene,
|
||||
willConnectTo session: UISceneSession,
|
||||
options connectionOptions: UIScene.ConnectionOptions
|
||||
) {
|
||||
guard let windowScene = scene as? UIWindowScene,
|
||||
let appDelegate = UIApplication.shared.delegate as? AppDelegate
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
if let existingWindow = window {
|
||||
existingWindow.windowScene = windowScene
|
||||
return
|
||||
}
|
||||
|
||||
let window = UIWindow(windowScene: windowScene)
|
||||
self.window = window
|
||||
appDelegate.window = window
|
||||
appDelegate.reactNativeFactory?.startReactNative(
|
||||
withModuleName: "main",
|
||||
in: window,
|
||||
launchOptions: appDelegate.launchOptions
|
||||
)
|
||||
|
||||
deliver(connectionOptions, to: appDelegate)
|
||||
}
|
||||
|
||||
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
|
||||
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
|
||||
for context in URLContexts {
|
||||
_ = appDelegate.application(UIApplication.shared, open: context.url, options: [:])
|
||||
}
|
||||
}
|
||||
|
||||
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
|
||||
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
|
||||
_ = appDelegate.application(
|
||||
UIApplication.shared,
|
||||
continue: userActivity,
|
||||
restorationHandler: { _ in }
|
||||
)
|
||||
}
|
||||
|
||||
private func deliver(
|
||||
_ connectionOptions: UIScene.ConnectionOptions,
|
||||
to appDelegate: AppDelegate
|
||||
) {
|
||||
for context in connectionOptions.urlContexts {
|
||||
_ = appDelegate.application(UIApplication.shared, open: context.url, options: [:])
|
||||
}
|
||||
for userActivity in connectionOptions.userActivities {
|
||||
_ = appDelegate.application(
|
||||
UIApplication.shared,
|
||||
continue: userActivity,
|
||||
restorationHandler: { _ in }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
function enableSceneLifecycle(contents) {
|
||||
if (contents.includes("@objc(SceneDelegate)")) {
|
||||
return contents;
|
||||
}
|
||||
if (!contents.includes(WINDOW_BLOCK)) {
|
||||
throw new Error(
|
||||
"AppDelegate.swift is missing the UIWindow startup block, so the UIScene lifecycle could not be applied.",
|
||||
);
|
||||
}
|
||||
|
||||
let next = contents.replace(
|
||||
"var window: UIWindow?\n",
|
||||
"var window: UIWindow?\n var launchOptions: [UIApplication.LaunchOptionsKey: Any]?\n",
|
||||
);
|
||||
next = next.replace(
|
||||
WINDOW_BLOCK,
|
||||
" // The window is created in SceneDelegate. This SDK refuses to launch without a UIScene.\n self.launchOptions = launchOptions",
|
||||
);
|
||||
return `${next.trimEnd()}\n${SCENE_DELEGATE}`;
|
||||
}
|
||||
|
||||
/** Adopt the UIScene lifecycle required by the current iOS SDK. */
|
||||
function withIosSceneLifecycle(config) {
|
||||
config = withInfoPlist(config, (mod) => {
|
||||
mod.modResults.UIApplicationSceneManifest = {
|
||||
UIApplicationSupportsMultipleScenes: false,
|
||||
UISceneConfigurations: {
|
||||
UIWindowSceneSessionRoleApplication: [
|
||||
{
|
||||
UISceneConfigurationName: "Default Configuration",
|
||||
UISceneDelegateClassName: "SceneDelegate",
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
return mod;
|
||||
});
|
||||
|
||||
return withAppDelegate(config, (mod) => {
|
||||
mod.modResults.contents = enableSceneLifecycle(mod.modResults.contents);
|
||||
return mod;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = withIosSceneLifecycle;
|
||||
Reference in new issue
Block a user