mdjfs / expo-image-multiple-picker

Fully customizable image picker for react native
https://npmjs.com/expo-image-multiple-picker
MIT License
21 stars 7 forks source link

BUG: Exception while fetching pictures #2

Closed MarcoFilosi closed 1 year ago

MarcoFilosi commented 2 years ago

It seems the library doesn't work using the simple example shown in the home page:

import { ImagePicker } from 'expo-image-multiple-picker'

function App() {
  return (
    <ImagePicker
      onSave={(assets) => console.log(assets)}
      onCancel={() => console.log('no permissions or user go back')}
    />
  )
}

Basically the album selection works but when user goes to pictures selection screen an exception is thrown. This is the output on console:

[Unhandled promise rejection: Error: Couldn't find cursor]
at node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:106:50 in promiseMethodWrapper
at node_modules/expo-modules-core/build/NativeModulesProxy.native.js:15:23 in moduleName.methodInfo.name
at node_modules/expo-media-library/build/MediaLibrary.js:374:17 in getAssetsAsync
at node_modules/expo-media-library/build/MediaLibrary.js:343:7 in getAssetsAsync
at node_modules/expo-image-multiple-picker/lib/index.js:180:27 in ImagePickerCarousel#fetchNextPage
at node_modules/expo-image-multiple-picker/lib/index.js:178:4 in ImagePickerCarousel#fetchNextPage
at node_modules/expo-image-multiple-picker/lib/index.js:211:30 in ImagePickerCarousel#fillStartImages
at node_modules/expo-image-multiple-picker/lib/index.js:209:4 in ImagePickerCarousel#fillStartImages
at node_modules/expo-image-multiple-picker/lib/index.js:217:18 in ImagePickerCarousel#componentDidMount
at node_modules/expo-image-multiple-picker/lib/index.js:215:4 in ImagePickerCarousel#componentDidMount

This is my current expo versions:

"expo": "~45.0.0",
"expo-cli": "^6.0.2",
"expo-image-multiple-picker": "^4.4.0",

You can reproduce it easily. Let me know if you need more information. Note: app has already permissions set properly

mdjfs commented 2 years ago

Hi!

I feel like the album you want to check is empty bc that's related of pagination errors... I'll check it later.

Is nice to know how much images had the album and what device are you using

MarcoFilosi commented 2 years ago

Hi, I've tested on iOS simulator and it has just 6 pictures. There is only just one album. It is called "Recents". By the way the exception is thrown immediately if I set "noAlbums" option.

See the attached picture regarding album selection

Simulator Screen Shot - iPhone 13 - 2022-08-11 at 15 43 59

mdjfs commented 2 years ago

I have some idea, i'll check it after work.

Thanks

MrSinaRJ commented 2 years ago

Hey @mdjfs, I have the same problem. Did you get anything done? Cause you had some ideas, I have none 😁

mdjfs commented 2 years ago

@MrSinaRJ @MarcoFilosi hey guys! Sorry for the delay, I was really busy at work... I'm trying replicate that but I have a problem. I'm not a mac user (bad news for testing)... Then @MrSinaRJ yes i have some idea, the bug is inside of this function:

image

Probably, the picker try to fetch an unexistent page. Maybe we need ensure if this page exists before fetch.

Can you do a console.log of this.state.page before MediaLibrary.getAssetsAsync? After that probably I have an answer for the bug

MrSinaRJ commented 1 year ago

Hey @mdjfs, Thanks for looking it up. The fact we're here is to help each other and improve what we achieve.

here is what I get from console.log before and after the said line:

before MediaLibrary.getAssetsAsync:::  undefined
error in catch after MediaLibrary.getAssetsAsync:::  [Error: Couldn't find cursor]

[Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'page.endCursor')]

I attach a screenshot of the code so you can trace better Screen Shot 2022-09-22 at 9 24 57 PM

MrSinaRJ commented 1 year ago

Additional useful data: In WhatsAppAlbum which you have provided in Readme, there is props variable, which the console.log() return the following object:

Object {
  "album": Object {
    "approximateLocation": null,
    "assetCount": 6,
    "endTime": null,
    "folderName": null,
    "id": "87574209-EE20-4693-832B-4CBB661F48F9",
    "locationNames": Array [],
    "startTime": null,
    "title": "Recents",
    "type": "smartAlbum",
  },
  "goToGallery": [Function bound dispatchSetState],
  "thumb": Object {
    "creationTime": 1522437259365,
    "duration": 0,
    "filename": "IMG_0006.HEIC",
    "height": 3024,
    "id": "CC95F08C-88C3-4012-9D6D-64A413D254B3/L0/001",
    "mediaSubtypes": Array [
      "hdr",
    ],
    "mediaType": "photo",
    "modificationTime": 1663867701019,
    "uri": "ph://CC95F08C-88C3-4012-9D6D-64A413D254B3",
    "width": 4032,
  },
}
Object {
  "album": Object {
    "approximateLocation": null,
    "assetCount": 1,
    "endTime": null,
    "folderName": null,
    "id": "1EE116F5-89F5-471C-8A85-FDED3F67E081",
    "locationNames": Array [],
    "startTime": null,
    "title": "Favorites",
    "type": "smartAlbum",
  },
  "goToGallery": [Function bound dispatchSetState],
  "thumb": Object {
    "creationTime": 1522437259365,
    "duration": 0,
    "filename": "IMG_0006.HEIC",
    "height": 3024,
    "id": "CC95F08C-88C3-4012-9D6D-64A413D254B3/L0/001",
    "mediaSubtypes": Array [
      "hdr",
    ],
    "mediaType": "photo",
    "modificationTime": 1663867701019,
    "uri": "ph://CC95F08C-88C3-4012-9D6D-64A413D254B3",
    "width": 4032,
  },
}

I have 1 Recents Album, and 1 Favorites I think cause the album path is virtual in this case, this happens and it may only happen on iOS simulator. I'll have access to physical iOS next week and will test that and will upload data from props to see if it changes.

mdjfs commented 1 year ago

Hi! I think is a detail related with expo-media-library, when try fetch assets with after: '0'. That in android works, returns the first assets for the album. But in iOS that didn't work because iOS only expect an asset ID. Not a position. And in android, the after option can be an Asset ID or a position.

Read more about that in this thread:

https://github.com/expo/expo/issues/15513

image

Then. I upload a new release of the library 4.3.1. @MrSinaRJ when you can test it and let me know if its ok to close the issue!

Thanks for all!

MrSinaRJ commented 1 year ago

Hey @mdjfs , Updated to 4.3.1 and it's okay Thanks for the awesome library

I know it's not the place, but is it possible to open imagePicker with all the selected items as a prop so user can edit his/her choice? (yes/no would be enough, if no I'll open a feature request issue, if yes I'm gonna need some documentation about how to use)

mdjfs commented 1 year ago

Glad to know the bug is fixed now for iOS 👍

No, actually there is no way to open ImagePicker with selected assets. Can be a feature request issue, i checked and is possible, just I need some time, and do some tests

Then, with the update bug is fixed. I'm gonna close the issue

Thanks!