How to use expo-asset-utils - 10 common examples

To help you get started, we’ve selected a few expo-asset-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github expo / expo-pixi / lib / spineAsync.js View on Github external
'loadSpineAsync: Please provide a valid resource for the `json` prop'
    );
    return null;
  } else {
    if (typeof json === 'number') {
      _json = await jsonFromResourceAsync(json);
    } else if (typeof json === 'object') {
      if (json.bones) {
        _json = json;
      } else {
        _json = await jsonFromResourceAsync(json);
      }
    }
  }
  // Downlaod the atlas file
  const atlasUrl = await uriAsync(atlas);
  const _atlas = await readAsStringAsync(atlasUrl);

  if (!_json || typeof _atlas !== 'string') {
    console.error(
      'loadSpine: Invalid props. Please provide: `{ json: Object, atlas: string, assetProvider: Function }`'
    );
  }

  const customAssetProvider = async (line, callback) => {
    const getAsset = async () => {
      if (isFunction(assetProvider)) {
        return new Promise(async res => {
          const resource = await assetProvider(line, res);
          if (resource) {
            res(resource);
          }
github expo / expo-three / src / TextureLoader.ts View on Github external
(async () => {
      const nativeAsset = await AssetUtils.resolveAsync(asset);

      function parseAsset(image) {
        texture.image = image;

        // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
        texture.format = formatFromURI(nativeAsset.localUri);
        texture.needsUpdate = true;

        if (onLoad !== undefined) {
          onLoad(texture);
        }
      }

      if (Platform.OS === 'web') {
        loader.load(
          nativeAsset.localUri,
github EvanBacon / Expo-Voxel / App.js View on Github external
get files() {
    return [
      ...AssetUtils.arrayFromObject(Assets.images || {}),
      // ...AssetUtils.arrayFromObject(Assets.models || {})
    ];
  }
github EvanBacon / Expo-Voxel / App.js View on Github external
async preloadAssets() {
    await AssetUtils.cacheAssetsAsync({
      // fonts: this.fonts,
      files: this.files,
      // audio: this.audio,
    });
    this.setState({ loading: false });
  }
github expo / expo / packages / expo-three / src / loaders / loadModelsAsync.ts View on Github external
async function loadFileAsync({ asset, extension, funcName }: { asset?: string, extension: string, funcName: string }): Promise<string | undefined> {
  if (!asset) {
    console.error(`ExpoTHREE.${funcName}: Cannot parse a null asset`);
    return;
  }
  let uri;
  try {
    uri = await AssetUtils.uriAsync(asset);
  } catch ({ message }) {
    const customErrorMessage = provideBundlingExtensionErrorMessage({
      extension,
      funcName,
    });
    console.error(customErrorMessage, message);
  }
  if (uri == null || typeof uri !== 'string' || uri === '') {
    console.error(
      `ExpoTHREE.${funcName}: Invalid \`localUri\` was retrieved from \`asset\` prop:`,
      uri
    );
  }
  if (!uri.match(`/\.${extension}$/i`)) {
    console.error(
      `ExpoTHREE.${funcName}: the \`asset\` provided doesn't have the correct extension of: .${extension}. URI: ${uri}`
github expo / expo / packages / expo-three / build / loaders / loadModelsAsync.js View on Github external
async function loadFileAsync({ asset, extension, funcName }) {
    if (!asset) {
        console.error(`ExpoTHREE.${funcName}: Cannot parse a null asset`);
        return;
    }
    let uri;
    try {
        uri = await AssetUtils.uriAsync(asset);
    }
    catch ({ message }) {
        const customErrorMessage = provideBundlingExtensionErrorMessage({
            extension,
            funcName,
        });
        console.error(customErrorMessage, message);
    }
    if (uri == null || typeof uri !== 'string' || uri === '') {
        console.error(`ExpoTHREE.${funcName}: Invalid \`localUri\` was retrieved from \`asset\` prop:`, uri);
    }
    if (!uri.match(`/\.${extension}$/i`)) {
        console.error(`ExpoTHREE.${funcName}: the \`asset\` provided doesn't have the correct extension of: .${extension}. URI: ${uri}`);
    }
    return;
}
github reggie3 / react-native-webview-quilljs / WebViewQuillJS / WebViewQuill.tsx View on Github external
private loadHTMLFile = async () => {
    try {
      let asset: Asset = await AssetUtils.resolveAsync(INDEX_FILE_PATH);
      let fileString: string = await FileSystem.readAsStringAsync(
        asset.localUri
      );

      this.setState({ webviewContent: fileString });
    } catch (error) {
      console.warn(error);
      console.warn("Unable to resolve index file");
    }
  };
github reggie3 / react-native-webview-quilljs / WebViewQuillEditor.js View on Github external
componentDidMount = async () => {
    try {
      const asset = await AssetUtils.resolveAsync(requiredAsset)
      console.log({asset})
      this.setState({ asset })
    } catch (error) {
      console.log({ error })
    }
  };
github expo / expo-three / build / loaders / loadModelsAsync.js View on Github external
async function loadFileAsync({ asset, funcName }) {
    if (!asset) {
        throw new Error(`ExpoTHREE.${funcName}: Cannot parse a null asset`);
    }
    return await AssetUtils.uriAsync(asset);
}
export async function loadMtlAsync({ asset, onAssetRequested }) {
github expo / expo-three / build / loadAsync.js View on Github external
export default async function loadAsync(res, onProgress, onAssetRequested = function () { }) {
    let urls = await resolveAsset(res);
    if (!urls) {
        throw new Error(`ExpoTHREE.loadAsync: Cannot parse undefined assets. Please pass valid resources for: ${res}.`);
    }
    const asset = urls[0];
    let url = await uriAsync(asset);
    if (url == null) {
        throw new Error(`ExpoTHREE.loadAsync: this asset couldn't be downloaded. Be sure that your app.json contains the correct extensions.`);
    }
    if (urls.length == 1) {
        if (url.match(/\.(jpeg|jpg|gif|png)$/)) {
            return loadTextureAsync({ asset });
        }
        else if (url.match(/\.assimp$/i)) {
            const arrayBuffer = await loadArrayBufferAsync({ uri: url, onProgress });
            const AssimpLoader = loaderClassForExtension('assimp');
            const loader = new AssimpLoader();
            return loader.parse(arrayBuffer, onAssetRequested);
        }
        else if (url.match(/\.dae$/i)) {
            return loadDaeAsync({
                asset: url,

expo-asset-utils

Utilities for converting files into Expo Assets

MIT
Latest version published 1 year ago

Package Health Score

52 / 100
Full package analysis