首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用react- native -router-flux在react native中加载应用程序后隐藏启动画面

如何使用react- native -router-flux在react native中加载应用程序后隐藏启动画面
EN

Stack Overflow用户
提问于 2019-04-22 19:30:00
回答 1查看 1.6K关注 0票数 0

我的应用程序中有闪屏,5秒后它会导航到另一个屏幕。

我想要的是闪屏应该只显示在第一次时,应用程序被加载,一旦用户出来的应用程序和打开它,然后它不应该显示闪屏。

以下是我的代码

代码语言:javascript
复制
import React, { Component } from 'react';
import { View, ImageBackground, StyleSheet, BackHandler, Alert } from 'react-native';
import { Actions } from 'react-native-router-flux';
import colors from '../styles/colors';

class SplashScreen extends Component {

    componentDidMount() {
        // Start counting when the page is loaded
        this.timeoutHandle = setTimeout(() => {
            Actions.welcome()
        }, 5000);
    }

    render() {
        return (
            <View style={styles.container}>
                <ImageBackground
                    source={require('../assets/BSWH-splash.jpg')}
                    style={styles.backgroundImage}
                />
            </View>
        );
    }
}
const styles = StyleSheet.create({
    container: {
        flex: 1,
    },
    backgroundImage: {
        resizeMode: 'stretch',
        flex: 1,
    },
    logoText: {
        fontSize: 34,
        color: colors.white,
        margin: 10,
    },
});
export default SplashScreen;

我使用了react-native-router-flux进行导航

请告诉我如何隐藏闪屏一旦应用程序被加载。

EN

回答 1

Stack Overflow用户

发布于 2019-04-22 20:21:39

这是你使用的一种变通方法。尝试使用npm包来获得完美的结果,最好的npm包是crazycodeboy/react-native-splash-screen

在这里,你可以使用Splashscreen.hide()函数在componentDidMount方法中隐藏SplashScreen。

但是如果你仍然想使用这种方法,你可以尝试

代码语言:javascript
复制
componentDidMount() {
    setTimeout( () => {this.load()}, 2500);       
    }
    load = () => {
      Actions.StartOrder()   //Go to StartOrder screen in 2500ms or 2.5secs
    }

这里,JS的setTimeout()方法将帮助您在您提到的时间间隔内重定向到特定的屏幕!!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55793688

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档