Skip to content

Commit

Permalink
fix: Add android prefix to windowSplashScreenBrandingImage (#1487)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed Sep 16, 2022
1 parent 8a1ffee commit 954d3e0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,12 @@ function updateProjectSplashScreen (platformConfig, locations) {
'windowSplashScreenAnimatedIcon',
'windowSplashScreenAnimationDuration',
'windowSplashScreenBackground',
'windowSplashScreenBrandingImage',
'android:windowSplashScreenBrandingImage',
'windowSplashScreenIconBackgroundColor',
'postSplashScreenTheme'
].forEach(themeKey => {
const cdvConfigPrefKey = 'Android' + themeKey.charAt(0).toUpperCase() + themeKey.slice(1);
const index = themeKey.indexOf(':') + 1;
const cdvConfigPrefKey = 'Android' + themeKey.charAt(index).toUpperCase() + themeKey.slice(index + 1);
const cdvConfigPrefValue = platformConfig.getPreference(cdvConfigPrefKey, this.platform);
let themeTargetNode = splashScreenTheme.find(`item[@name="${themeKey}"]`);

Expand Down Expand Up @@ -411,7 +412,7 @@ function updateProjectSplashScreen (platformConfig, locations) {
updateProjectSplashScreenImage(locations, themeKey, cdvConfigPrefKey, cdvConfigPrefValue);
break;

case 'windowSplashScreenBrandingImage':
case 'android:windowSplashScreenBrandingImage':
// display warning only when set.
if (cdvConfigPrefValue) {
events.emit('warn', `"${themeKey}" is currently not supported by the splash screen compatibility library. https://issuetracker.google.com/issues/194301890`);
Expand All @@ -422,13 +423,14 @@ function updateProjectSplashScreen (platformConfig, locations) {
// force the themes value to `@color/cdv_splashscreen_icon_background`
if (!cdvConfigPrefValue && themeTargetNode) {
splashScreenTheme.remove(themeTargetNode);
delete themes.getroot().attrib['xmlns:tools'];
} else if (cdvConfigPrefValue) {
// if there is no current node, create a new node.
if (!themeTargetNode) {
themeTargetNode = themes.getroot().makeelement('item', { name: themeKey });
themeTargetNode = themes.getroot().makeelement('item', { name: themeKey, 'tools:targetApi': '31' });
splashScreenTheme.append(themeTargetNode);
themes.getroot().attrib['xmlns:tools'] = 'http://schemas.android.com/tools';
}

// set the user defined color.
themeTargetNode.text = '@drawable/ic_cdv_splashscreen_branding';
}
Expand Down Expand Up @@ -537,7 +539,7 @@ function cleanupAndSetProjectSplashScreenImage (srcFile, destFilePath, possibleP
function updateProjectSplashScreenImage (locations, themeKey, cdvConfigPrefKey, cdvConfigPrefValue = '') {
const SPLASH_SCREEN_IMAGE_BY_THEME_KEY = {
windowSplashScreenAnimatedIcon: 'ic_cdv_splashscreen',
windowSplashScreenBrandingImage: 'ic_cdv_splashscreen_branding'
'android:windowSplashScreenBrandingImage': 'ic_cdv_splashscreen_branding'
};

const destFileName = SPLASH_SCREEN_IMAGE_BY_THEME_KEY[themeKey] || null;
Expand All @@ -555,7 +557,7 @@ function updateProjectSplashScreenImage (locations, themeKey, cdvConfigPrefKey,
// Default Drawable Source File
let defaultSrcFilePath = null;

if (themeKey !== 'windowSplashScreenBrandingImage') {
if (themeKey !== 'android:windowSplashScreenBrandingImage') {
try {
// coming from user project
defaultSrcFilePath = require.resolve('cordova-android/templates/project/res/drawable/' + destFileNameExt);
Expand All @@ -575,7 +577,7 @@ function updateProjectSplashScreenImage (locations, themeKey, cdvConfigPrefKey,
}

events.emit(emitType, emmitMessage);
const cleanupOnly = themeKey === 'windowSplashScreenBrandingImage';
const cleanupOnly = themeKey === 'android:windowSplashScreenBrandingImage';
cleanupAndSetProjectSplashScreenImage(defaultSrcFilePath, destFilePath, possiblePreviousDestFilePath, cleanupOnly);
return;
}
Expand Down

0 comments on commit 954d3e0

Please sign in to comment.