1082815dcSEvan Baconimport { ExpoConfig } from '@expo/config-types'; 2082815dcSEvan Bacon 3082815dcSEvan Baconimport { InfoPlist, InterfaceOrientation } from './IosConfig.types'; 4*8a424bebSJames Ideimport { createInfoPlistPluginWithPropertyGuard } from '../plugins/ios-plugins'; 5082815dcSEvan Bacon 6082815dcSEvan Baconexport const withOrientation = createInfoPlistPluginWithPropertyGuard( 7082815dcSEvan Bacon setOrientation, 8082815dcSEvan Bacon { 9082815dcSEvan Bacon infoPlistProperty: 'UISupportedInterfaceOrientations', 10082815dcSEvan Bacon expoConfigProperty: 'orientation', 11082815dcSEvan Bacon }, 12082815dcSEvan Bacon 'withOrientation' 13082815dcSEvan Bacon); 14082815dcSEvan Bacon 15082815dcSEvan Baconexport function getOrientation(config: Pick<ExpoConfig, 'orientation'>) { 16082815dcSEvan Bacon return config.orientation ?? null; 17082815dcSEvan Bacon} 18082815dcSEvan Bacon 19082815dcSEvan Baconexport const PORTRAIT_ORIENTATIONS: InterfaceOrientation[] = [ 20082815dcSEvan Bacon 'UIInterfaceOrientationPortrait', 21082815dcSEvan Bacon 'UIInterfaceOrientationPortraitUpsideDown', 22082815dcSEvan Bacon]; 23082815dcSEvan Bacon 24082815dcSEvan Baconexport const LANDSCAPE_ORIENTATIONS: InterfaceOrientation[] = [ 25082815dcSEvan Bacon 'UIInterfaceOrientationLandscapeLeft', 26082815dcSEvan Bacon 'UIInterfaceOrientationLandscapeRight', 27082815dcSEvan Bacon]; 28082815dcSEvan Bacon 29082815dcSEvan Baconfunction getUISupportedInterfaceOrientations(orientation: string | null): InterfaceOrientation[] { 30082815dcSEvan Bacon if (orientation === 'portrait') { 31082815dcSEvan Bacon return PORTRAIT_ORIENTATIONS; 32082815dcSEvan Bacon } else if (orientation === 'landscape') { 33082815dcSEvan Bacon return LANDSCAPE_ORIENTATIONS; 34082815dcSEvan Bacon } else { 35082815dcSEvan Bacon return [...PORTRAIT_ORIENTATIONS, ...LANDSCAPE_ORIENTATIONS]; 36082815dcSEvan Bacon } 37082815dcSEvan Bacon} 38082815dcSEvan Bacon 39082815dcSEvan Baconexport function setOrientation( 40082815dcSEvan Bacon config: Pick<ExpoConfig, 'orientation'>, 41082815dcSEvan Bacon infoPlist: InfoPlist 42082815dcSEvan Bacon): InfoPlist { 43082815dcSEvan Bacon const orientation = getOrientation(config); 44082815dcSEvan Bacon 45082815dcSEvan Bacon return { 46082815dcSEvan Bacon ...infoPlist, 47082815dcSEvan Bacon UISupportedInterfaceOrientations: getUISupportedInterfaceOrientations(orientation), 48082815dcSEvan Bacon }; 49082815dcSEvan Bacon} 50