I am trying to access iOS' share button where you can share content to all services, including messages etc... Any idea how I could do this? Thanks
Asked
Active
Viewed 1.1k times
4
-
The "iOS share button" is UIActivityViewController: http://jairtrejo.mx/blog/2015/09/share-button-react-native – Nov 18 '16 at 15:02
-
Ok thanks so I would have to write it in ObjC and then link it @IanBell? – dylan Nov 18 '16 at 16:56
-
https://github.com/facebook/react-native/blob/master/Libraries/ActionSheetIOS/RCTActionSheetManager.m – Nov 18 '16 at 19:21
4 Answers
7
You now have a simple Share API in react-native.
import { Share } from "react-native"
Share.share(
{
title: "a title",
message: "some message",
// or
url: imageReference
},
(options)
);

MoOx
- 8,423
- 5
- 40
- 39
3
You might want to check out the react-native-share package, it should cover your usecase. You can also see more relevant packages on JS.Coach

martinarroyo
- 9,389
- 3
- 38
- 75
0
It's much easier than you think. Adding to @MoOx answer further.
With the new share api available, you can easily share information with your React Native app by just using it with all variables and configuration. (see here)
import React from 'react';
import { Share, View, Button } from 'react-native';
const ShareExample = () => {
const onShare = async () => {
try {
const result = await Share.share({
message:
'React Native | A framework for building native apps using React',
});
if (result.action === Share.sharedAction) {
if (result.activityType) {
// shared with activity type of result.activityType
} else {
// shared
}
} else if (result.action === Share.dismissedAction) {
// dismissed
}
} catch (error) {
alert(error.message);
}
};
return (
<View style={{ marginTop: 50 }}>
<Button onPress={onShare} title="Share" />
</View>
);
};
export default ShareExample;

Lonare
- 3,581
- 1
- 41
- 45