[ react-native-bootsplash 공식문서 ]
모바일 애플리케이션에 스플래시 화면과 앱 아이콘을 추가하기 위한 훌륭한 옵션입니다.
그것은 즉시 스플래시 화면과 앱 아이콘을 생성하는 데 활용할 수 있는 CLI와 함께 제공됩니다.
자세히 살펴봅시다.
Splash Screen에 사용할 4096px x 4096px 로고 이미지 ( .png, .svg ) 파일
$ npm install react-native-bootsplash
+ cd ios && pod install
# --- or ---
$ yarn add react-native-bootsplash
+ cd ios && pod install
$ npx react-native generate-bootsplash [Logo_path] \ [options]
+ cd ios && pod install
# --- or ---
$ yarn react-native generate-bootsplash [Logo_path] \ [options]
+ cd ios && pod install
Project Root 로부터 Logo 파일 위치
예시 ) . / assets / images / logo_ss.png
--platforms <list> Platforms to generate for, separated by a comma (default: "android,ios,web")
--background <string> Background color (in hexadecimal format) (default: "#fff")
--logo-width <number> Logo width at @1x (in dp - we recommend approximately ~100) (default: 100)
--assets-output <string> Assets output directory path
--flavor <string> Android flavor build variant (where your resource directory is) (default: "main")
--html <string> HTML template file path (your web app entry point) (default: "index.html")
--license-key <string> License key to enable brand and dark mode assets generation
--brand <string> Brand file path (PNG or SVG)
--brand-width <number> Brand width at @1x (in dp - we recommend approximately ~80) (default: 80)
--dark-background <string> [dark mode] Background color (in hexadecimal format)
--dark-logo <string> [dark mode] Logo file path (PNG or SVG)
--dark-brand <string> [dark mode] Brand file path (PNG or SVG)
-h, --help display help for command
yarn react-native generate-bootsplash svgs/light_logo.svg \
--platforms=android,ios,web \
--background=F5FCFF \
--logo-width=100 \
--assets-output=assets \
--flavor=main \
--html=index.html \
--license-key=xxxxx \
--brand=svgs/light_brand.svg \
--brand-width=80 \
--dark-background=00090A \
--dark-logo=svgs/dark_logo.svg \
--dark-brand=svgs/dark_brand.svg
>> Android
android/app/src/main/res/values/colors.xml
android/app/src/main/res/drawable-hdpi/bootsplash_logo.png
android/app/src/main/res/drawable-mdpi/bootsplash_logo.png
android/app/src/main/res/drawable-xhdpi/bootsplash_logo.png
android/app/src/main/res/drawable-xxhdpi/bootsplash_logo.png
android/app/src/main/res/drawable-xxxhdpi/bootsplash_logo.png
>> iOS
ios/RNBootSplashExample/BootSplash.storyboard
ios/RNBootSplashExample.xcodeproj/project.pbxproj
ios/RNBootSplashExample/Info.plist
ios/RNBootSplashExample/Images.xcassets/BootSplashLogo.imageset/Contents.json
ios/RNBootSplashExample/Images.xcassets/BootSplashLogo.imageset/bootsplash_logo-<hash>.png
ios/RNBootSplashExample/Images.xcassets/BootSplashLogo.imageset/bootsplash_logo-<hash>@2x.png
ios/RNBootSplashExample/Images.xcassets/BootSplashLogo.imageset/bootsplash_logo-<hash>@3x.png
>> Web
index.html
>> Assets
assets/bootsplash.manifest.json
assets/bootsplash.logo.png
assets/bootsplash.logo@1.5x.png
assets/bootsplash.logo@2x.png
assets/bootsplash.logo@3x.png
assets/bootsplash.logo@4x.png
>> With licence key
{...}
# Thanks for using react-native-bootsplash
# Done in 2.75s.
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Your base theme customization -->
</style>
<!-- BootTheme should inherit from Theme.BootSplash or Theme.BootSplash.EdgeToEdge -->
<style name="BootTheme" parent="Theme.BootSplash">
<item name="bootSplashBackground">@color/bootsplash_background</item>
<item name="bootSplashLogo">@drawable/bootsplash_logo</item>
<item name="bootSplashBrand">@drawable/bootsplash_brand</item> <!-- Only if you have a brand image -->
<item name="postBootSplashTheme">@style/AppTheme</item>
</style>
</resources>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- … -->
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme"> <!-- Apply @style/AppTheme on .MainApplication -->
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true"
android:theme="@style/BootTheme"> <!-- Apply @style/BootTheme on .MainActivity -->
<!-- … -->
</activity>
</application>
</manifest>
// …
// add these required imports:
import android.os.Bundle;
import com.zoontek.rnbootsplash.RNBootSplash;
public class MainActivity extends ReactActivity {
// …
@Override
protected void onCreate(Bundle savedInstanceState) {
RNBootSplash.init(this, R.style.BootTheme); // ⬅️ initialize the splash screen
super.onCreate(savedInstanceState); // super.onCreate(null) with react-native-screens
}
}
// …
// add these required imports:
import android.os.Bundle
import com.zoontek.rnbootsplash.RNBootSplash
class MainActivity : ReactActivity() {
// …
override fun onCreate(savedInstanceState: Bundle?) {
RNBootSplash.init(this, R.style.BootTheme) // ⬅️ initialize the splash screen
super.onCreate(savedInstanceState) // super.onCreate(null) with react-native-screens
}
}
#import "AppDelegate.h"
#import "RNBootSplash.h" // ⬅️ add the header import
// …
@implementation AppDelegate
// …
// ⬇️ Add this before file @end (for react-native 0.74+)
- (void)customizeRootView:(RCTRootView *)rootView {
[RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView]; // ⬅️ initialize the splash screen
}
// OR
// ⬇️ Add this before file @end (for react-native < 0.74)
- (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initProps:(NSDictionary *)initProps {
UIView *rootView = [super createRootViewWithBridge:bridge moduleName:moduleName initProps:initProps];
[RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView]; // ⬅️ initialize the splash screen
return rootView;
}
@end
import { useEffect } from "react";
import { Text } from "react-native";
import BootSplash from "react-native-bootsplash";
type hide = (config?: { fade?: boolean }) => Promise<void>;
const App = () => {
useEffect(() => {
const init = async () => {
// …do multiple sync or async tasks
};
init().finally(async () => {
await BootSplash.hide({ fade: true });
console.log("BootSplash has been hidden successfully");
});
}, []);
return <Text>My awesome app</Text>;
};
------- 사용법 -------
import BootSplash from "react-native-bootsplash";
type isVisible = () => Promise<boolean>;
BootSplash.isVisible().then((value) => console.log(value));
import { NavigationContainer } from "@react-navigation/native";
import BootSplash from "react-native-bootsplash";
const App = () => (
<NavigationContainer
onReady={() => {
BootSplash.hide();
}}
>
{/* content */}
</NavigationContainer>
);
jest.mock("react-native-bootsplash", () => {
return {
hide: jest.fn().mockResolvedValue(),
isVisible: jest.fn().mockResolvedValue(false),
useHideAnimation: jest.fn().mockReturnValue({
container: {},
logo: { source: 0 },
brand: { source: 0 },
}),
};
});
{
"setupFiles": ["<rootDir>/jest/setup.js"]
}
- <resources>
+ <resources xmlns:tools="http://schemas.android.com/tools">
<style name="BootTheme" parent="Theme.BootSplash">
<!-- … -->
+ <!-- Apply color + style to the status bar (true = dark-content, false = light-content) -->
+ <item name="android:statusBarColor" tools:targetApi="m">@color/bootsplash_background</item>
+ <item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
</style>
- <style name="BootTheme" parent="Theme.BootSplash">
+ <style name="BootTheme" parent="Theme.BootSplash.EdgeToEdge">