在使用带钩子的功能组件时,如何实现加载资源的同时显示闪屏?使用带有钩子的应用程序加载和/或启动屏幕的模式是什么?
Thanks!
Bill
如果你只明白Hook's useState
,这是一个非常容易的改变。这可以简单地转换为函数,并使用以下方法解析状态值hooks
。如果你改变这个例子AppLoading
to Hook
,下面的代码如下。
AppLoading使用Hooks
import React, { useState } from 'react';
import { View ,Image } from "react-native";
import { Asset } from 'expo-asset';
import { AppLoading } from 'expo';
export default function App() {
const [isReady, setReady] = useState(false);
const _cacheResourcesAsync = async () => {
const images = [require('./assets/snack-icon.png')];
const cacheImages = images.map(image => {
return Asset.fromModule(image).downloadAsync();
});
return Promise.all(cacheImages);
}
return (
isReady === false ? ( <AppLoading
startAsync={_cacheResourcesAsync}
onFinish={() => setReady(true)}
onError={console.warn}
/>) : (<View style={{ flex: 1 }}>
<Image source={require('./assets/snack-icon.png')} />
</View>)
);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)