Make로 작업하시는 분들에 한해 에러 처리 방법입니다.
Make를 사용안하시는 분들은 1단계 방법추가하시고 SplashScreen.show(this, R.style.SplashScreenTheme, true); 3번째 매개변수 전달하면 됩니다.
- react-native-splash-screen 설치
yarn add react-native-splash-screen
react-naitve link react-native-splash-screen
- @bam.tech/react-native-make 설치
yarn add @bam.tech/react-native-make
react-native set-splash --path 경로 --resize center --background 색상
하시게 되면 아래와 같이 MAinActivity.java에 생성이 될겁니다.
public class MainActivity extends ReactActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashScreenTheme);
super.onCreate(savedInstanceState);
}
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "test";
}
/**
* Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and
* you can specify the rendered you wish to use (Fabric or the older renderer).
*/
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new MainActivityDelegate(this, getMainComponentName());
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashScreenTheme);
super.onCreate(savedInstanceState);
} }
public static class MainActivityDelegate extends ReactActivityDelegate {
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashScreenTheme);
super.onCreate(savedInstanceState);
} public MainActivityDelegate(ReactActivity activity, String mainComponentName) {
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashScreenTheme);
super.onCreate(savedInstanceState);
} super(activity, mainComponentName);
}
@Override
protected ReactRootView createRootView() {
ReactRootView reactRootView = new ReactRootView(getContext());
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
return reactRootView;
}
}
}
여기서 이대로 사용하시게 되면 에러가 발생합니다. 메이커 사용하기 전 MainActivity에서 한가지만 더 추가해서 사용하시면 됩니다.
//MainActivity 상단
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashScreenTheme, true);
super.onCreate(savedInstanceState);
}
전체코드
public class MainActivity extends ReactActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashScreenTheme, true);
super.onCreate(savedInstanceState);
}
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "Onnuri_driving";
}
/**
* Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and
* you can specify the rendered you wish to use (Fabric or the older renderer).
*/
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new MainActivityDelegate(this, getMainComponentName());
}
public static class MainActivityDelegate extends ReactActivityDelegate {
public MainActivityDelegate(ReactActivity activity, String mainComponentName) {
super(activity, mainComponentName);
}
@Override
protected ReactRootView createRootView() {
ReactRootView reactRootView = new ReactRootView(getContext());
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
return reactRootView;
}
}
}
'React Native' 카테고리의 다른 글
Locofy.ai - Figma 를 React, React Native, HTML/CSS, Next.js 코드 변환 (0) | 2022.07.26 |
---|---|
react-native webview 영역이 사라질 경우 앱 꺼지는 문제 (0) | 2022.04.22 |
소셜로그인 진행시 Android hasykey 추출 3가지 방법 (0) | 2022.01.21 |
NPM libs colors, faker 사용 주의 (0) | 2022.01.12 |
Chocolatey로 윈도우에서도 패키지 관리를 해보자 (0) | 2021.11.25 |