UNPKG

vt-nativescript-advanced-webview

Version:

An advanced webview using Chrome CustomTabs on Android and SFSafariViewController on iOS.

47 lines (46 loc) 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var color_1 = require("tns-core-modules/color"); var SFSafariViewControllerDelegateImpl = (function (_super) { __extends(SFSafariViewControllerDelegateImpl, _super); function SFSafariViewControllerDelegateImpl() { return _super !== null && _super.apply(this, arguments) || this; } SFSafariViewControllerDelegateImpl.initWithOwnerCallback = function (owner, callback) { var delegate = (SFSafariViewControllerDelegateImpl.new()); delegate._owner = owner; delegate._callback = callback; return delegate; }; SFSafariViewControllerDelegateImpl.prototype.safariViewControllerDidCompleteInitialLoad = function (controller, didLoadSuccessfully) { console.log('Delegate, safariViewControllerDidCompleteInitialLoad: ' + didLoadSuccessfully); }; SFSafariViewControllerDelegateImpl.prototype.safariViewControllerDidFinish = function (controller) { if (this._callback && typeof this._callback === 'function') { this._callback(true); } }; SFSafariViewControllerDelegateImpl.ObjCProtocols = [SFSafariViewControllerDelegate]; return SFSafariViewControllerDelegateImpl; }(NSObject)); function init() { } exports.init = init; function openAdvancedUrl(options) { if (!options.url) { throw new Error('No url set in the Advanced WebView Options object.'); } var sfc = SFSafariViewController.alloc().initWithURL(NSURL.URLWithString(options.url)); if (options.toolbarColor) { sfc.preferredBarTintColor = new color_1.Color(options.toolbarColor).ios; } if (options.toolbarControlsColor) { sfc.preferredControlTintColor = new color_1.Color(options.toolbarControlsColor).ios; } sfc.delegate = SFSafariViewControllerDelegateImpl.initWithOwnerCallback(new WeakRef({}), options.isClosed); var app = UIApplication.sharedApplication; var animated = true; var completionHandler = null; app.keyWindow.rootViewController.presentViewControllerAnimatedCompletion(sfc, animated, completionHandler); } exports.openAdvancedUrl = openAdvancedUrl;