Socket
Socket
Sign inDemoInstall

expo-asset

Package Overview
Dependencies
Maintainers
26
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expo-asset

An Expo universal module to download assets and pass them into other APIs


Version published
Weekly downloads
531K
decreased by-12.3%
Maintainers
26
Weekly downloads
 
Created

What is expo-asset?

The expo-asset package is a library for managing assets in Expo projects. It provides utilities for loading and caching assets such as images, fonts, and other media files, making it easier to handle these resources in a performant way.

What are expo-asset's main functionalities?

Loading Assets

This feature allows you to load assets such as images. The code sample demonstrates how to load an image asset asynchronously and log its local URI once it is loaded.

import { Asset } from 'expo-asset';

async function loadAssets() {
  const imageAsset = Asset.fromModule(require('./path/to/image.png'));
  await imageAsset.downloadAsync();
  console.log('Image loaded:', imageAsset.localUri);
}

Caching Assets

This feature allows you to cache multiple assets. The code sample demonstrates how to cache an array of image assets asynchronously and log a message once all assets are cached.

import { Asset } from 'expo-asset';

async function cacheAssets() {
  const assets = [
    require('./path/to/image1.png'),
    require('./path/to/image2.png')
  ];
  const cachePromises = assets.map(asset => Asset.fromModule(asset).downloadAsync());
  await Promise.all(cachePromises);
  console.log('All assets cached');
}

Using with Expo's Asset System

This feature demonstrates how to use expo-asset with Expo's AppLoading component to load and cache assets before rendering the main application. The code sample shows how to load an image asset and display a loading screen until the asset is ready.

import { Asset } from 'expo-asset';
import { AppLoading } from 'expo';

export default function App() {
  const [isReady, setIsReady] = useState(false);

  async function loadResources() {
    const imageAsset = Asset.fromModule(require('./path/to/image.png'));
    await imageAsset.downloadAsync();
  }

  if (!isReady) {
    return (
      <AppLoading
        startAsync={loadResources}
        onFinish={() => setIsReady(true)}
        onError={console.warn}
      />
    );
  }

  return (
    <View>
      <Text>App is ready!</Text>
    </View>
  );
}

Other packages similar to expo-asset

Keywords

FAQs

Package last updated on 21 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc