forked from Expensify/react-native-share-menu
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
46 lines (40 loc) · 1.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { NativeModules, NativeEventEmitter } from "react-native";
const { ShareMenu } = NativeModules;
const EventEmitter = new NativeEventEmitter(ShareMenu);
const NEW_SHARE_EVENT_NAME = "NewShareEvent";
export const ShareMenuReactView = {
dismissExtension(error = null) {
NativeModules.ShareMenuReactView.dismissExtension(error);
},
openApp() {
NativeModules.ShareMenuReactView.openApp();
},
continueInApp(extraData = null) {
NativeModules.ShareMenuReactView.continueInApp(extraData);
},
data() {
return NativeModules.ShareMenuReactView.data();
},
};
export default {
/**
* @deprecated Use `getInitialShare` instead. This is here for backwards compatibility.
*/
getSharedText(callback) {
this.getInitialShare(callback);
},
getInitialShare(callback) {
ShareMenu.getSharedText(callback);
},
addNewShareListener(callback) {
const count = EventEmitter.listenerCount(NEW_SHARE_EVENT_NAME);
if (count > 0) {
EventEmitter.removeAllListeners(NEW_SHARE_EVENT_NAME);
}
const subscription = EventEmitter.addListener(
NEW_SHARE_EVENT_NAME,
callback
);
return subscription;
},
};