From ea52e9018a99cf29dd4dd69a4bfb1d44e3cb600c Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Tue, 20 Oct 2026 21:48:44 +0300 Subject: [PATCH] [Tablet] gate tablet builds and align app clip configuration (#11797) --- app.config.js | 11 +- .../appConfig.test.js | 50 +++++++ .../withClipInfoPlist.js | 15 +- .../withClipInfoPlist.test.js | 136 ++++++++++++++++++ .../withXcodeTarget.js | 8 +- .../withXcodeTarget.test.js | 68 +++++++++ 6 files changed, 276 insertions(+), 12 deletions(-) create mode 100644 plugins/starterPackAppClipExtension/appConfig.test.js create mode 100644 plugins/starterPackAppClipExtension/withClipInfoPlist.test.js create mode 100644 plugins/starterPackAppClipExtension/withXcodeTarget.test.js diff --git a/app.config.js b/app.config.js index ea2247846..aad075c7f 100644 --- a/app.config.js +++ b/app.config.js @@ -63,7 +63,7 @@ module.exports = function (_config) { userInterfaceStyle: 'automatic', primaryColor: '#006AFF', ios: { - supportsTablet: false, + supportsTablet: IS_DEV || IS_TESTFLIGHT, bundleIdentifier: 'xyz.blueskyweb.app', appleTeamId: process.env.EXPO_APPLE_TEAM_ID, config: { @@ -71,6 +71,13 @@ module.exports = function (_config) { }, icon: IOS_ICON_FILE, infoPlist: { + UISupportedInterfaceOrientations: ['UIInterfaceOrientationPortrait'], + 'UISupportedInterfaceOrientations~ipad': [ + 'UIInterfaceOrientationPortrait', + 'UIInterfaceOrientationPortraitUpsideDown', + 'UIInterfaceOrientationLandscapeLeft', + 'UIInterfaceOrientationLandscapeRight', + ], CADisableMinimumFrameDurationOnPhone: true, UIBackgroundModes: ['remote-notification'], NSUserActivityTypes: ['INSendMessageIntent'], @@ -477,7 +484,7 @@ module.exports = function (_config) { }, }, ], - ['expo-screen-orientation', {initialOrientation: 'PORTRAIT_UP'}], + ['expo-screen-orientation'], ['expo-location'], [ 'expo-contacts', diff --git a/plugins/starterPackAppClipExtension/appConfig.test.js b/plugins/starterPackAppClipExtension/appConfig.test.js new file mode 100644 index 000000000..1ae8b9d32 --- /dev/null +++ b/plugins/starterPackAppClipExtension/appConfig.test.js @@ -0,0 +1,50 @@ +const {IOSConfig} = require('expo/config-plugins') + +const createAppConfig = require('../../app.config') + +const originalBuildEnvironment = process.env.EXPO_PUBLIC_ENV + +afterEach(() => { + if (originalBuildEnvironment === undefined) { + delete process.env.EXPO_PUBLIC_ENV + } else { + process.env.EXPO_PUBLIC_ENV = originalBuildEnvironment + } +}) + +it.each([ + ['local development', undefined, true, '"1,2"'], + ['development', 'development', true, '"1,2"'], + ['end-to-end testing', 'e2e', true, '"1,2"'], + ['TestFlight', 'testflight', true, '"1,2"'], + ['production', 'production', false, '"1"'], +])( + 'gates tablet support and parent device families for %s', + (_name, environment, supportsTablet, expectedDeviceFamilies) => { + if (environment === undefined) { + delete process.env.EXPO_PUBLIC_ENV + } else { + process.env.EXPO_PUBLIC_ENV = environment + } + + const config = createAppConfig({name: 'Bluesky', slug: 'bluesky'}).expo + + expect(config.ios.supportsTablet).toBe(supportsTablet) + expect( + IOSConfig.DeviceFamily.formatDeviceFamilies( + IOSConfig.DeviceFamily.getDeviceFamilies(config), + ), + ).toBe(expectedDeviceFamilies) + expect(config.ios.infoPlist.UISupportedInterfaceOrientations).toEqual([ + 'UIInterfaceOrientationPortrait', + ]) + expect( + config.ios.infoPlist['UISupportedInterfaceOrientations~ipad'], + ).toEqual([ + 'UIInterfaceOrientationPortrait', + 'UIInterfaceOrientationPortraitUpsideDown', + 'UIInterfaceOrientationLandscapeLeft', + 'UIInterfaceOrientationLandscapeRight', + ]) + }, +) diff --git a/plugins/starterPackAppClipExtension/withClipInfoPlist.js b/plugins/starterPackAppClipExtension/withClipInfoPlist.js index e5034cef3..75ea37df0 100644 --- a/plugins/starterPackAppClipExtension/withClipInfoPlist.js +++ b/plugins/starterPackAppClipExtension/withClipInfoPlist.js @@ -1,3 +1,4 @@ +/* eslint-disable import/no-nodejs-modules -- Expo config plugins run in Node. */ const {withInfoPlist} = require('expo/config-plugins') const plist = require('@expo/plist') const path = require('path') @@ -25,14 +26,12 @@ const withClipInfoPlist = (config, {targetName}) => { CFBundleShortVersionString: config.version, CFBundleIconName: 'AppIcon', UIViewControllerBasedStatusBarAppearance: 'NO', - UISupportedInterfaceOrientations: [ - 'UIInterfaceOrientationPortrait', - 'UIInterfaceOrientationPortraitUpsideDown', - ], - 'UISupportedInterfaceOrientations~ipad': [ - 'UIInterfaceOrientationPortrait', - 'UIInterfaceOrientationPortraitUpsideDown', - ], + // Match the parent's resolved orientation and multitasking settings. + UISupportedInterfaceOrientations: + config.modResults.UISupportedInterfaceOrientations, + 'UISupportedInterfaceOrientations~ipad': + config.modResults['UISupportedInterfaceOrientations~ipad'], + UIRequiresFullScreen: config.modResults.UIRequiresFullScreen, }) fs.mkdirSync(path.dirname(targetPath), {recursive: true}) diff --git a/plugins/starterPackAppClipExtension/withClipInfoPlist.test.js b/plugins/starterPackAppClipExtension/withClipInfoPlist.test.js new file mode 100644 index 000000000..1b7b6eb37 --- /dev/null +++ b/plugins/starterPackAppClipExtension/withClipInfoPlist.test.js @@ -0,0 +1,136 @@ +/* eslint-disable import/no-nodejs-modules -- Config plugin tests run in Node. */ +const fs = require('fs') +const {IOSConfig} = require('expo/config-plugins') +const plist = require('@expo/plist').default + +const createAppConfig = require('../../app.config') +const {withClipInfoPlist} = require('./withClipInfoPlist') + +jest.mock('fs', () => ({ + ...jest.requireActual('fs'), + mkdirSync: jest.fn(), + writeFileSync: jest.fn(), +})) + +const allOrientations = [ + 'UIInterfaceOrientationPortrait', + 'UIInterfaceOrientationPortraitUpsideDown', + 'UIInterfaceOrientationLandscapeLeft', + 'UIInterfaceOrientationLandscapeRight', +] + +/** @param {import('@expo/config-types').ExpoConfig} inputConfig */ +async function generateClipInfoPlist(inputConfig) { + const rawConfig = { + ...inputConfig, + ios: { + ...inputConfig.ios, + infoPlist: {...inputConfig.ios?.infoPlist}, + }, + } + + // Match Expo prebuild's registration order: custom plugins, then defaults. + /** @type {import('expo/config-plugins').ExportedConfig} */ + let config = withClipInfoPlist(inputConfig, {targetName: 'BlueskyClip'}) + config = IOSConfig.Orientation.withOrientation(config) + config = IOSConfig.RequiresFullScreen.withRequiresFullScreen(config) + const infoPlistMod = config.mods?.ios?.infoPlist + if (!infoPlistMod) { + throw new Error('Expected an Info.plist mod') + } + const result = await infoPlistMod({ + ...config, + modRawConfig: rawConfig, + modResults: {...rawConfig.ios.infoPlist}, + modRequest: { + projectRoot: '/project', + platformProjectRoot: '/project/ios', + platform: 'ios', + modName: 'infoPlist', + introspect: false, + }, + }) + + expect(fs.writeFileSync).toHaveBeenCalledTimes(1) + const [targetPath, xml] = jest.mocked(fs.writeFileSync).mock.calls[0] + expect(targetPath).toBe('/project/ios/BlueskyClip/Info.plist') + if (typeof xml !== 'string') { + throw new Error('Expected a plist string') + } + const clip = /** @type {import('@expo/plist').PlistObject} */ ( + plist.parse(xml) + ) + return {clip, parent: result.modResults} +} + +describe('App Clip orientations', () => { + beforeEach(() => { + jest.clearAllMocks() + }) + + it('inherits all multitasking orientations from the current app config', async () => { + const {clip, parent} = await generateClipInfoPlist( + createAppConfig({name: 'Bluesky', slug: 'bluesky'}).expo, + ) + + expect(clip['UISupportedInterfaceOrientations~ipad']).toEqual( + allOrientations, + ) + expect(clip.UISupportedInterfaceOrientations).toEqual([ + 'UIInterfaceOrientationPortrait', + ]) + expect(clip.UIRequiresFullScreen).toBe(false) + expect(clip['UISupportedInterfaceOrientations~ipad']).toEqual( + parent['UISupportedInterfaceOrientations~ipad'], + ) + expect(clip).not.toHaveProperty('UIBackgroundModes') + expect(clip.UILaunchScreen).toEqual({}) + expect(clip.NSAppClip).toEqual({ + NSAppClipRequestEphemeralUserNotification: false, + NSAppClipRequestLocationConfirmation: false, + }) + }) + + it.each([ + ['default universal', {ios: {supportsTablet: true}}], + ['portrait phone', {orientation: 'portrait', ios: {supportsTablet: false}}], + [ + 'landscape phone', + {orientation: 'landscape', ios: {supportsTablet: false}}, + ], + ['tablet-only', {orientation: 'portrait', ios: {isTabletOnly: true}}], + [ + 'full-screen tablet', + { + orientation: 'landscape', + ios: { + supportsTablet: true, + requireFullScreen: true, + infoPlist: { + 'UISupportedInterfaceOrientations~ipad': [ + 'UIInterfaceOrientationLandscapeLeft', + ], + }, + }, + }, + ], + ])('matches resolved parent settings for %s', async (_name, options) => { + const {clip, parent} = await generateClipInfoPlist({ + name: 'Bluesky', + slug: 'bluesky', + version: '1.0.0', + ...options, + }) + + for (const key of [ + 'UISupportedInterfaceOrientations', + 'UISupportedInterfaceOrientations~ipad', + 'UIRequiresFullScreen', + ]) { + expect(clip[key]).toEqual(parent[key]) + if (parent[key] === undefined) { + expect(clip).not.toHaveProperty(key) + } + } + }) +}) diff --git a/plugins/starterPackAppClipExtension/withXcodeTarget.js b/plugins/starterPackAppClipExtension/withXcodeTarget.js index 2c6cd4006..18fc77b1f 100644 --- a/plugins/starterPackAppClipExtension/withXcodeTarget.js +++ b/plugins/starterPackAppClipExtension/withXcodeTarget.js @@ -1,4 +1,4 @@ -const {withXcodeProject} = require('expo/config-plugins') +const {IOSConfig, withXcodeProject} = require('expo/config-plugins') const BUILD_PHASE_FILES = ['AppDelegate.swift', 'ViewController.swift'] @@ -54,7 +54,11 @@ const withXcodeTarget = (config, {targetName}) => { buildSettingsObj.PRODUCT_BUNDLE_IDENTIFIER = `"${config.ios?.bundleIdentifier}.AppClip"` buildSettingsObj.SWIFT_EMIT_LOC_STRINGS = 'YES' buildSettingsObj.SWIFT_VERSION = '5.0' - buildSettingsObj.TARGETED_DEVICE_FAMILY = `"1"` + // App Clips must support exactly the same device families as their parent. + buildSettingsObj.TARGETED_DEVICE_FAMILY = + IOSConfig.DeviceFamily.formatDeviceFamilies( + IOSConfig.DeviceFamily.getDeviceFamilies(config), + ) buildSettingsObj.DEVELOPMENT_TEAM = 'B3LX46C5HS' buildSettingsObj.IPHONEOS_DEPLOYMENT_TARGET = '16.4' buildSettingsObj.ASSETCATALOG_COMPILER_APPICON_NAME = 'AppIcon' diff --git a/plugins/starterPackAppClipExtension/withXcodeTarget.test.js b/plugins/starterPackAppClipExtension/withXcodeTarget.test.js new file mode 100644 index 000000000..3b4b80a3d --- /dev/null +++ b/plugins/starterPackAppClipExtension/withXcodeTarget.test.js @@ -0,0 +1,68 @@ +const {IOSConfig} = require('expo/config-plugins') + +const {withXcodeTarget} = require('./withXcodeTarget') + +jest.mock('expo/config-plugins', () => ({ + ...jest.requireActual('expo/config-plugins'), + /** + * @param {unknown} config + * @param {(config: unknown) => unknown} action + */ + withXcodeProject: (config, action) => action(config), +})) + +describe('App Clip device family', () => { + it.each([ + ['default iPhone-only', {}, '"1"'], + ['explicit iPhone-only', {supportsTablet: false}, '"1"'], + ['universal', {supportsTablet: true}, '"1,2"'], + ['tablet-only', {isTabletOnly: true}, '"2"'], + [ + 'tablet-only with tablet support', + {supportsTablet: true, isTabletOnly: true}, + '"2"', + ], + ])('matches the parent for %s builds', (_name, ios, expected) => { + /** @type {Record}>} */ + const configurations = { + APP_DEBUG: {buildSettings: {PRODUCT_NAME: '"Bluesky"'}}, + APP_RELEASE: {buildSettings: {PRODUCT_NAME: '"Bluesky"'}}, + } + const project = { + addTarget: jest.fn(() => { + configurations.CLIP_DEBUG = { + buildSettings: {PRODUCT_NAME: '"BlueskyClip"'}, + } + configurations.CLIP_RELEASE = { + buildSettings: {PRODUCT_NAME: '"BlueskyClip"'}, + } + return {uuid: 'APP_CLIP_TARGET', pbxNativeTarget: {}} + }), + addBuildPhase: jest.fn(), + addPbxGroup: jest.fn(() => ({uuid: 'APP_CLIP_GROUP'})), + addFile: jest.fn(), + pbxXCBuildConfigurationSection: () => configurations, + addTargetAttribute: jest.fn(), + addTargetDependency: jest.fn(), + getFirstTarget: () => ({uuid: 'APP_TARGET'}), + hash: {project: {objects: {}}}, + } + const config = { + name: 'Bluesky', + slug: 'bluesky', + version: '1.0.0', + ios: {bundleIdentifier: 'xyz.blueskyweb.app', ...ios}, + modResults: project, + } + + IOSConfig.DeviceFamily.setDeviceFamily(config, {project}) + withXcodeTarget(config, {targetName: 'BlueskyClip'}) + + for (const buildType of ['DEBUG', 'RELEASE']) { + const parent = configurations[`APP_${buildType}`].buildSettings + const clip = configurations[`CLIP_${buildType}`].buildSettings + expect(parent.TARGETED_DEVICE_FAMILY).toBe(expected) + expect(clip.TARGETED_DEVICE_FAMILY).toBe(parent.TARGETED_DEVICE_FAMILY) + } + }) +}) -- knotmirror 0.0.1