React-native

[React Native] react-native-splash-screen패키지 Android에서 SplashScreen.show(this, R.style.SplashScreenTheme) 적용 안 되는 문제

판교너굴맨 2023. 8. 1. 00:47

이 게시물을 보시는 분들은 react-native-splash-screen 패키지를 적용하고, README 문서대로 statusBar의 color를 바꾸는 작업을 진행하고 있을 거라고 생각이 듭니다.

 

아래는 라이브러리의 문서입니다.

 

If you want to customize the color of the status bar when the splash screen is displayed:

Create android/app/src/main/res/values/colors.xml and add

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="status_bar_color"><!-- Colour of your status bar here --></color>
</resources>

 

Create a style definition for this in android/app/src/main/res/values/styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="SplashScreenTheme" parent="SplashScreen_SplashTheme">
        <item name="colorPrimaryDark">@color/status_bar_color</item>
    </style>
</resources>

 

Change your show method to include your custom style:

MainActivity.java

SplashScreen.show(this, R.style.SplashScreenTheme);

 

statusBar Style을 설정해 주고, 문서대로 mainActivity.java 파일에 SplashScreen.show(this, R.style.SplashScreenTheme);를 작성해 주면 아래와 같은 에러를 만나게 됩니다.

error: incompatible types: int cannot be converted to boolean SplashScreen.show(this, R.style.SplashScreenTheme);

문서대로 했는데 인수의 타입이 다르다고 하니 뭔가 이상하다.. 해당 패키지의 show 클래스를 확인해 봤습니다.

 

android/src/main/java/org/devio/rn/splashscreen/SplashScreen.java

public static void show(final Activity activity, final int themeResId, final boolean fullScreen) {
	...
}

themeResId 외에 boolean 타입의 fullscreen 매개변수가 있는 걸 확인할 수 있습니다.

 

그래서 저는 MainActivity.java 파일에 아래와 같이 수정해서 해결했습니다.

@Override
protected void onCreate(Bundle savedInstanceState) {
    SplashScreen.show(this, R.style.SplashScreenTheme, false);
    super.onCreate(savedInstanceState);
}

 

 

fullscreen을 설정했을 때의 화면은 아래 이슈에서 확인할 수 있습니다.

 

Update README for SplashScreen.show() by saamerm · Pull Request #562 · crazycodeboy/react-native-splash-screen

As mentioned in #559, Updated README for the new function definition for show SplashScreen.show(this, R.style.SplashScreenTheme, true);

github.com