Created
March 30, 2015 10:50
-
-
Save vakrilov/039f19abd1b323d45d19 to your computer and use it in GitHub Desktop.
NativeScript - Share button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import frame = require("ui/frame"); | |
import view = require("ui/core/view"); | |
import utils = require("utils/utils"); | |
import platform = require("platform"); | |
export function shareTap(args) { | |
share("here we go"); | |
} | |
function share(text: string) { | |
if (platform.device.os === platform.platformNames.android) { | |
var intent = new android.content.Intent(android.content.Intent.ACTION_SEND); | |
intent.setType("text/plain"); | |
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject"); | |
intent.putExtra(android.content.Intent.EXTRA_TEXT, text); | |
var activity = frame.topmost().android.activity; | |
activity.startActivity(android.content.Intent.createChooser(intent, "share")); | |
} | |
else if (platform.device.os === platform.platformNames.ios){ | |
var currentPage = frame.topmost().currentPage; | |
var controller = new UIActivityViewController(utils.ios.collections.jsArrayToNSArray([text]), null); | |
(<UIViewController>currentPage.ios).presentViewControllerAnimatedCompletion(controller, true, null); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Page loaded="pageLoaded"> | |
<Page.optionsMenu> | |
<MenuItem text="share" tap="shareTap" /> | |
</Page.optionsMenu> | |
<!-- Other content --> | |
</Page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment