Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic with Capacitor removing white screen after splash?

trying to solve the white screen problem after the splash screen then it loads, how do we remove it? i tried to set timeout but still not working.

with cordova i can set it up but i'm failing using capacitor

like image 513
Nedlogs Avatar asked Jan 16 '21 14:01

Nedlogs


People also ask

How do you remove a splash screen in a Capacitor?

You can disable the splash screen by setting launchDuration: 0 in capacitor.

Can I use Capacitor without Ionic?

Do I need to use Ionic Framework with Capacitor? No, you do not need to use Ionic Framework with Capacitor. Without the Ionic Framework, you may need to implement Native UI yourself. Without the Ionic CLI, you may need to configure tooling yourself to enable features such as livereload.

What does Capacitor do in Ionic?

What is Capacitor by Ionic? Capacitor is an open source project that runs modern Web Apps natively on iOS, Android, Electron, and Web (using Progressive Web App technology) while providing a powerful and easy-to-use interface for accessing native SDKs and native APIs on each platform.


3 Answers

Try this.

capacitor.config.json - on plugins

"plugins": {
            "SplashScreen": {
              "launchShowDuration": 5000,
              "launchAutoHide": true,
              "androidScaleType": "CENTER_CROP",
              "androidSplashResourceName": "splash",
              "splashFullScreen": false,
              "splashImmersive": false
            }
          },
          "android": {
            "allowMixedContent": true
          }

And then in android/app/src/main/res/values/styles.xml file:

Change the below:

<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:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowIsTranslucent">true</item>
   </style>

The launchShowDuration is probably what you're after. In case you do get an issue with the splash image width being stretched, the xml will solve that...

like image 183
wiredmartian Avatar answered Oct 16 '22 20:10

wiredmartian


I had the same problem.

capacitor for control needed to install the splashScreen plug-in.

This works for me:

npm i --save @capacitor/splash-screen

capacitor.config.json // .ts

"plugins": {
"SplashScreen": {
  "launchShowDuration": 10000,
  "launchAutoHide": false
}}

app.component.ts

import {SplashScreen} from '@capacitor/splash-screen';
setTimeout(() => {
    SplashScreen.hide();
  }, 2000);
like image 2
HolyMarsia Avatar answered Oct 16 '22 19:10

HolyMarsia


You can change the color in capacitor.config with backgroundColor.

{
    "appId": "io.ionic.starter",
    "appName": "app",
    "webDir": "build",
    "bundledWebRuntime": false,
    "backgroundColor": "#ff0000" // <-- here
}

You don't need download the extra package "@capacitor/SplashScreen" lol.

Disclaimers: I'm speaking for Capacitor v3 and Ionic v5

like image 2
Hyfy Avatar answered Oct 16 '22 19:10

Hyfy