UNPKG

@react-native-tvos/config-tv

Version:

Config plugin to reconfigure native directories for Apple TV and Android TV development if needed

63 lines (62 loc) 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.withTVXcodeProject = void 0; exports.setXcodeProjectBuildSettings = setXcodeProjectBuildSettings; const config_plugins_1 = require("expo/config-plugins"); const utils_1 = require("./utils"); /** * Reads the existing IPHONEOS_DEPLOYMENT_TARGET from the Xcode project build settings. * This represents Expo's default iOS deployment target as set during prebuild. */ function getExpoDefaultIosDeploymentTarget(project) { const configurations = project.pbxXCBuildConfigurationSection(); // @ts-ignore for (const { buildSettings } of Object.values(configurations || {})) { if (buildSettings?.IPHONEOS_DEPLOYMENT_TARGET) { return buildSettings.IPHONEOS_DEPLOYMENT_TARGET; } } return undefined; } const withTVXcodeProject = (config, params) => { return (0, config_plugins_1.withXcodeProject)(config, async (config) => { const expoDefaultIosDeploymentTarget = getExpoDefaultIosDeploymentTarget(config.modResults); const deploymentTarget = (0, utils_1.tvosDeploymentTarget)(params, config, expoDefaultIosDeploymentTarget); config.modResults = await setXcodeProjectBuildSettings(config, { project: config.modResults, params, deploymentTarget, }); return config; }); }; exports.withTVXcodeProject = withTVXcodeProject; function setXcodeProjectBuildSettings(_, { project, params, deploymentTarget, }) { const configurations = project.pbxXCBuildConfigurationSection(); // @ts-ignore for (const { buildSettings } of Object.values(configurations || {})) { // Guessing that this is the best way to emulate Xcode. // Using `project.addToBuildSettings` modifies too many targets. if (buildSettings !== undefined) { buildSettings.SDKROOT = "appletvos"; } if (typeof buildSettings?.PRODUCT_NAME !== "undefined") { (0, utils_1.verboseLog)(`modifying target ${buildSettings?.PRODUCT_NAME} for tvOS`, { params, platform: "ios", property: "xcodeproject", }); buildSettings.TARGETED_DEVICE_FAMILY = "3"; buildSettings.TVOS_DEPLOYMENT_TARGET = deploymentTarget; if (typeof buildSettings?.IOS_DEPLOYMENT_TARGET !== "undefined") { delete buildSettings?.IOS_DEPLOYMENT_TARGET; } if (params.appleTVImages) { // set the app icon source buildSettings.ASSETCATALOG_COMPILER_APPICON_NAME = "TVAppIcon"; buildSettings.ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = "YES"; } } } return project; }