How to use the expo-media-library.getAssetsAsync function in expo-media-library

To help you get started, we’ve selected a few expo-media-library 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 / apps / native-component-list / src / screens / MediaLibrary / MediaLibraryScreen.tsx View on Github external
async loadMoreAssets(currentAssets = this.state.assets, cursor = this.state.endCursor) {
    if (
      this.isLoadingAssets ||
      (cursor === this.state.endCursor && this.state.hasNextPage === false)
    ) {
      return;
    }

    const { state } = this;
    const album = this.getAlbum();

    this.isLoadingAssets = true;

    const { assets, endCursor, hasNextPage } = await MediaLibrary.getAssetsAsync({
      first: PAGE_SIZE,
      after: cursor,
      mediaType: state.mediaType,
      sortBy: state.sortBy,
      album: album && album.id,
    });

    const lastAsset = currentAssets[currentAssets.length - 1];

    if (!lastAsset || lastAsset.id === cursor) {
      this.setState({
        assets: ([] as MediaLibrary.Asset[]).concat(currentAssets, assets),
        endCursor,
        hasNextPage,
        refreshing: false,
      });
github hyakt / expo-multiple-media-imagepicker / src / ImageBrowser.js View on Github external
getPhotos = () => {
    let params = { first: 500, mimeTypes: ['image/jpeg'] }
    if (this.state.after) params.after = this.state.after
    if (!this.state.hasNextPage) return
    MediaLibrary
      .getAssetsAsync(params)
      .then((assets) => this.processPhotos(assets))
  }
github akveo / kittenTricks / src / containers / layouts / messaging / chat3 / chat3.container.tsx View on Github external
public componentWillMount(): void {
    MediaLibrary.getAssetsAsync({ first: 6 })
      .then((data: MediaLibrary.PagedInfo) =>
        this.setState({ galleryFiles: data.assets }));
    this.props.navigation.setParams({
      interlocutor: this.state.conversation.interlocutor,
      lastSeen: this.state.conversation.lastSeen,
      onBack: this.onBackPress,
      onProfile: this.onProfilePress,
    });
  }
github akveo / kittenTricks / src / containers / layouts / messaging / chat2 / chat2.container.tsx View on Github external
public componentWillMount(): void {
    MediaLibrary.getAssetsAsync({ first: 6 })
      .then(this.onMediaResponse);
    this.props.navigation.setParams({
      interlocutor: this.state.conversation.interlocutor,
      lastSeen: this.state.conversation.lastSeen,
      onBack: this.onBackPress,
      onProfile: this.onProfilePress,
    });
  }
github hyakt / expo-multiple-media-imagepicker / example / components / ImageBrowser.js View on Github external
getPhotos = () => {
    let params = { first: 500 }
    if (this.state.after) params.after = this.state.after
    if (!this.state.hasNextPage) return
    MediaLibrary
      .getAssetsAsync(params)
      .then((assets) => {
        this.processPhotos(assets)
      })
  }
github expo / expo / home / screens / MediaLibrary / MediaLibraryScreen.tsx View on Github external
async loadMoreAssets(currentAssets = this.state.assets, cursor = this.state.endCursor) {
    if (
      this.isLoadingAssets ||
      (cursor === this.state.endCursor && this.state.hasNextPage === false)
    ) {
      return;
    }

    const { state } = this;
    const album = this.getAlbum();

    this.isLoadingAssets = true;

    const { assets, endCursor, hasNextPage } = await MediaLibrary.getAssetsAsync({
      first: PAGE_SIZE,
      after: cursor,
      mediaType: state.mediaType,
      sortBy: state.sortBy,
      album: album && album.id,
    });

    const lastAsset = currentAssets[currentAssets.length - 1];

    if (!lastAsset || lastAsset.id === cursor) {
      this.setState({
        assets: ([] as MediaLibrary.Asset[]).concat(currentAssets, assets),
        endCursor,
        hasNextPage,
        refreshing: false,
      });