React Native Expo : Is there a way to cache the content of a whole directory instead of having to individually write the path of each file

Viewed 18

Usually, you would need to do something similar to this to cache videos and pictures:

SplashScreen.preventAutoHideAsync();

function cacheAssets(images) {
  return images.map((image) => {
    if (typeof image === "string") {
      return Image.prefetch(image);
    } else {
      return Asset.fromModule(image).downloadAsync();
    }
  });
}

export default function App() {
  const [appIsReady, setAppIsReady] = useState(false);

  // Load any resources or data that you need prior to rendering the app
  useEffect(() => {
    async function loadResourcesAndDataAsync() {
      try {
        const Assets = cacheAssets([
          require("./app/assets/salutt_splash_video_no_tagline.mp4"),
          require("./app/assets/AppCustomBackgroundsFrench/LoginOptionsFR1.png"),
          require("./app/assets/AppCustomBackgroundsFrench/SignInFR1.png"),
          etc.,

        ]);

        await Promise.all([...Assets]);
      } catch (e) {
        // You might want to provide this error information to an error reporting service
        console.warn(e);
      } finally {
        setAppIsReady(true);
        setTimeout(SplashScreen.hideAsync, 400);
      }
    }

    loadResourcesAndDataAsync();
  }, []);

  if (!appIsReady) {
    return null;
  }

Is there a way to just put the name of the directory or use recursive wildcards like **/*.png to chose a bunch of files at the same time?

0 Answers
Related