olofd / react-native-photos-framework

A modern and comprehensive CameraRoll/iCloud-library-API for React Native 📸 📹
MIT License
220 stars 99 forks source link

Get full resolution image? #19

Closed adbl closed 7 years ago

adbl commented 7 years ago

Thanks for a great library!

In our use case we first present photo thumbnails in a collection (user can keep scrolling to see all theirs photos), user picks one to preview and then send it. We want to make sure the max resolution image gets sent at that point.

After checking around in this library/RN and apple docs, I think I have understood the following:

Could we add an option to withOptions to support this?

olofd commented 7 years ago

Hi! Would be glad to help, but let me ask you:

How are you sending the image? Some custom ObjC-code I would guess? If that's correct I guess you are loading the image with the imageloader defined in this library or by using the React Natives imageLoader that you can use via the bridge in native modules?

If that's the case this is only an extension in our imageLoader?

We could make the extension of course, but it would seem easier, I you already have custom ObjC-code to just load the desired image yourself using PhotoFramework, in the format you like and then send the bytes.

Enlighten me if you are using some RN-feature to send the actual image. Like if RN's XHR has the ability to post images loaded with RN.. Is that the case?

Sry if I'm confused. Would like to help, just need some more info.

adbl commented 7 years ago

I realized that my request doesn't make sense anymore, but I'll answer your questions anyway because I learned I few things which may be useful.

A) RN XHR can send binary "file" data from things that implement RCTURLRequestHandler interface. In fact, the RCTImageLoader implements it too (it seems) checking all available image loaders, (but it needs a recompress which is not ideal). If this library implemented the RCTURLRequestHandler directly, sending the "raw" file with XHR would be supported out of the box.

B) In our case we first use the RN ImageEditor to allow the user to crop the image (but at a fixed pretty high resolution...), ImageEditor uses the ImageLoader method which doesn't specify size, so max resolution will be used. It then places the cropped Image in ImageStore which implement both ImageLoader and RCTURLRequestHandler. We could send it with XHR directly using the ImageStore uri, but we also need to store the file locally so we have a piece of native code which writes the data to a file before sending it (using react-native-fetch-blob due to other reasons).

C) when we really need to load the full resolution image in a view (for example to do interactive crop/zoom preview), we should just set the style width/height as specified by the asset and it will get loaded (then put in a ScrollView or something).

I elaborated on some of this here https://github.com/wkh237/react-native-fetch-blob/issues/218

olofd commented 7 years ago

Sounds good. I will definitely look into implementing RCTURLRequestHandler. Did not know it existed before this and I sounds like a feature we should support. Let me know if there is anything else I can help with.

olofd commented 7 years ago

@adbl Should we close this?

FYI: I'm implementing RCTURLRequestHandler at the moment. It will land next week. (I know you found another solution, but I still thought it made sense to implement the interface).

adbl commented 7 years ago

Nice to hear! Feel free to reference this issue when that's merged in case someone searching for this kind of stuff to help put the pieces together

olofd commented 7 years ago

RCTURLRequestHandler implementation is now released under 1.0 on npm.