react-native-cameraroll: Camera Roll not returning any photos on iOS
I reported this bug in the react-native repo here at facebook/react-native#24140 , but they said to post it here.
š Bug Report
When fetching photos from the Camera Roll on iOS by calling CameraRoll.getPhotos()
, it always return an empty array of edges in the data. This problem is not present when I run it on Android nor in a Snack. I tried implementing the community version and the built-in version of the Camera Roll, but the problem persisted. I also tried running it on the iOS simulator, on an iPhone, and an iPad with no success.
To Reproduce
- Create a new react native project (with
react-native init
) - Link the Camera Roll library a. With the RCTCameraRoll library as described here from facebookās website b. Or with the RNCCameraRoll library as described in your README
- Add the permission keys in the Info.plist as described here from facebookās website
- Copy paste the sample code from facebookās website
- Run
react-native start --reset-cache
(Solved the problems I was having with metro) - Run
react-native run-ios
Expected Behavior
I would expect the Camera Roll getPhotos function to return a populated edges array in the edges with the information/URI of images in the phones camera roll.
Code Example
Cannot replicate bug in a Snack.
With the built-in Camera Roll Here is a repo with the code example. I also uploaded the iOS release app file to appetize.io, which does have the problem.
With the community version Here is a repo with the code example. I also uploaded the iOS release app file to appetize.io, which does have the same problem.
Environment
Output of the react-native info
command
React Native Environment Info:
System:
OS: macOS High Sierra 10.13.6
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 18.59 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 11.12.0 - /usr/local/bin/node
Yarn: 1.15.2 - /usr/local/bin/yarn
npm: 6.7.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
Android SDK:
API Levels: 21, 23, 25, 26, 27, 28
Build Tools: 21.1.2, 23.0.3, 25.0.2, 26.0.2, 27.0.3, 28.0.2, 28.0.3
System Images: android-28 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.3 AI-182.5107.16.33.5264788
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.1 => 0.59.1
npmGlobalPackages:
react-native-cli: 2.0.1
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 13
- Comments: 22 (11 by maintainers)
Commits related to this issue
- Default groupTypes to "All". Fixes #18 — committed to scarlac/react-native-cameraroll by deleted user 5 years ago
- Default groupTypes to "All". Fixes #18 — committed to scarlac/react-native-cameraroll by deleted user 5 years ago
- Default groupTypes to "All". Fixes #18 — committed to scarlac/react-native-cameraroll by deleted user 5 years ago
Found solution: After poking around in the native code - RN 0.59.0 contains a breaking change: You are now required to supply the
groupTypes: "All"
option when callinggetPhotos
like so:If you omit
groupTypes
, a predicate (filter) will be applied such that no photos will be returned in some cases. Itās possible this filter will show some photos but not all. This issue applies to both community version and RN bundled version of CameraRoll.@JoshuaGross Could we default
groupTypes
to'All'
by default?@JoshuaGross Yep, that fixes my problem! Thanks @scarlac
@JoshuaGross did you see this commit on the RNC repo (thatās not on RN core) ? https://github.com/react-native-community/react-native-cameraroll/commit/0d1059ef75889103382c26e2cc18b32c393943e0
It basically sets all as default on JS side.
@JoshuaGross when I put
SavedPhotos
, no images are returned, weirdSounds good! Iāll have a look on Monday, @JoshuaGross
@scarlac I changed my mind, I think itās worthwhile changing the default in this case, Iāll just need to test a lot of things on my end to ensure nothing breaks at FB. Would you mind submitting a PR? Might be worthwhile submitting followup documentation changes to indicate that āallā is the default for that param.
@JoshuaGross Iād be fine with a docs fix.
Current code example in
README.md
do not include this options (see https://github.com/react-native-community/react-native-cameraroll#example). I also see Expo snacks around the web not using this property, so weāre almost guaranteed to have people fumbling for answers. If itās truly breaking, I think it deserves a proper mention.