forked from tjvantoll/nativescript-social-share
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsocial-share.ios.js
34 lines (31 loc) · 1.05 KB
/
social-share.ios.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
var frameModule = require("ui/frame");
var utilsModule = require("utils/utils");
function share(thingToShare, index) {
var activityController = UIActivityViewController.alloc()
.initWithActivityItemsApplicationActivities([thingToShare], null);
var presentViewController = activityController.popoverPresentationController;
if (presentViewController) {
var page = frameModule.topmost().currentPage;
if (page && page.ios.navigationItem.rightBarButtonItems &&
page.ios.navigationItem.rightBarButtonItems.count > 0) {
presentViewController.barButtonItem = page.ios.navigationItem.rightBarButtonItems[0];
} else {
presentViewController.sourceView = page.ios.view;
}
}
utilsModule.ios.getter(UIApplication, UIApplication.sharedApplication)
.keyWindow
.rootViewController
.presentViewControllerAnimatedCompletion(activityController, true, null);
}
module.exports = {
shareImage: function(image) {
share(image);
},
shareText: function(text) {
share(text);
},
shareFile: function(filePath) {
share(NSURL.fileURLWithPath(filePath));
}
};