【发布时间】:2022-01-10 16:34:17
【问题描述】:
我想在加载初始屏幕时检查访问令牌是否存在。世博会怎么做?
【问题讨论】:
-
文档在这个主题上非常扎实:docs.expo.dev/versions/latest/sdk/splash-screen
标签: javascript react-native expo access-token splash-screen
我想在加载初始屏幕时检查访问令牌是否存在。世博会怎么做?
【问题讨论】:
标签: javascript react-native expo access-token splash-screen
I found the solution :-)
``// import....
import * as SplashScreen from 'expo-splash-screen';
//.......
//.......function
const [appIsReady, setAppIsReady] = useState(false);
//.......
useEffect(()=>{
async function prepare() {
try {
await SplashScreen.preventAutoHideAsync();
await isUser(); // checking for token availability
await new Promise(resolve => setTimeout(resolve, 2000));
} catch (e) {
console.log(e);
} finally {
setAppIsReady(true);
}
};
prepare();
},[]);
const onLayoutRootView = useCallback(async () => {
if (appIsReady) {
await SplashScreen.hideAsync();
}
}, [appIsReady]);
if (!appIsReady) {
return null;
};
return (
<NavigationContainer>
<View style={{flex:1,backgroundColor:"#e0ab24"}} onLayout=
{onLayoutRootView}>
//.....(navigator)
//....
</View>
</NavigationContainer>``
关注文档:https://docs.expo.dev/versions/latest/sdk/splash-screen/
【讨论】: