From bb4f86e7b90314da848dfba453b130c64ffbc3f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Fri, 14 Mar 2025 12:22:05 +0900 Subject: [PATCH] feat: add AndroidEdgeToEdge preference & theme flag (#1779) --- lib/prepare.js | 25 +++++++++++++++++++++++-- spec/unit/prepare.spec.js | 2 +- templates/project/res/values/themes.xml | 5 ++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/prepare.js b/lib/prepare.js index 5206e508..aebadb4a 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -271,7 +271,7 @@ function cleanWww (projectRoot, locations) { */ function updateProjectAccordingTo (platformConfig, locations) { updateProjectStrings(platformConfig, locations); - updateProjectSplashScreen(platformConfig, locations); + updateProjectTheme(platformConfig, locations); const name = platformConfig.name(); @@ -376,11 +376,31 @@ function warnForDeprecatedSplashScreen (cordovaProject) { * be used to update project * @param {Object} locations A map of locations for this platform */ -function updateProjectSplashScreen (platformConfig, locations) { +function updateProjectTheme (platformConfig, locations) { // res/values/themes.xml const themes = xmlHelpers.parseElementtreeSync(locations.themes); const splashScreenTheme = themes.find('style[@name="Theme.App.SplashScreen"]'); + // Update edge-to-edge settings in app theme. + let hasE2E = false; // default case + + const preferenceE2E = platformConfig.getPreference('AndroidEdgeToEdge', this.platform); + if (!preferenceE2E) { + events.emit('verbose', 'The preference name "AndroidEdgeToEdge" was not set. Defaulting to "false".'); + } else { + const hasInvalidPreferenceE2E = preferenceE2E !== 'true' && preferenceE2E !== 'false'; + if (hasInvalidPreferenceE2E) { + events.emit('verbose', 'Preference name "AndroidEdgeToEdge" has an invalid value. Valid values are "true" or "false". Defaulting to "false"'); + } + hasE2E = hasInvalidPreferenceE2E ? false : preferenceE2E === 'true'; + } + + const optOutE2EKey = 'android:windowOptOutEdgeToEdgeEnforcement'; + const optOutE2EItem = splashScreenTheme.find(`item[@name="${optOutE2EKey}"]`); + const optOutE2EValue = !hasE2E ? 'true' : 'false'; + optOutE2EItem.text = optOutE2EValue; + events.emit('verbose', `Updating theme item "${optOutE2EKey}" with value "${optOutE2EValue}"`); + let splashBg = platformConfig.getPreference('AndroidWindowSplashScreenBackground', this.platform); if (!splashBg) { splashBg = platformConfig.getPreference('SplashScreenBackgroundColor', this.platform); @@ -397,6 +417,7 @@ function updateProjectSplashScreen (platformConfig, locations) { splashBgNode.text = '@color/cdv_splashscreen_background'; [ + // Splash Screen 'windowSplashScreenAnimatedIcon', 'windowSplashScreenAnimationDuration', 'android:windowSplashScreenBrandingImage', diff --git a/spec/unit/prepare.spec.js b/spec/unit/prepare.spec.js index 374eb26a..c93f02a3 100644 --- a/spec/unit/prepare.spec.js +++ b/spec/unit/prepare.spec.js @@ -950,7 +950,7 @@ describe('prepare', () => { prepare.__set__('updateWww', jasmine.createSpy('updateWww')); prepare.__set__('updateIcons', jasmine.createSpy('updateIcons').and.returnValue(Promise.resolve())); - prepare.__set__('updateProjectSplashScreen', jasmine.createSpy('updateProjectSplashScreen')); + prepare.__set__('updateProjectTheme', jasmine.createSpy('updateProjectTheme')); prepare.__set__('warnForDeprecatedSplashScreen', jasmine.createSpy('warnForDeprecatedSplashScreen') .and.returnValue(Promise.resolve())); prepare.__set__('updateFileResources', jasmine.createSpy('updateFileResources').and.returnValue(Promise.resolve())); diff --git a/templates/project/res/values/themes.xml b/templates/project/res/values/themes.xml index 9190bbb5..9465ca08 100644 --- a/templates/project/res/values/themes.xml +++ b/templates/project/res/values/themes.xml @@ -17,7 +17,7 @@ specific language governing permissions and limitations under the License. --> - +