forked from tjvantoll/nativescript-social-share
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocial-share.ios.ts
More file actions
37 lines (30 loc) · 1.21 KB
/
social-share.ios.ts
File metadata and controls
37 lines (30 loc) · 1.21 KB
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
import { ios } from "tns-core-modules/utils/utils";
import { Frame } from "tns-core-modules/ui";
function share(thingsToShare) {
const activityController = UIActivityViewController.alloc()
.initWithActivityItemsApplicationActivities(thingsToShare, null);
const presentViewController = activityController.popoverPresentationController;
if (presentViewController) {
const page = Frame.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;
}
}
const app = UIApplication.sharedApplication;
const window = app.keyWindow || (app.windows && app.windows.count > 0 && app.windows[0]);
const rootController = window.rootViewController;
ios.getVisibleViewController(rootController)
.presentViewControllerAnimatedCompletion(activityController, true, null);
}
export function shareImage(image) {
share([image]);
}
export function shareText(text) {
share([text]);
}
export function shareUrl(url, text) {
share([NSURL.URLWithString(url), text]);
}