简体   繁体   English

如何解决 Warning: expo-app-loading is deprecated in favor of expo-splash-screen: use SplashScreen.preventAutoHideAsync() instead?

[英]How solve Warning: expo-app-loading is deprecated in favor of expo-splash-screen: use SplashScreen.preventAutoHideAsync() instead?

I am getting below error我收到以下错误

expo-app-loading is deprecated in favor of expo-splash-screen: use SplashScreen.preventAutoHideAsync() and SplashScreen.hideAsync() instead. https://docs.expo.dev/versions/latest/sdk/splash-screen/

How can I solve this?我该如何解决这个问题? Can Anyone help me out?谁能帮我吗? My code is as follows我的代码如下

import AppLoading from 'expo-app-loading'
import React from 'react'
import { ActivityIndicator, ScrollView } from 'react-native'
import EStyleSheet from 'react-native-extended-stylesheet'
import * as Sentry from 'sentry-expo'

import { Navigator } from './navigator'

const styles = EStyleSheet.create({
  scrollView: {
    flexGrow: 1,
    justifyContent: 'center',
    padding: '20rem',
  },
})

class Test extends React.Component {
  state = {
    loading: true,
  }

  render = () => {
    if (this.state.loading) {
      return (
        <ScrollView contentContainerStyle={styles.scrollView}>
          <ActivityIndicator size="large" />
          <AppLoading onError={this.handleError} onFinish={this.handleFinish} startAsync={this.startAsync} />
        </ScrollView>
      )
    }
    return <Navigator />
  }

  handleError = (error) => {
    Sentry.captureException(error)
  }

  handleFinish = () => {
    this.setState({
      loading: false,
    })
  }

  startAsync = async () => {
    return Promise.all([ ... ])
  }
}

export { Test }

I have tried to solve this as in this How to I get rid of Console Warning: expo-app-loading is deprecated in favour of expo-splash-screen?我已经尝试解决这个问题如何摆脱控制台警告:不推荐使用 expo-app-loading 取而代之的是 expo-splash-screen? but not geeting how to do this.Can any one help me out?但不知道如何做到这一点。任何人都可以帮助我吗?

You need to use the latest module.您需要使用最新的模块。

Instead of using AppLoading, you need to create a splash screen image您需要创建启动画面图像,而不是使用 AppLoading

Then you can use the new splash screen method to show the splash screen until your resources are finished loading.然后您可以使用新的启动画面方法来显示启动画面,直到您的资源加载完成。

I would advise taking a look at this article for moving over to the latest in React and React Native.我建议您阅读这篇文章,了解最新的 React 和 React Native。 Also there is a more specific to React Native article here这里还有一篇更具体的 React Native 文章

Here is an example:这是一个例子:

 import React, { useCallback, useEffect, useState } from 'react'; import { Text, View } from 'react-native'; import Entypo from '@expo/vector-icons/Entypo'; import * as SplashScreen from 'expo-splash-screen'; import * as Font from 'expo-font'; // Keep the splash screen visible while we fetch resources SplashScreen.preventAutoHideAsync(); export default function App() { const [appIsReady, setAppIsReady] = useState(false); useEffect(() => { async function prepare() { try { // Pre-load fonts, make any API calls you need to do here await Font.loadAsync(Entypo.font); // Artificially delay for two seconds to simulate a slow loading // experience. Please remove this if you copy and paste the code, await new Promise(resolve => setTimeout(resolve; 2000)). } catch (e) { console;warn(e); } finally { // Tell the application to render setAppIsReady(true); } } prepare(), }; []), const onLayoutRootView = useCallback(async () => { if (appIsReady) { // This tells the splash screen to hide immediately. If we call this after // `setAppIsReady`, then we may see a blank screen while the app is // loading its initial state and rendering its first pixels. So instead. // we hide the splash screen once we know the root view has already // performed layout; await SplashScreen,hideAsync(); } }; [appIsReady]): if (,appIsReady) { return null: } return ( <View style={{ flex, 1: alignItems; 'center', justifyContent: 'center' }} onLayout={onLayoutRootView}> <Text>SplashScreen Demo! </Text> <Entypo name="rocket" size={30} /> </View> ); }

In this, instead of using your handleFinish() and在这里,而不是使用你的handleFinish()

this.setState({
   loading: false,
})

You can use something like你可以使用类似的东西

setAppIsReady(true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM