react-native-cameraroll: [IOS] CameraRoll.getPhotos() returns photos with duplicates

Bug

  • CameraRoll.getPhotos in IOS returns photos with duplicates of the photos.

Screen Shot 2019-08-07 at 2 35 56 PM

Environment info

React native info output:

React Native Environment Info:
    System:
      OS: macOS 10.14.5
      CPU: (4) x64 Intel(R) Core(TM) i5-4308U CPU @ 2.80GHz
      Memory: 32.09 MB / 8.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 12.4.0 - /usr/local/bin/node
      Yarn: 1.16.0 - /usr/local/bin/yarn
      npm: 6.9.0 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
      Android SDK:
        API Levels: 23, 28, 29
        Build Tools: 28.0.3, 29.0.0
        System Images: android-28 | Google Play Intel x86 Atom, android-29 | Intel x86 Atom_64
    IDEs:
      Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
    npmPackages:
      react: ^16.8.3 => 16.8.6 
      react-native: ^0.59.8 => 0.59.9 
    npmGlobalPackages:
      create-react-native-app: 2.0.2
      react-native-cli: 2.0.1

Steps To Reproduce

Describe what you expected to happen:

  1. CameraRoll.getPhotos should not return an object containing the photos and the duplicates.

Reproducible sample code

Number of photos in phone should be less than the value of first in CameraRoll Params

CameraRoll Params:

ios: {
    first: 30,
    assetType: 'Photos',
    groupTypes: 'All',
  }

Code for getting photos:

CameraRoll.getPhotos(// config)
   .then(data => console.log(data)
   .catch(err => console.log(err));

Expected output: data returned should be only the photos but the data returned contains the photos and its duplicates.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (1 by maintainers)

Most upvoted comments

It is duplicated because when you are fetching with groupTypes: 'All', it will return every albums and images inside them. In your example case may have 2 albums: Recent Photos and All Photos.

Yes I found this was happening for me due to having some photos marked as Favorite so they were in the “Favorites” album, and getting by groupTypes: 'All' was getting duplicates.

@stevejboyer then what should I set the groupTypes to in order to get all photos without them being duplicated?

I’m still actively working on figuring this whole thing out. For a while I was teaching myself Swift (I come from the web, not native app development), and writing my own photos getter, because the native one is so buggy.

For now I’ve found if I put groupTypes to ‘Album’ or ‘Library’ it will get photos from a specific custom-named album, but not Favorites or another built-in album.

Looks like I was getting duplicates from the Favorites album when I asked for: groupTypes: ‘All’, groupName: ‘UserLibrary’ Once I set groupName to undefined it actually stopped returning duplicates, so perhaps I was incorrect earlier about it being from groupTypes: ‘All’.

Like I said, still figuring this stuff out 😕

It is duplicated because when you are fetching with groupTypes: 'All', it will return every albums and images inside them. In your example case may have 2 albums: Recent Photos and All Photos.