alinz / react-native-share-extension

react-native as an engine to drive share extension
MIT License
762 stars 396 forks source link

Restores proper image handling for iOS #132

Closed AndrewHenderson closed 5 years ago

AndrewHenderson commented 5 years ago

Reverts changes in https://github.com/alinz/react-native-share-extension/commit/1e98f58991a892fd941a809f9564fb5181693ba0.

Changes in that PR cause inability to use image data for fetch requests. I personally find that I am unable to upload images from the share extension if the changes linked are included. This PR gets things working again.

@brenwarwcdg Please review your work. I'm not strong in Objective-C, but there appears to be an issue. It seems in these changes, images are assumed to be png for iOS. https://github.com/alinz/react-native-share-extension/commit/5540d951bb16b92a95bf855998afe8344de0e70c#diff-cd365a662ae840f4beb6a01a1c8ffa1fR106

chaitanyadeorukhkar commented 5 years ago

Reverting these changes will result in the share extension receiving a URL instead of an Image from apps like Photos. This URL cannot be used within RN.

The approach taken earlier was correct. We create a temporary file where we write the image to if it is a URL. This way we are able to use that image within RN.

The only issue there was:

Assuming the name of each file as "RNSE_TEMP_IMG"

NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"RNSE_TEMP_IMG"]; 

Assuming the extension of each file as "png"

NSString *fullPath = [filePath stringByAppendingPathExtension:@"png"];

Instead of this if we can extract the file name & extension from the URL/Image, use that in the full path of the created temporary file, we will have a proper file shared with the correct extension and name.

What do you think @AndrewHenderson @brenwarwcdg ?

I am not too strong with Objective-C but I'll try sending a PR if you think this approach could help fix both the problems (unusable URL & incorrect extension)

Edit - Created a PR: https://github.com/alinz/react-native-share-extension/pull/158