安装独立apk后的Expo闪屏或白屏

时间:2019-10-17 11:08:18

标签: react-native react-native-android expo

我知道这个问题已经问过几次了,但是我找不到答案。所以我想我会详细说明我的问题。在开发中一切正常。但是,当我制作独立APK时,启动画面不会消失。加载组件后,我什至试图隐藏它。那也行不通。可能是什么问题?

import { SplashScreen } from 'expo';


 componentDidMount() {
    setTimeout(function(){
      SplashScreen.hide();
    },2000);
  }

2 个答案:

答案 0 :(得分:0)

尝试: 创建一个屏幕:SplashScreen.js 并编写下面的代码:

import React, { Component } from 'react';
import { View, StatusBar, Image } from 'react-native';
import introImage from '../assets/IntroPin3.gif';

export default class Loading extends Component {

render() {

return (
  <View style={{ flex: 1, justifyContent:'center', alignItems:'center', backgroundColor: '#FDFDFF' }}>
  <StatusBar hidden />
    <Image
    style={{height:350, width: 350 }}
    source={ introImage}
   />
  </View>
  );
 }
}

并在您的app.js中 写下来:

import React, { Component } from 'react';
import SplashScreen from './Components/SplashScreen.js';
import Intro from './Components/Menu.js';


export default class Index extends Component {
state = {
ready: false,
};
 componentDidMount() {
 setTimeout(() => {
  this.setState({ ready: true });
}, 5530);
}

render() {
if (this.state.ready === false) {
  return <SplashScreen />;
 }
  return <Intro />;
 }
}

如果有帮助,请告诉我。

答案 1 :(得分:0)

import SplashScreen from 'react-native-splash-screen'

export default class WelcomePage extends Component {

componentDidMount() {
    // do stuff while splash screen is shown
    // After having done stuff (such as async tasks) hide the splash screen
    SplashScreen.hide();
 }
}

尝试这个...您还可以阅读文档: https://github.com/crazycodeboy/react-native-splash-screen