Skip to content

Commit bb4f86e

Browse files
authored
feat: add AndroidEdgeToEdge preference & theme flag (apache#1779)
1 parent d0b5986 commit bb4f86e

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

lib/prepare.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ function cleanWww (projectRoot, locations) {
271271
*/
272272
function updateProjectAccordingTo (platformConfig, locations) {
273273
updateProjectStrings(platformConfig, locations);
274-
updateProjectSplashScreen(platformConfig, locations);
274+
updateProjectTheme(platformConfig, locations);
275275

276276
const name = platformConfig.name();
277277

@@ -376,11 +376,31 @@ function warnForDeprecatedSplashScreen (cordovaProject) {
376376
* be used to update project
377377
* @param {Object} locations A map of locations for this platform
378378
*/
379-
function updateProjectSplashScreen (platformConfig, locations) {
379+
function updateProjectTheme (platformConfig, locations) {
380380
// res/values/themes.xml
381381
const themes = xmlHelpers.parseElementtreeSync(locations.themes);
382382
const splashScreenTheme = themes.find('style[@name="Theme.App.SplashScreen"]');
383383

384+
// Update edge-to-edge settings in app theme.
385+
let hasE2E = false; // default case
386+
387+
const preferenceE2E = platformConfig.getPreference('AndroidEdgeToEdge', this.platform);
388+
if (!preferenceE2E) {
389+
events.emit('verbose', 'The preference name "AndroidEdgeToEdge" was not set. Defaulting to "false".');
390+
} else {
391+
const hasInvalidPreferenceE2E = preferenceE2E !== 'true' && preferenceE2E !== 'false';
392+
if (hasInvalidPreferenceE2E) {
393+
events.emit('verbose', 'Preference name "AndroidEdgeToEdge" has an invalid value. Valid values are "true" or "false". Defaulting to "false"');
394+
}
395+
hasE2E = hasInvalidPreferenceE2E ? false : preferenceE2E === 'true';
396+
}
397+
398+
const optOutE2EKey = 'android:windowOptOutEdgeToEdgeEnforcement';
399+
const optOutE2EItem = splashScreenTheme.find(`item[@name="${optOutE2EKey}"]`);
400+
const optOutE2EValue = !hasE2E ? 'true' : 'false';
401+
optOutE2EItem.text = optOutE2EValue;
402+
events.emit('verbose', `Updating theme item "${optOutE2EKey}" with value "${optOutE2EValue}"`);
403+
384404
let splashBg = platformConfig.getPreference('AndroidWindowSplashScreenBackground', this.platform);
385405
if (!splashBg) {
386406
splashBg = platformConfig.getPreference('SplashScreenBackgroundColor', this.platform);
@@ -397,6 +417,7 @@ function updateProjectSplashScreen (platformConfig, locations) {
397417
splashBgNode.text = '@color/cdv_splashscreen_background';
398418

399419
[
420+
// Splash Screen
400421
'windowSplashScreenAnimatedIcon',
401422
'windowSplashScreenAnimationDuration',
402423
'android:windowSplashScreenBrandingImage',

spec/unit/prepare.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ describe('prepare', () => {
950950

951951
prepare.__set__('updateWww', jasmine.createSpy('updateWww'));
952952
prepare.__set__('updateIcons', jasmine.createSpy('updateIcons').and.returnValue(Promise.resolve()));
953-
prepare.__set__('updateProjectSplashScreen', jasmine.createSpy('updateProjectSplashScreen'));
953+
prepare.__set__('updateProjectTheme', jasmine.createSpy('updateProjectTheme'));
954954
prepare.__set__('warnForDeprecatedSplashScreen', jasmine.createSpy('warnForDeprecatedSplashScreen')
955955
.and.returnValue(Promise.resolve()));
956956
prepare.__set__('updateFileResources', jasmine.createSpy('updateFileResources').and.returnValue(Promise.resolve()));

templates/project/res/values/themes.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
specific language governing permissions and limitations
1818
under the License.
1919
-->
20-
<resources>
20+
<resources xmlns:tools="http://schemas.android.com/tools">
2121
<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen.IconBackground">
2222
<!-- Optional: Set the splash screen background. (Default: #FFFFFF) -->
2323
<item name="windowSplashScreenBackground">@color/cdv_splashscreen_background</item>
@@ -30,5 +30,8 @@
3030

3131
<!-- Required: Set the theme of the Activity that directly follows your splash screen. -->
3232
<item name="postSplashScreenTheme">@style/Theme.AppCompat.NoActionBar</item>
33+
34+
<!-- Disable Edge-to-Edge for SDK 35 -->
35+
<item name="android:windowOptOutEdgeToEdgeEnforcement" tools:targetApi="35">true</item>
3336
</style>
3437
</resources>

0 commit comments

Comments
 (0)