How to use the expo-asset.Asset.fromModule function in expo-asset

To help you get started, we’ve selected a few expo-asset 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 Marwan01 / food-converter / node_modules / expo-font / src / Font.ts View on Github external
function _getAssetForSource(source: FontSource): Asset {
  if (source instanceof Asset) {
    return source;
  }

  if (!isWeb && typeof source === 'string') {
    return Asset.fromURI(source);
  }

  if (isWeb || typeof source === 'number') {
    return Asset.fromModule(source);
  }

  // @ts-ignore Error: Type 'string' is not assignable to type 'Asset'
  // We can't have a string here, we would have thrown an error if !isWeb
  // or returned Asset.fromModule if isWeb.
  return source;
}
github expo / expo / packages / expo-font / src / FontLoader.ts View on Github external
export function getAssetForSource(source: FontSource): Asset | FontResource {
  if (source instanceof Asset) {
    return source;
  }

  if (typeof source === 'string') {
    return Asset.fromURI(source);
  } else if (typeof source === 'number') {
    return Asset.fromModule(source);
  } else if (typeof source === 'object' && typeof source.uri !== 'undefined') {
    return getAssetForSource(source.uri);
  }

  // @ts-ignore Error: Type 'string' is not assignable to type 'Asset'
  // We can't have a string here, we would have thrown an error if !isWeb
  // or returned Asset.fromModule if isWeb.
  return source;
}
github flow-typed / flow-typed / definitions / npm / expo-asset_v4.x.x / flow_v0.104.x- / test_expo-asset.js View on Github external
it('should passes when used properly', () => {
      Asset.fromModule('uri').downloadAsync();
      Asset.fromModule(1).downloadAsync();
    });
github expo / expo / packages / expo-av / src / AV.ts View on Github external
function _getAssetFromPlaybackSource(source?: PlaybackSource | null): Asset | null {
  if (source == null) {
    return null;
  }

  let asset: Asset | null = null;
  if (typeof source === 'number') {
    asset = Asset.fromModule(source);
  } else if (source instanceof Asset) {
    asset = source;
  }
  return asset;
}
github calebnance / expo-multi-screen-starter / src / constants / functions.js View on Github external
return Object.values(images).map(image => {
    if (typeof image === 'string') {
      return Image.prefetch(image);
    }

    return Asset.fromModule(image).downloadAsync();
  });
};
github expo / expo / apps / native-component-list / src / screens / ImageManipulatorScreen.tsx View on Github external
async componentDidMount() {
    const image = Asset.fromModule(
      require('../../assets/images/example2.jpg')
    );
    await image.downloadAsync();
    this.setState({
      ready: true,
      image,
      original: image,
    });
  }
github expo / expo-asset-utils / src / cacheAssetsAsync.js View on Github external
  return files.map(file => Asset.fromModule(file).downloadAsync());
}

expo-asset

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

MIT
Latest version published 11 days ago

Package Health Score

89 / 100
Full package analysis