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

bug: main activity theme is wrongly set up and the background is the splash screen #4787

Closed
rpanadero opened this issue Jul 2, 2021 · 3 comments · Fixed by #4841
Closed
Labels
needs reproduction needs reproducible example to illustrate the issue platform: android

Comments

@rpanadero
Copy link

rpanadero commented Jul 2, 2021

Bug Report

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 3.0.2
  @capacitor/core: 3.0.2
  @capacitor/android: 3.0.2
  @capacitor/ios: 3.0.2

Installed Dependencies:

  @capacitor/cli: 3.0.2
  @capacitor/android: 3.0.2
  @capacitor/core: 3.0.2
  @capacitor/ios: 3.0.2

[success] iOS looking great! 👌
[success] Android looking great! 👌

Platform(s)

  • Android

Current Behavior

The main activity theme of my application is not set properly on Capacitor 3 by BridgeActivity and the background of the main activity is the splash screen.

I found this issue after upgrading to Capacitor 3 and you can reproduce it by opening the application keyboard. While the keyboard is being opened, pay attention to the gap that appears between the keyboard and your application content during 1s approx. because if your splash screen is pink, this gap will look pink. On Capacitor 2 this gap was black and that is the expected behavior. Please, have a look at the video:

Grabacion.de.pantalla.2021-07-02.a.las.10.34.15.mov

After a deep investigation on the bridge activity tasks, I think that the activity theme is set up too late to '@style/AppTheme.NoActionBar', whose background is set up to black by default, what makes the activity still use the theme that says AndroidManifest which is '@style/AppTheme.NoActionBarLaunch', whose background is set up with the splash screen.

https://github.com/ionic-team/capacitor/blob/3.0.2/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java#L65

If you have a look at the implementation, you can realize that the theme is set up during the 'onStart' life cycle because it is there where the bridge and its plugins are initialized automatically.

https://github.com/ionic-team/capacitor/blob/3.0.2/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java#L111
https://github.com/ionic-team/capacitor/blob/3.0.2/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java#L65

Before Capacitor 3, this doesn't happen because it was necessary to invoke 'init' (BridgeActivity method) from 'onCreate' of the application main activity to initialize all Capacitor plugins. Apart from configuring the plugins, this 'init' method also sets up the activity theme, etc. And it seems correct the place and moment where/when the theme should be set up.

To sum up, the difference between Capacitor 2 and Capacitor 3 is that the Capacitor 2 sets up the theme during 'onCreate' method and Capacitor 3 during 'onStart'. In fact, if I force to set the activity theme into the 'onCreate' method of my main activity works:

public class MainActivity extends BridgeActivity {
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(R.style.AppTheme_NoActionBar);
  }
  
}

And calling the 'init' method into the 'onCreate' of the main activity also works properly, although it is highly discouraged by Capacitor because the plugins are not registered automatically by doing this. (NOT TO DO THIS)

public class MainActivity extends BridgeActivity {
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
      add(SplashScreenPlugin.class);
    }});
  }
  
}

Expected Behavior

From my point of view, Capacitor 2 behavior is right and the main activity background should be dark or the value configured in the '@style/AppTheme.NoActionBar' theme.

Code Reproduction

Not provided.

Other Technical Details

npm --version output:
6.14.8

node --version output:
v14.15.0

pod --version output (iOS issues only):
1.10.1

Additional Context

While the issue is being investigated I suggest to set the activity theme into the 'onCreate' method of your main activity.

public class MainActivity extends BridgeActivity {
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(R.style.AppTheme_NoActionBar);
  }
  
}
@jcesarmobile jcesarmobile added the needs reproduction needs reproducible example to illustrate the issue label Jul 2, 2021
@Ionitron
Copy link
Collaborator

Ionitron commented Jul 2, 2021

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks!
Ionitron 💙

@Ionitron Ionitron added the needs reply needs reply from the user label Jul 2, 2021
@rpanadero
Copy link
Author

rpanadero commented Jul 5, 2021

This is the Code Reproduction that demonstrates the issue described in my first comment.

https://github.com/rpanadero/capacitor-issue-4787

Steps to reproduce the issue:

  • Open the app
  • Touch the input

Then, you will see the behavior/issue described while the keyboard is being opened.

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 11, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs reproduction needs reproducible example to illustrate the issue platform: android
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants