簡體   English   中英

如何在加載 expo 時檢查某些內容?

[英]How to check something while loading in expo?

我想在加載啟動畫面時檢查訪問令牌是否存在。 如何在 expo 中做到這一點?

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/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM