Spla sh Белое мерцание экрана перед загрузкой (React Native Expo) - PullRequest
0 голосов
/ 04 мая 2020

Когда приложение загружается, появляется белый фон, после чего появляется экран мерцания sh. Я удалил экран spla sh из файла приложения. json, поскольку я вручную загружаю и скрываю экран spla sh. (При выходе из экрана spla sh в приложении. json файл приводит к отображению экрана spla sh с последующим белым мерцанием, а затем снова отображается spla sh scrren)

Приложение. js

import React from 'react';
import { StyleSheet, View, Image } from 'react-native'
import { MyAuthStack, MyMainDrawer } from './Screens/Navigators'
import firebase from './firebase'
import { AppLoading, SplashScreen } from 'expo';
import { Asset } from 'expo-asset';

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      authState: false,
      imgUrl: '',
      isSplashReady: false,
      isAppReady: false,
    }

  }
  _cacheSplashResourcesAsync = async () => {
    const gif = require('./assets/splash.png');
    return Asset.fromModule(gif).downloadAsync();
  }

  _cacheResourcesAsync = async () => {
    SplashScreen.hide();

    const images = [
      require('./assets/addthreadicon.png'),
      require('./assets/500x500.png'),
    ];
    const cacheImages = images.map((image) => Asset.fromModule(image).downloadAsync());

    await Promise.all(cacheImages);
    firebase.auth().onAuthStateChanged(user => {
      if (user != null) {
        const userRef = firebase.database().ref(`users/${firebase.auth().currentUser.uid}/img`)
        userRef.once('value', snapshot => {
          this.setState({ imgUrl: snapshot.val(), authState: true, isAppReady: true })
        })
      } else {
          this.setState({ imgUrl: '', authState: false, isAppReady: true })
      }
    })
  };
  render() {
    const { isSplashReady, isAppReady, authState } = this.state;
    if (!isSplashReady) {
      return (
        <AppLoading
          startAsync={this._cacheSplashResourcesAsync}
          onFinish={() => this.setState({ isSplashReady: true })}
          onError={process.env.NODE_ENV === 'production' ? undefined : console.warn /* eslint-disable-line no-console */}
          autoHideSplash={false}
        />
      );
    }
    return (
      <View style={{ flex: 1 }}>
        {!isAppReady ? (
          <Image
            source={require('./assets/splash.png')}
            onLoad={this._cacheResourcesAsync}
            style={{ width: '100%', height: '100%' }}
          />
        ) : (
            <View style={{ flex: 1 }}>
              {authState ? (<MyMainDrawer imgUrl={this.state.imgUrl} />) : (<MyAuthStack />)}
            </View>
          )
        }
      </View>
    )

  }
}

});

Приложение. json

{
  "expo": {
    "name": "Blank Template",
    "slug": "movie",
    "privacy": "public",
    "sdkVersion": "36.0.0",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "android": {
      "package": "com.saim.moviethreads",
      "versionCode": 1,
      "config": {
        "googleMobileAdsAppId": "" 
      }
    },
    "ios": {
      "supportsTablet": true,
      "bundleIdentifier": "com.yourcompany.yourappname",
      "buildNumber": "1.0.0"
    }

  }
}
...