我有一个默认的react-native 项目,我是从这turorial安装的,我用this tutorial为我的项目添加了一个启动屏幕.然而,现在我明白了:

  • 0.5秒的闪屏照片
  • 然后是1.5秒的白色屏幕
  • 然后我的应用程序启动了,

What is the best and most standard way to fix this problem?

<application
  android:name=".MainApplication"
  android:allowBackup="true"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:theme="@style/AppTheme">
  <activity
    android:name=".SplashActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="adjustResize"
    android:theme="@style/SplashTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
  <activity android:name=".MainActivity" />
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>

推荐答案

First:

Second step(Plugin Installation):
Automatic installation

react-native link react-native-splash-screen or rnpm link react-native-splash-screen

Manual installation
Android:
1: In your android/settings.gradle file, make the following additions:

include ':react-native-splash-screen'   
project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android')

2:在你的android/app/build中.gradle文件,将:react-native-splash-screen项目添加为编译时依赖项:

...
dependencies {
    ...
    compile project(':react-native-splash-screen')
}

3:更新主应用程序.java文件通过以下更改使用react-native-splash-screen:

// react-native-splash-screen >= 0.3.1
import org.devio.rn.splashscreen.SplashScreenReactPackage;
// react-native-splash-screen < 0.3.1
import com.cboy.rn.splashscreen.SplashScreenReactPackage;

public class MainApplication extends Application implements ReactApplication {

    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        @Override
        protected boolean getUseDeveloperSupport() {
            return BuildConfig.DEBUG;
        }

        @Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                    new MainReactPackage(),
            new SplashScreenReactPackage()  //here
            );
        }
    };

    @Override
    public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
    }
}

Example Code:

import React, {Component} from 'react';
import {
    StyleSheet,
    View,
    Text,
    TouchableOpacity,
    Linking,
} from 'react-native'
import SplashScreen from 'react-native-splash-screen'

export default class example extends Component {

    componentDidMount() {
        SplashScreen.hide();
    }


    render() {
        return (
            <TouchableOpacity
                style={styles.container}
                onPress={(e)=> {
                    Linking.openURL('http://www.devio.org/');
                }}
            >
                <View >
                    <Text style={styles.item}>
                        SplashScreen 启动屏
                    </Text>
                    <Text style={styles.item}>
                        @:http://www.devio.org/
                    </Text>
                    <Text style={styles.item}>
                        GitHub:https://github.com/crazycodeboy
                    </Text>
                    <Text style={styles.item}>
                        Email:crazycodeboy@gmail.com
                    </Text>
                </View>
            </TouchableOpacity>
        )
    }

}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#f3f2f2',
        marginTop: 30
    },
    item: {
        fontSize: 20,
    },
    line: {
        flex: 1,
        height: 0.3,
        backgroundColor: 'darkgray',
    },
})

React-native相关问答推荐

如何在Reaction Native中将身体分成三部分

在第二次加载时仅将本机应用程序设置为状态

类似Snapchat的Reaction Native筛选器

如何在 React Native 中正确地将组件导入到我的导航器中?

react native条件渲染

React Native 转换与枢轴点

React Native - ScrollView 中的 ListView 分页?

使用 react-native 设置 Select 器的高度

library not found for -lRCTGeolocation

错误:安装 react-native-elements 后无法识别字体系列 Material Design 图标?

React native Refresh 有效,但下一次调用仍使用最后一个令牌

如何在 react-native 上自动聚焦下一个 TextInput

在Android上更改高度时react-native TextInput显示错误

React Native - Firebase 身份验证持久性不起作用

react-native 中的倒数计时器

如何在 react native 中将数组保存在异步存储中?

INSTALL_FAILED_INSUFFICIENT_STORAGE 运行 npm run android 命令时出错

React native - 以编程方式判断是否启用了远程 JS 调试

zoom 到指定的标记 react-native-maps

如何将图形 API 与 react-native-fbsdk 一起使用?