nativescript-ssi-awesome-webview
Version:
Awesome WebViews for all NativeScript Apps!
48 lines • 2.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var app = require("tns-core-modules/application");
var CustomTabsClient = androidx.browser.customtabs.CustomTabsClient;
var CustomTabsServiceConnection = androidx.browser.customtabs.CustomTabsServiceConnection;
var CustomTabsIntent = androidx.browser.customtabs.CustomTabsIntent;
var color_1 = require("tns-core-modules/color");
var CUSTOM_TAB_PACKAGE_NAME = "com.android.chrome";
var mCustomTabsClient = null;
var mCustomTabsServiceConnection = null;
var mCustomTabsSession = null;
var context = function () { return app.android.startActivity || app.android.context; };
function init() {
mCustomTabsServiceConnection = new (CustomTabsServiceConnection.extend({
onCustomTabsServiceConnected: function (name, client) {
mCustomTabsClient = client;
mCustomTabsClient.warmup(long(0));
mCustomTabsSession = mCustomTabsClient.newSession(null);
},
onServiceDisconnected: function (name) {
mCustomTabsClient = null;
}
}))();
CustomTabsClient.bindCustomTabsService(context(), CUSTOM_TAB_PACKAGE_NAME, mCustomTabsServiceConnection);
}
exports.init = init;
function openWebView(options) {
if (!options.url) {
throw new Error('No url set in the Advanced WebView Options object.');
}
var intentBuilder;
if (mCustomTabsSession) {
intentBuilder = new CustomTabsIntent.Builder();
}
else {
intentBuilder = new CustomTabsIntent.Builder(mCustomTabsSession);
}
intentBuilder.setShowTitle(options.showTitle === true);
if (options.toolbarColor) {
intentBuilder.setToolbarColor(new color_1.Color(options.toolbarColor).android);
}
intentBuilder.addDefaultShareMenuItem();
intentBuilder.enableUrlBarHiding();
intentBuilder.build()
.launchUrl(context(), android.net.Uri.parse(options.url));
}
exports.openWebView = openWebView;
//# sourceMappingURL=awesome-webview.android.js.map