7

Im developing my first React Native app with Expo and are having some troubles with the splash screen.

In my app.json I have set the following under expo:

{
  "expo": {
    "name": "my-iOS-Android-app",
    "slug": "my-iOS-Android-app",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "backgroundColor": "#C808F9"
    },
    "owner": "linus",
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true,
      "bundleIdentifier": "my.test.app"
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#FFFFFF"
      }
    },
    "web": {
      "favicon": "./assets/favicon.png"
    }
  }
} 

I have followed the guide on Expo´s website and this is my code:

useEffect(() => {
    async function prepare() {
      try {
        await SplashScreen.preventAutoHideAsync();
        let data = await fetchData();
        await new Promise(resolve => setTimeout(resolve, 8000));
        setData(data);
      } catch (e) {
        console.warn(e);
      } finally {
        setAppIsReady(true);
      }
    }

    prepare();
    // initSorting();
  }, [])

  const onLayoutRootView = useCallback(async () => {
    if (appIsReady) {
      await SplashScreen.hideAsync();
    }
  }, [appIsReady]);

  if (!appIsReady) {
    return null;
  }

As you can see I have added an 8 second timeout. The purple screen pops up while expo is downloading the code to my phone, then a blank screen is seen for 8 seconds. Im using an iOS device for the testing.

Can someone explain what Im doing wrong? Or have I misunderstood the purpose of expos´s splash screen?

Thanks!

10
  • Can you show the whole app.json file? We should make sure you have that setting in the expo config block. Also, what platform is this on? The docs for splash screen have a small note that changes to the app manifest register differently across Android/iOS: docs.expo.dev/guides/splash-screens Commented Feb 15, 2022 at 21:08
  • @TylerWilliams I have updated my post! Im using an iPhone 13 Pro. Commented Feb 15, 2022 at 21:54
  • Hmm, are you using Expo Go? I'm having the same issues in Expo Go + Expo Snacks. This comment in a different question suggests maybe Splash screen doesn't work in Expo Go, and you may have to try it out in the simulator on its own: stackoverflow.com/a/69289654/12502416 Commented Feb 15, 2022 at 22:52
  • @TylerWilliams Yes, Im using Expo Go. Ok I will try it out on a simulator. Otherwise, would it be a good practise to return a custom splash screen while appIsReady == false? Right now I have a custom splash screen as the initial route in my Drawer Navigator and Im not sure whether this is ok or not. Commented Feb 16, 2022 at 18:31
  • I don't think you're supposed to use the custom splash screen approach, based on the docs here. I haven't done it myself, but it may be one of those scenarios where doing it the "wrong" way is good enough and solves your problem. Let me know if the simulator works and maybe we can add an updated answer to your question. Commented Feb 16, 2022 at 19:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.