facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
117.74k stars 24.16k forks source link

Share does not support `url` on Android #18993

Closed James2516 closed 5 years ago

James2516 commented 6 years ago

Environment

Environment: OS: macOS Sierra 10.12.6 Node: 9.8.0 Yarn: - npm: 5.6.0

Packages: (wanted => installed) react: 16.3.1 => 16.3.1 react-native: 0.55.1 => 0.55.1

Steps to Reproduce

https://facebook.github.io/react-native/docs/share.html#ios Why does it only support url prop on iOS? Is there some other way to share a file on Android?

MarkOSullivan94 commented 6 years ago

Experiencing this issue as well in our app. Did a bit of digging into the React Native source code and you can find the js function used to share content here: https://github.com/facebook/react-native/blob/4a802100d16ee9f52e6e4caea6e54b9a49694351/Libraries/Share/Share.js#L65

That ties in with the ShareModule on Android. I had a look through the code and found it's only looking for title and message in the share content.

Title https://github.com/facebook/react-native/blob/26684cf3adf4094eb6c405d345a75bf8c7c0bf88/ReactAndroid/src/main/java/com/facebook/react/modules/share/ShareModule.java#L60

Message https://github.com/facebook/react-native/blob/26684cf3adf4094eb6c405d345a75bf8c7c0bf88/ReactAndroid/src/main/java/com/facebook/react/modules/share/ShareModule.java#L64

For the ShareModule to work with images on Facebook it would need something like this added


        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_TEXT,"TITLE: This is a test share");
        shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
        shareIntent.setType("image/*");
        startActivity(Intent.createChooser(shareIntent, "Share image via:"));

I did a couple of tests with apps on my Pixel 2 and this code allows you to share a text and image for:

Or just an image for:

I think the only thing which needs to be passes from the Share.js is the uri or a location to generate the uri ( Uri.parse(imageLocation) ) should hopefully work.

In my opinion should be two functions in Share.js because I know not everyone will want to show an image, so there should be shareText and shareImage functions.

James2516 commented 6 years ago

@MarkOSullivan94 what about sharing a file? Could you submit a PR if you know how to fix it? The implementation from react-native-share seems non-trivial.

MarkOSullivan94 commented 6 years ago

Honestly I have no idea how I would go about testing my changes.

I've just done a bit of reading up on contributing to the project but after reading up on the How to Contribute guide, I walked away not knowing how I'm supposed to be able to run my changes to the RN project with my existing RN projects.

I tried messaging in the #need-help channel and the #react-native channels in the Reactiflux discord server seeking advice but got no response.

Edit: I found a document to explain how to test changes! Might look into trying to see if I can get a fix for this in the next couple of weeks.

kevinscience commented 6 years ago

I really need to share a url on Android. Because Facebook is showing nothing! And what's the meaning for this whole Share module if there is nothing to share.

antonioaltamura commented 6 years ago

I honestly think this is a huge lack for this module, I can't believe it..

The @MarkOSullivan94 solution involves native "hacks", so even if it works it can't be used inside Expo.

MarkOSullivan94 commented 6 years ago

@antonioaltamura what you mean it wont work with Expo?

antonioaltamura commented 6 years ago

Uhm I saw java edits and I thought they were in android directory. I recheck you post I guess I was wrong, didn't test yet but looks doable even in Expo.

MarkOSullivan94 commented 6 years ago

Have been unable to test my changes to the RN project for this. Hopefully once I get help with my issue (https://github.com/facebook/react-native/issues/19358), I'll be able to get my changes to work, allowing for the sharing of images for Android in RN Share API.

stale[bot] commented 6 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

James2516 commented 6 years ago

stale--

MarkOSullivan94 commented 5 years ago

Hit another block https://github.com/facebook/react-native/issues/21776

MarkOSullivan94 commented 5 years ago

Another block hit #22118

I would be great if someone with a running local build of React Native can test these changes for me.

Titozzz commented 5 years ago

Hello there 👋 this issue seems more of a precise feature request than a bug report. For this reason, we'd prefer for you to post it to Canny so that it can be prioritized against the FR already there (maybe someone already submitted it!), or you can create a pull request 👍

MarkOSullivan94 commented 5 years ago

@Titozzz I think it would be a good idea for you to post it to Canny first and then link it in here before closing this issue, means you wont have numerous people who read your post going there and posting the same idea over and over again.