React Native | react native splash E0.68.+ error 대응
페이지 정보
작성자 이호섭 조회76,382회 댓글0건본문
https://hallowed-handspring-1c3.notion.site/react-native-splash-E0-68-error-5d5461b93a784c9d8426ece793279878
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;
}
}
}