RN启动页框架初步使用记录 react-native-splash-screen

框架地址
https://github.com/crazycodeboy/react-native-splash-screen/tree/master

问题描述:

由于本人使用的RN版本为0.51
使用 npm i react-native-splash-screen --save安装导入后
出现错度(是由于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.进入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.创建文件夹和文件 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 创建文件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.按照以下方式导入和使用 这里官方文档(#import "RNSplashScreen.h")导入出错)
       
#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
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容