yeahzy
주말에 몰아쓰는 개발일기
yeahzy
전체 방문자
오늘
어제
  • 분류 전체보기 (22)
    • 주말에 쓰는 개발일기 (20)
      • javascript (10)
      • java (1)
      • react-native (5)
      • react (2)
    • 모든 일은 평일에 이루어지지 (2)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 파일업로드
  • opener 안될 때
  • event.preventDefault()
  • window.opener
  • next.js기초
  • Ajax
  • 크롬개발자도구오류
  • showModalDialog
  • event.stopPropagation()
  • fileupload
  • 프론트엔드로드맵
  • popup opener
  • Java
  • javascript
  • showModalDialog.js
  • 크롬 opener
  • popup에서 부모창 함수 호출
  • 신입개발자로드맵
  • 개발자역량강화로드맵
  • javascript opener오류

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
yeahzy

주말에 몰아쓰는 개발일기

주말에 쓰는 개발일기/react-native

[react-native] 스플래시 만들기

2022. 6. 4. 19:06

공통

  1. react-native-splash-screen을 설치한다.ios : cd ios && pod install && cd ..
  2. npm install react-native-splash-screen --save
  3. App.js 에서 splash screen을 종료시키는 코드를 추가한다.
import React, {useEffect} from 'react';
import SplashScreen from 'react-native-splash-screen';

//...

const App = () => {
  useEffect(() => {
    SplashScreen.hide();
  }, []);

  return (
    <Provider store={store}>
      <StatusBar barStyle="dark-content" />
      <NavigationContainer />
    </Provider>
  );
};

export default App;

 

 

ios

1. open ios/[project_name].xcworkspace을 실행하여 Xcode를 실행

2. [project_name] > [project_name] > Imagex.xcassets 에서 + 를 누르고 Image Set 을 클릭하여 SplashIcon 을 입력

3. 세가지 사이즈(300px, 600px @x2, 900px @x3)의 png 파일을 끌어넣는다.

4. LaunchScreen.storyBoard 에서 기본적으로 설정되어있는 프로젝트 네임과 Powered by React Native 를 지우고 Background > custom 에서 색상을 변경한다. 두번째 탭에서 코드로 변경할 수 있다.

5. 상단의 + (Library) 를 클릭하고 Image를 검색하여 Image View를 추가한다.

6. SplashIcon를 입력하여 이미지를 선택하고 Content Mode 옵션은 Aspect Fit로 설정한다.

7. AppDelegate.m 에 splash코드를 추가하여 적용하면 된다.

#import "AppDelegate.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNSplashScreen.h"
//...
//...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"juwe"
                                            initialProperties:nil];

  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];

  [RNSplashScreen show];
  return YES;
}
//...

 

 

안드로이드

1. android/app/src/main/res 에서 다음과 같이 디렉토리에 따라 파일을 추가한다.

mipmap-mdpi -> splash_icon.png
mipmap-hdpi -> splash_icon@2x.png
mipmap-xhdpi, mipmap-xxhdpi, mipmap-xxxhdpi -> splash_icon@3x.png
추가 후, 모든 파일이름은 splash_icon1.png, splash_icon2.png로 수정한다.

2. android/app/src/main/res/values/colors.xml 생성

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="splashscreen_bg">#ffffff</color>
    <color name="app_bg">#ffffff</color>
</resources>

3. android/app/src/main/res/values/styles.xml 수정

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:textColor">#000000</item>

        <!-- Add the following line to set the default status bar color for all the app. -->
        <item name="android:statusBarColor">@color/app_bg</item>
        <!-- Add the following line to set the default status bar text color for all the app 
        to be a light color (false) or a dark color (true) -->
        <item name="android:windowLightStatusBar">false</item>
        <!-- Add the following line to set the default background color for all the app. -->
        <item name="android:windowBackground">@color/app_bg</item>
    </style>

    <!-- Adds the splash screen definition -->
    <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:statusBarColor">@color/splashscreen_bg</item>
        <item name="android:background">@color/splashscreen_bg</item>
    </style>

</resources>

4. android/app/src/main/AndroidManifest.xml 수정

<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">

        <activity
          android:name=".SplashActivity"
          android:theme="@style/SplashTheme"
          android:label="@string/app_name">
          <intent-filter>
              <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>
        </activity>

    <!-- ... -->

      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">

         <!-- 삭제 -->
         <!-- <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter> -->
       

      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

5. android/app/src/main/java/com/[package_name]/SplashActivity.java 생성

<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">

        <activity
          android:name=".SplashActivity"
          android:theme="@style/SplashTheme"
          android:label="@string/app_name">
          <intent-filter>
              <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>
        </activity>

    <!-- ... -->

      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">

         <!-- 삭제 -->
         <!-- <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter> -->
       

      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

7. android/app/src/main/res/layout/launch_screen.xml 생성 ⇒ 라이브러리에서 자동으로 읽는 파일. 이름 변경 불가

<?xml version="1.0" encoding="utf-8"?>
<!-- 이미지 두개 들어가도록 커스텀 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/splashscreen_bg"
        android:orientation="vertical">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_gravity="center"
            android:gravity="center_vertical"
            android:orientation="vertical">
        <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:src="@mipmap/splash_icon1"
                android:layout_marginBottom="50dp"/>
    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center_vertical"
            android:orientation="vertical">
        <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/splash_icon2"
                android:layout_gravity="center|bottom"
                android:layout_marginBottom="50dp" />
    </LinearLayout>

</LinearLayout>

'주말에 쓰는 개발일기 > react-native' 카테고리의 다른 글

[react-native] 안드로이드 aab 파일 추출하기  (0) 2022.06.04
[react-native] 안드로이드 디바이스에서 앱 테스트하기  (0) 2022.06.04
[react-native] 웹뷰 프로젝트 생성 및 초기셋팅  (0) 2022.06.04
[react-native] react-native : 이 시스템에서 스크립트를 실행할 수 없으므로 C:\Program Files\nodejs\react-native.ps1 파일을 로드할 수 없습니다.  (0) 2022.06.04
    '주말에 쓰는 개발일기/react-native' 카테고리의 다른 글
    • [react-native] 안드로이드 aab 파일 추출하기
    • [react-native] 안드로이드 디바이스에서 앱 테스트하기
    • [react-native] 웹뷰 프로젝트 생성 및 초기셋팅
    • [react-native] react-native : 이 시스템에서 스크립트를 실행할 수 없으므로 C:\Program Files\nodejs\react-native.ps1 파일을 로드할 수 없습니다.
    yeahzy
    yeahzy
    주말에 몰아 쓰려고 만들었는데 생각보다 주말은 빠르다..

    티스토리툴바