react-native-splash-screen icon indicating copy to clipboard operation
react-native-splash-screen copied to clipboard

Top margin of android splash screen off by 24dp height

Open steve-else opened this issue 8 years ago • 19 comments

When attempting to use this library to open the splash screen immediately after the initial splash screen loads, the image needs to be offset by about 24dp to account for the height of the status bar. Using this guide I saw that you have to add 24dp marginTop to properly align a center image on the splash screen to make it align properly so you don't see it shift from one splash screen to the next.

The issue is that some devices require you add 24dp, and some require you use -24dp to achieve the right effect. I believe this is somehow due to different devices compensating for the status bar in different ways. The two devices I tested on were a Pixel 2 XL and a Nexus 6p. On the Nexus, 24dp makes both splash screens align perfectly. On the Pixel, -24dp is needed. Has anyone come across this issue before? And more appropriately for this package, is there any plan to match the styling of splash screen called in-app to the one that devices use on their default splash screens?

steve-else avatar Jun 22 '18 18:06 steve-else

I have the same problem. The splash screen looks fine on most devices, but on some devices (Samsung A3) the splash screen jumps down a few pixels. @steve-else did you, by any chance, find a solution for this?

SimonErich avatar Jul 11 '18 15:07 SimonErich

Unfortunately not. It seems different devices seem to handle the splash screen differently, I don't have a solution to fit all android devices correctly.

steve-else avatar Jul 11 '18 17:07 steve-else

Hey guys, any news? I have the same problem.

robsoncoelho avatar Aug 23 '18 19:08 robsoncoelho

Jumping here (no pun intended) to also share experiencing the same issue.

I initially integrated this and tested on a Samsung Galaxy S7 with a margin top of -24dp. Then I switched to a Samsung Galaxy S8 and the difference was huge. I actually had to adjust it to a positive value to (I think it was 24 or 48dp) to avoid the jump. Moving back to Galaxy S7 of course now it jumps...

From what I understand the 24dp compensates for the status bar, and if that's the case, but the question remains why is it a positive value on one phone and a negative one on the other...

Tilwin90 avatar Sep 20 '18 14:09 Tilwin90

any fix to this ? i have the same issue

FadiAboMsalam avatar Nov 16 '18 17:11 FadiAboMsalam

I was able to fix this issue with a few changes to what was given in the guide linked above.

First, in the layout for the splash (launch_screen.xml), don't use an ImageView with margin, just apply the same background drawable that your SplashActivity theme is using:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background_splash"
    android:orientation="vertical">

</LinearLayout>

And in the theme you set on your SplashActivity, use android:background instead of android:windowBackground:

<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:background">@drawable/background_splash</item>
    <item name="android:statusBarColor">@color/primary</item>
</style>

This will make it center the splash within the area between the status bar and the system UI buttons, which is consistent with how react-native-splash-screen is centered and prevents the jump from occurring.

dmchoull avatar Jan 30 '19 15:01 dmchoull

Thank you dmchoull. Your fix helped me.

slightlyprivate avatar Mar 07 '19 05:03 slightlyprivate

I also had to include

<item name="android:windowFullscreen">true</item>

in SplashTheme and pass true to show() in MainActivity as follows

protected void onCreate(Bundle savedInstanceState) {
   SplashScreen.show(this, true);
   super.onCreate(savedInstanceState);
}

to hide the status bar and render the splash image in full screen.

Related issues: #385, #105

acostalima avatar Apr 16 '19 16:04 acostalima

Works on mostly devices, but still jump in Xiaomi Redmi Note 7.

AlanQuadros avatar Aug 29 '19 21:08 AlanQuadros

I also have this problem in Xiaomi Redmi Note 7.

mayconmesquita avatar Oct 07 '19 00:10 mayconmesquita

Hi,

Any updates for Xiaomi devices?

iamacoderguy avatar Mar 01 '20 09:03 iamacoderguy

i have the same problem for Xiaomi devices...

zhanghaoxu avatar Apr 09 '20 13:04 zhanghaoxu

i have the same problem for Xiaomi devices...

For Xiaomi devices or indeed, the devices with Cutout Mode, I used some tips in this post https://github.com/zoontek/react-native-bootsplash/issues/52, especially at this comment https://github.com/zoontek/react-native-bootsplash/issues/52#issuecomment-580366701.

And to make it work for all device models, I had to check the Xiaomi model, and use the configuration for it only.

iamacoderguy avatar Apr 13 '20 02:04 iamacoderguy

@iamacoderguy , how did you check for xiaomi model and the devices with Cutout Mode, for setting splash theme ? can you share the code ?

parth3724 avatar May 08 '20 07:05 parth3724

@iamacoderguy , how did you check for xiaomi model and the devices with Cutout Mode, for setting splash theme ? can you share the code ?

I didn't see the comment, sorry. Might be the following code can help other developers

// file: MainActivity.java
// ...
@Override
  protected void onCreate(Bundle savedInstanceState) {
    int themeId = R.style.SplashTheme;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
      switch (Build.MANUFACTURER) {
        case "Xiaomi":
          themeId = R.style.SplashThemeXiaomi;
          break;
        default:
          break;
      }
    }

    SplashScreen.show(this, themeId);
    super.onCreate(savedInstanceState);
  }
// file: res/values-v28/styles.xml

<resources>
    <style name="SplashThemeXiaomi" parent="SplashTheme">
        <item name="android:windowTranslucentStatus">true</item>
    </style>
</resources>

iamacoderguy avatar Jul 23 '20 03:07 iamacoderguy

I'm having this issue, even in fullscreen i'm getting white space on the top

styles

<style name="SplashScreen" parent="Theme.ReactNative.AppCompat.Light.NoActionBar.FullScreen">
        <item name="android:windowBackground">@color/red</item>
        <item name="android:windowTranslucentNavigation">false</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:windowDrawsSystemBarBackgrounds">false</item>
        <item name="android:windowTranslucentStatus">false</item>
</style>

launch_screen

<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">

    <ImageView
        android:layout_width="128dp"
        android:layout_height="128dp"
        android:scaleType="centerCrop"
        android:src="@mipmap/launch_screen_logo" />

</LinearLayout>

Screenshot_1610539623

inmogr avatar Jan 13 '21 12:01 inmogr

I had this after ejecting from expo, I changed the last argument from false to true on this line in the MainActivity.java despite it having a comment advising against it but it worked.

SplashScreen.show(this, SplashScreenImageResizeMode.CONTAIN, ReactRootView.class, true);

Patrick-Sawyer avatar Feb 24 '21 21:02 Patrick-Sawyer

@dmchoull solution causes a RN crash in my case. Had to set negative margin to the background image.

gentlee avatar Mar 10 '21 12:03 gentlee

Solved by adding under LaunchTheme in styles.xml

<item name="android:windowDrawsSystemBarBackgrounds">false</item>

taniket15 avatar Mar 19 '21 16:03 taniket15