Skip to content
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

fix: Add android prefix to windowSplashScreenBrandingImage #1487

Merged
merged 8 commits into from
Sep 16, 2022
18 changes: 11 additions & 7 deletions lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,18 @@ function updateProjectSplashScreen (platformConfig, locations) {
'windowSplashScreenAnimatedIcon',
'windowSplashScreenAnimationDuration',
'windowSplashScreenBackground',
'windowSplashScreenBrandingImage',
'android:windowSplashScreenBrandingImage',
'windowSplashScreenIconBackgroundColor',
'postSplashScreenTheme'
].forEach(themeKey => {
const cdvConfigPrefKey = 'Android' + themeKey.charAt(0).toUpperCase() + themeKey.slice(1);
let index = 0;
if (themeKey.indexOf(':') !== -1) {
index = themeKey.indexOf(':') + 1;
}
const cdvConfigPrefKey = 'Android' + themeKey.charAt(index).toUpperCase() + themeKey.slice(index + 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is better performance or eaiser to read, but what about this?

const themeKeyDescoped = themeKey.replace('android:', '');
const cdvConfigPrefKey = 'Android' + themeKeyDescoped.charAt(0).toUpperCase() + themeKeyDescoped.slice(1);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the if as it's not really necessary, so the code is simpler now, let me know if you still prefer to use the replace.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you have is good. Dont need to use replace.

const cdvConfigPrefValue = platformConfig.getPreference(cdvConfigPrefKey, this.platform);
let themeTargetNode = splashScreenTheme.find(`item[@name="${themeKey}"]`);

console.log('hola', cdvConfigPrefKey);
jcesarmobile marked this conversation as resolved.
Show resolved Hide resolved
switch (themeKey) {
case 'windowSplashScreenBackground':
// use the user defined value for "colors.xml"
Expand All @@ -411,7 +415,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 Down Expand Up @@ -537,7 +541,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 +559,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 +579,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