框架地址
https://github.com/crazycodeboy/react-native-splash-screen/tree/master
問題描述:
由于本人使用的RN版本為0.51
使用 npm i react-native-splash-screen --save安裝導(dǎo)入后
出現(xiàn)錯度(是由于android studio版本原因)
com.android.support:appcompat-v7:26.0.1
...
所以使用(以下命令安裝較早版本按照框架步驟)
1.npm i react-native-splash-screen@3.0.6 --save
2.react-native link react-native-splash-screen
Android:
3.進(jìn)入MainActivity.java 添加以下代碼
...
import android.os.Bundle;
import org.devio.rn.splashscreen.SplashScreen;
public class MainActivity extends ReactActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this);
super.onCreate(savedInstanceState);
}
// ...other code
}
4.創(chuàng)建文件夾和文件 launch_screen.xml in app/src/main/res/layout
4.1 在launch_screen.xml文件中寫入
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/launch_screen">
</LinearLayout>
4.2 創(chuàng)建文件app/src/main/res/values/colors.xml 在colors.xml寫入
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary_dark">#000000</color>
</resources>
iOS:
5.按照以下方式導(dǎo)入和使用 這里官方文檔(#import "RNSplashScreen.h")導(dǎo)入出錯)
#import "SplashScreen.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
// ...other code
[RNSplashScreen show];
return YES;
}
@end
5.1 可以使用 LaunchImage or LaunchScreen.xib