capacitor-assets icon indicating copy to clipboard operation
capacitor-assets copied to clipboard

Splash Screen is squashed on Android

Open potije opened this issue 4 years ago • 16 comments

My splash.png resource has the correct resolution of 2732x2732, and yet when I run cordova-res and test the app on my phone it is clearly squashed... Is there something I am missing, because I have not read about anyone with this problem.

Original: splash

Squashed: splash-squashed

potije avatar Oct 02 '20 08:10 potije

Can confirm this, we are experiencing the same issue. On iOS it seems to work fine.

basvdijk avatar Oct 12 '20 07:10 basvdijk

It looks like adding "--fit contain" in the cordova-res command get rid of this issue. Because the default resizing method is --fit cover.

Amatewasu avatar Oct 24 '20 22:10 Amatewasu

@Amatewasu I've tried this, but it gives a square squeezed splash screen.

basvdijk avatar Oct 24 '20 23:10 basvdijk

Finally, I also have the same issue and I don't know how to get rid of it.

Amatewasu avatar Oct 24 '20 23:10 Amatewasu

Can confirm that I am also struggling with the same issue for Android.

"@capacitor/android": "^2.4.4",
"@capacitor/cli": "2.4.4",
"@capacitor/core": "2.4.4",

talhaazhar avatar Dec 08 '20 19:12 talhaazhar

Seems like adding androidScaleType value helped me for Android. I do not know the equivalent for Cordova, but for Capacitor it was as simple as editing the capacitor.config.json:

"SplashScreen": {
    "androidScaleType": "CENTER_CROP"
}

Also, here is a list of scale types to pick from.

talhaazhar avatar Dec 09 '20 16:12 talhaazhar

I was having the same problem, and adding this to config.xml fixed it:

<preference name="SplashMaintainAspectRatio" value="true" />

(I've only tested on my Android phone, so can't say for sure if it works as intended in all cases)

robertadamsonsmith avatar Dec 30 '20 01:12 robertadamsonsmith

@talhaazhar when I use this option I still briefly see the stretched splashscreen before it shows correctly. Did you have the same?

basvdijk avatar Dec 30 '20 12:12 basvdijk

@basvdijk I had to settle for diving into the native side and creating a 9-Patch File for Splash Screens.

Honestly worth spending the time to create one and never having to worry about it if you have already made the switch from Cordova to Capacitor. I found cordova-res support for Capacitor to be a little limited as of yet (even for icons) and @romannurik Android Asset Studio is a life-saver.

talhaazhar avatar Jan 04 '21 18:01 talhaazhar

The problem, as far as I can see it, is that the splash screen is rendered with a resolution that does not include the bottom navigation bar. The default settings hide the bottom navigation bar which leaves us with a stretched splash screen.

After a night of trial and error I found a combination of settings that keeps a margin on the bottom of the screen (so the splash screen doesn't stretch) and fills it with a color.

You can generate the images as normal: cordova-res android --skip-config --copy

Next modify two files:

capacitor.config.json should contain this (replace backgroundColor with something that suits your design):

"plugins": {
    "SplashScreen": {
      "launchAutoHide": false,
      "androidScaleType": "CENTER_CROP",
      "splashImmersive": true,
      "backgroundColor": "#00405b"
    }
  },

android\app\src\main\res\values\styles.xml change:

<style name="AppTheme.NoActionBarLaunch" parent="AppTheme.NoActionBar">
        <item name="android:background">@drawable/splash</item>
</style>

to:

<style name="AppTheme.NoActionBarLaunch" parent="AppTheme.NoActionBar">
        <item name="android:background">@drawable/splash</item>
        <item name="android:windowIsTranslucent">true</item>
</style>

Run npx cap sync android so capacitor can put everything in the right place

Don't be fooled by the emulator, it doesn't show it correctly. Test it on a real device by exporting and installing the apk.

credits to this SO post that got me (finally) in the right direction: https://stackoverflow.com/a/68858732

holygekko avatar Aug 23 '21 20:08 holygekko

@talhaazhar thanks for linking the 9-patch article. At the end it mentions changing <bitmap to <nine-patch, but I'm not seeing how to do this. The "launch_splash.xml" mentioned in the article no longer exists anywhere. Do you remember what you did?

dminkovsky avatar Sep 23 '21 06:09 dminkovsky

@dminkovsky the tutorial is using an older version of Capacitor. I am assuming that you are using Capacitor 2+? If so, simple delete the splash folder under res/drawable and make sure that you are using the splash.9.png file name (as mentioned in the tutorial.

talhaazhar avatar Sep 24 '21 13:09 talhaazhar

@talhaazhar thanks a lot for the reply.

Yep, I am on v2 still. So it's just a naming convention? I thought this might be the case, but I had a few blocking issues that prevented me from just trying it out.

Thanks again for this lead. Using the 9 patch definitely seems like the better approach.

dminkovsky avatar Sep 24 '21 17:09 dminkovsky

I have same issue with ionic5/6 and capacitor3. but this solution is works perfectly: https://stackoverflow.com/a/69659719/2059039

thanks @holygekko

progcode avatar Feb 10 '22 19:02 progcode

The issue I had was with in capacitor.config.js

Eventually I found that androidScaleType doesn't work if you've set useDialog to true. Once I changed my config to the following, everything worked fine.

plugins: {
    SplashScreen: {
      launchShowDuration: 3000,
      launchAutoHide: true,
      backgroundColor: "#ffffffff",
      androidSplashResourceName: "splash",
      androidScaleType: "CENTER_CROP",
      showSpinner: false,
      splashFullScreen: true,
      splashImmersive: true,
      layoutName: "launch_screen",
      useDialog: false,
    },
  },

uncoded-apps avatar Jun 02 '22 15:06 uncoded-apps

All went belly up with Capacitor 4.

Using 9 patch images keeps the aspect ratio in portrait mode, but the splash screen is still squashed in landscape mode, why is that?

mirko77 avatar Aug 08 '22 17:08 mirko77

Closing as this isn't an issue with the @capacitor/assets new version of the tool. If it is, please let me know and I'll reopen. If this should be filed in the Capacitor repo please file an issue there instead, thanks.

mlynch avatar Oct 02 '22 21:10 mlynch

Whoever stambles upon on this issue, please see https://stackoverflow.com/questions/66285483/ionic-capacitor-android-splash-screen-responsiveness .

gelinger777 avatar Jun 24 '23 20:06 gelinger777