If you are using the @capacitor/splash-screen API to show a splash screen in your Ionic Android app with Capacitor 3 you might run into this issue:
Problem
For a fraction of a second the splash image will be shown distorted until it is shown in the correct aspect ratio. That means that it also "jumps" a bit on the screen This will especially be noticeable if you launch the app while the device is in landscape orientation or if you your device has stretched or fat display aspect ratio.
Background Info
It happens because AppTheme.NoActionBarLaunch
that is used on app launch for MainActivity
is set up to have the splash image as the background image, but the "real" splash image is initialized a couple of milliseconds later in the SplasScreen.buildViews()
method of the plugin.
Solution
To fix it, you can change the following in your styles.xml
file under /android/app/src/main/values
:
Old:
<style name="AppTheme.NoActionBarLaunch" parent="AppTheme.NoActionBar">
<item name="android:background">@drawable/splash</item>
</style>
New (no background):
<style name="AppTheme.NoActionBarLaunch" parent="AppTheme.NoActionBar">
<item name="android:background">@null</item>
</style>
Or set the background color of your splash screen:
<style name="AppTheme.NoActionBarLaunch" parent="AppTheme.NoActionBar">
<item name="android:background">#ffffff</item>
</style>
This will prevent the showing of the splash image as a background image before the actual ImageView is added to the view hierarchy. The ImageView will have the correct scaleType as defined in androidScaleType
of the plugin configuration.
Tested with the following versions:
- @capacitor/android: 3.0.0-rc.0
- @capacitor/splash-screen: 0.3.6
- @ionic/angular: 5.6.3
The following configuration is used:
const config: CapacitorConfig = {
// ...
plugins: {
SplashScreen: {
launchShowDuration: 3000,
launchAutoHide: false,
backgroundColor: '#ffffffff',
androidSplashResourceName: 'splash',
androidScaleType: 'CENTER_CROP',
showSpinner: false,
splashFullScreen: false,
splashImmersive: false,
},
},
// ...
};
Note: No need to call SplashScreen.show()
in the TypeScript (Ionic) code, it will automatically be shown. Just call SplashScreen.hide()
in your TypeScript code once you want to hide the SplashScreen.