Skip to content

feat: add AndroidEdgeToEdge preference & theme flag #1779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand All @@ -397,6 +417,7 @@ function updateProjectSplashScreen (platformConfig, locations) {
splashBgNode.text = '@color/cdv_splashscreen_background';

[
// Splash Screen
'windowSplashScreenAnimatedIcon',
'windowSplashScreenAnimationDuration',
'android:windowSplashScreenBrandingImage',
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/prepare.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
5 changes: 4 additions & 1 deletion templates/project/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
specific language governing permissions and limitations
under the License.
-->
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen.IconBackground">
<!-- Optional: Set the splash screen background. (Default: #FFFFFF) -->
<item name="windowSplashScreenBackground">@color/cdv_splashscreen_background</item>
Expand All @@ -30,5 +30,8 @@

<!-- Required: Set the theme of the Activity that directly follows your splash screen. -->
<item name="postSplashScreenTheme">@style/Theme.AppCompat.NoActionBar</item>

<!-- Disable Edge-to-Edge for SDK 35 -->
<item name="android:windowOptOutEdgeToEdgeEnforcement" tools:targetApi="35">true</item>
</style>
</resources>
Loading