How to use the expo-asset-utils.uriAsync function in expo-asset-utils

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 / packages / expo-three / src / loaders / loadModelsAsync.ts View on Github external
async function loadFileAsync({ asset, extension, funcName }: { asset?: string, extension: string, funcName: string }): Promise {
  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 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,
github expo / expo-three / src / loaders / loadModelsAsync.ts View on Github external
async function loadFileAsync({ asset, funcName }): Promise {
  if (!asset) {
    throw new Error(`ExpoTHREE.${funcName}: Cannot parse a null asset`);
  }
  return await AssetUtils.uriAsync(asset);
}
github expo / expo-pixi / lib / spineAsync.js View on Github external
async function jsonFromResourceAsync(resource) {
  const jsonUrl = await uriAsync(resource);
  const jsonString = await readAsStringAsync(jsonUrl);
  return JSON.parse(jsonString);
}

expo-asset-utils

Utilities for converting files into Expo Assets

MIT
Latest version published 3 years ago

Package Health Score

48 / 100
Full package analysis