Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nativescript-inappbrowser

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nativescript-inappbrowser - npm Package Compare versions

Comparing version 2.3.0 to 3.0.0

utils.ios.d.ts

2

ChromeTabsManagerActivity.d.ts
import Context = android.content.Context;
import Intent = android.content.Intent;
import Bundle = android.os.Bundle;
import { Observable } from 'tns-core-modules/data/observable';
import { Observable } from '@nativescript/core';
export declare class ChromeTabsEvent extends Observable {

@@ -6,0 +6,0 @@ message: String;

@@ -0,18 +1,15 @@

var Intent = android.content.Intent;
import { Observable } from '@nativescript/core';
import { BROWSER_TYPES } from './InAppBrowser.common';
import { DISMISSED_EVENT } from './utils.android';
export class ChromeTabsEvent extends Observable {
}
export const BROWSER_ACTIVITY_EVENTS = new ChromeTabsEvent();
const KEY_BROWSER_INTENT = 'browserIntent';
const BROWSER_RESULT_TYPE = 'browserResultType';
const DEFAULT_RESULT_TYPE = BROWSER_TYPES.DISMISS;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Intent = android.content.Intent;
var observable_1 = require("tns-core-modules/data/observable");
var ChromeTabsEvent = (function (_super) {
__extends(ChromeTabsEvent, _super);
function ChromeTabsEvent() {
return _super !== null && _super.apply(this, arguments) || this;
}
return ChromeTabsEvent;
}(observable_1.Observable));
exports.ChromeTabsEvent = ChromeTabsEvent;
exports.BROWSER_ACTIVITY_EVENTS = new ChromeTabsEvent();
var KEY_BROWSER_INTENT = 'browserIntent';
var BROWSER_RESULT_TYPE = 'browserResultType';
var DEFAULT_RESULT_TYPE = 'dismiss';
var ChromeTabsManagerActivity = (function (_super) {
exports.ChromeTabsManagerActivity = void 0;
var ChromeTabsManagerActivity = /** @class */ (function (_super) {
__extends(ChromeTabsManagerActivity, _super);

@@ -27,2 +24,5 @@ function ChromeTabsManagerActivity() {

_super.prototype.onCreate.call(this, savedInstanceState);
// This activity gets opened in 2 different ways. If the extra KEY_BROWSER_INTENT is present we
// start that intent and if it is not it means this activity was started with FLAG_ACTIVITY_CLEAR_TOP
// in order to close the intent that was started previously so we just close this.
if (this.getIntent().hasExtra(KEY_BROWSER_INTENT)

@@ -41,2 +41,5 @@ && (!savedInstanceState || !savedInstanceState.getString(BROWSER_RESULT_TYPE))) {

_super.prototype.onResume.call(this);
// onResume will get called twice, the first time when the activity is created and a second
// time if the user closes the chrome tabs activity. Knowing this we can detect if the user
// dismissed the activity and send an event accordingly.
if (!this.mOpened) {

@@ -46,3 +49,3 @@ this.mOpened = true;

else {
this.resultType = 'cancel';
this.resultType = BROWSER_TYPES.CANCEL;
this.finish();

@@ -54,14 +57,14 @@ }

switch (this.resultType) {
case 'cancel':
exports.BROWSER_ACTIVITY_EVENTS.set('message', 'chrome tabs activity closed');
exports.BROWSER_ACTIVITY_EVENTS.set('resultType', this.resultType);
case BROWSER_TYPES.CANCEL:
BROWSER_ACTIVITY_EVENTS.set('message', 'chrome tabs activity closed');
BROWSER_ACTIVITY_EVENTS.set('resultType', this.resultType);
break;
default:
exports.BROWSER_ACTIVITY_EVENTS.set('message', 'chrome tabs activity destroyed');
exports.BROWSER_ACTIVITY_EVENTS.set('resultType', DEFAULT_RESULT_TYPE);
BROWSER_ACTIVITY_EVENTS.set('message', 'chrome tabs activity destroyed');
BROWSER_ACTIVITY_EVENTS.set('resultType', DEFAULT_RESULT_TYPE);
break;
}
exports.BROWSER_ACTIVITY_EVENTS.notify({
eventName: 'DismissedEvent',
object: exports.BROWSER_ACTIVITY_EVENTS
BROWSER_ACTIVITY_EVENTS.notify({
eventName: DISMISSED_EVENT,
object: BROWSER_ACTIVITY_EVENTS
});

@@ -85,4 +88,3 @@ this.resultType = null;

ChromeTabsManagerActivity = __decorate([
JavaProxy('com.proyecto26.inappbrowser.ChromeTabsManagerActivity'),
__metadata("design:paramtypes", [])
JavaProxy('com.proyecto26.inappbrowser.ChromeTabsManagerActivity')
], ChromeTabsManagerActivity);

@@ -92,15 +94,15 @@ return ChromeTabsManagerActivity;

exports.ChromeTabsManagerActivity = ChromeTabsManagerActivity;
exports.createStartIntent = function (context, authIntent) {
var intent = exports.createBaseIntent(context);
export const createStartIntent = (context, authIntent) => {
let intent = createBaseIntent(context);
intent.putExtra(KEY_BROWSER_INTENT, authIntent);
return intent;
};
exports.createDismissIntent = function (context) {
var intent = exports.createBaseIntent(context);
export const createDismissIntent = (context) => {
let intent = createBaseIntent(context);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
return intent;
};
exports.createBaseIntent = function (context) {
export const createBaseIntent = (context) => {
return new Intent(context, ChromeTabsManagerActivity.class);
};
//# sourceMappingURL=ChromeTabsManagerActivity.js.map

@@ -1,52 +0,2 @@

import { EventData } from 'tns-core-modules/data/observable';
import { BrowserResult, AuthSessionResult } from './InAppBrowser.common';
declare type Animations = {
startEnter: string;
startExit: string;
endEnter: string;
endExit: string;
};
declare type InAppBrowserOptions = {
showTitle?: boolean;
toolbarColor?: string;
secondaryToolbarColor?: string;
enableUrlBarHiding?: boolean;
enableDefaultShare?: boolean;
forceCloseOnRedirection?: boolean;
animations?: Animations;
headers?: {
[key: string]: string;
};
};
declare class InAppBrowserModule extends java.lang.Object {
private static ERROR_CODE;
private static KEY_TOOLBAR_COLOR;
private static KEY_SECONDARY_TOOLBAR_COLOR;
private static KEY_ENABLE_URL_BAR_HIDING;
private static KEY_SHOW_PAGE_TITLE;
private static KEY_DEFAULT_SHARE_MENU_ITEM;
private static KEY_FORCE_CLOSE_ON_REDIRECTION;
private static KEY_ANIMATIONS;
private static KEY_HEADERS;
private static KEY_ANIMATION_START_ENTER;
private static KEY_ANIMATION_START_EXIT;
private static KEY_ANIMATION_END_ENTER;
private static KEY_ANIMATION_END_EXIT;
private static redirectResolve;
private static redirectReject;
private currentActivity;
private animationIdentifierPattern;
constructor();
isAvailable(): Promise<boolean>;
open(url: string, options?: InAppBrowserOptions): Promise<BrowserResult>;
close(): void;
openAuth(url: string, redirectUrl: string, options?: InAppBrowserOptions): Promise<AuthSessionResult>;
closeAuth(): void;
onEvent(event: EventData): void;
private registerEvent;
private resolveAnimationIdentifierIfNeeded;
private applyAnimation;
private flowDidFinish;
}
declare const _default: InAppBrowserModule;
export default _default;
import { InAppBrowserClassMethods } from './InAppBrowser.common';
export declare const InAppBrowser: InAppBrowserClassMethods;

@@ -1,20 +0,17 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Uri = android.net.Uri;
var Bundle = android.os.Bundle;
var TextUtils = android.text.TextUtils;
var Intent = android.content.Intent;
var Color = android.graphics.Color;
var BitmapFactory = android.graphics.BitmapFactory;
var Browser = android.provider.Browser;
var Pattern = java.util.regex.Pattern;
var AssertionError = java.lang.AssertionError;
var color_1 = require("tns-core-modules/color");
var utils_1 = require("tns-core-modules/utils/utils");
var application_1 = require("tns-core-modules/application");
var ChromeTabsManagerActivity_1 = require("./ChromeTabsManagerActivity");
var InAppBrowser_common_1 = require("./InAppBrowser.common");
var utils_android_1 = require("./utils.android");
var CustomTabsIntent = (useAndroidX() ? androidx.browser : android.support).customtabs.CustomTabsIntent;
function useAndroidX() {
return global.androidx && global.androidx.browser;
}
var InAppBrowserModule = (function (_super) {
import { Utils, Application } from '@nativescript/core';
import { BROWSER_ACTIVITY_EVENTS, createStartIntent, createDismissIntent } from './ChromeTabsManagerActivity';
import { getDefaultOptions, BROWSER_TYPES, } from './InAppBrowser.common';
import { getDrawableId, toolbarIsLight, CustomTabsIntent, DISMISSED_EVENT, ARROW_BACK_WHITE, ARROW_BACK_BLACK, getPreferredPackages, openAuthSessionPolyfillAsync, closeAuthSessionPolyfillAsync, } from './utils.android';
let InAppBrowserModuleInstance;
function setup() {
var InAppBrowserModule = /** @class */ (function (_super) {
__extends(InAppBrowserModule, _super);

@@ -27,6 +24,7 @@ function InAppBrowserModule() {

InAppBrowserModule.prototype.isAvailable = function () {
return Promise.resolve(true);
var context = Utils.android.getApplicationContext();
var resolveInfos = getPreferredPackages(context);
return Promise.resolve(!(resolveInfos === null || resolveInfos.isEmpty()));
};
InAppBrowserModule.prototype.open = function (url, options) {
if (options === void 0) { options = {}; }
var mOpenBrowserPromise = InAppBrowserModule.redirectResolve;

@@ -36,11 +34,11 @@ if (mOpenBrowserPromise) {

var result = {
type: 'cancel'
type: BROWSER_TYPES.CANCEL
};
return Promise.resolve(result);
}
this.currentActivity = application_1.android.foregroundActivity || application_1.android.startActivity;
this.currentActivity = Application.android.foregroundActivity || Application.android.startActivity;
if (!this.currentActivity) {
return Promise.reject(new Error(InAppBrowserModule.ERROR_CODE));
}
var inAppBrowserOptions = InAppBrowser_common_1.getDefaultOptions(url, options);
var inAppBrowserOptions = getDefaultOptions(url, options);
var builder = new CustomTabsIntent.Builder();

@@ -50,3 +48,4 @@ if (inAppBrowserOptions[InAppBrowserModule.KEY_TOOLBAR_COLOR]) {

try {
builder.setToolbarColor(new color_1.Color(colorString).android);
builder.setToolbarColor(Color.parseColor(colorString));
this.isLightTheme = toolbarIsLight(colorString);
}

@@ -60,3 +59,3 @@ catch (error) {

try {
builder.setSecondaryToolbarColor(new color_1.Color(colorString).android);
builder.setSecondaryToolbarColor(Color.parseColor(colorString));
}

@@ -67,9 +66,6 @@ catch (error) {

}
if (inAppBrowserOptions[InAppBrowserModule.KEY_ENABLE_URL_BAR_HIDING]) {
builder.enableUrlBarHiding();
}
if (inAppBrowserOptions[InAppBrowserModule.KEY_DEFAULT_SHARE_MENU_ITEM]) {
builder.addDefaultShareMenuItem();
}
var context = utils_1.ad.getApplicationContext();
var context = Utils.android.getApplicationContext();
if (inAppBrowserOptions[InAppBrowserModule.KEY_ANIMATIONS]) {

@@ -79,3 +75,9 @@ var animations = inAppBrowserOptions[InAppBrowserModule.KEY_ANIMATIONS];

}
if (inAppBrowserOptions[InAppBrowserModule.KEY_HAS_BACK_BUTTON]) {
builder.setCloseButtonIcon(BitmapFactory.decodeResource(context.getResources(), this.isLightTheme
? getDrawableId(ARROW_BACK_BLACK)
: getDrawableId(ARROW_BACK_WHITE)));
}
var customTabsIntent = builder.build();
var intent = customTabsIntent.intent;
var keyHeaders = inAppBrowserOptions[InAppBrowserModule.KEY_HEADERS];

@@ -89,10 +91,28 @@ if (keyHeaders) {

}
customTabsIntent.intent.putExtra(Browser.EXTRA_HEADERS, headers);
intent.putExtra(Browser.EXTRA_HEADERS, headers);
}
if (inAppBrowserOptions[InAppBrowserModule.KEY_FORCE_CLOSE_ON_REDIRECTION]) {
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
var intent = customTabsIntent.intent;
if (!inAppBrowserOptions[InAppBrowserModule.KEY_SHOW_IN_RECENTS]) {
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
}
intent.putExtra(CustomTabsIntent.EXTRA_ENABLE_URLBAR_HIDING, !!inAppBrowserOptions[InAppBrowserModule.KEY_ENABLE_URL_BAR_HIDING]);
try {
if (inAppBrowserOptions[InAppBrowserModule.KEY_BROWSER_PACKAGE] !== undefined) {
var packageName = inAppBrowserOptions[InAppBrowserModule.KEY_BROWSER_PACKAGE];
if (!TextUtils.isEmpty(packageName)) {
intent.setPackage(packageName);
}
}
else {
var packageName = inAppBrowserOptions[InAppBrowserModule.KEY_BROWSER_PACKAGE];
intent.setPackage(packageName);
}
}
catch (error) {
if (error.printStackTrace)
error.printStackTrace();
}
intent.setData(Uri.parse(url));

@@ -106,3 +126,3 @@ if (inAppBrowserOptions[InAppBrowserModule.KEY_SHOW_PAGE_TITLE]) {

this.registerEvent();
this.currentActivity.startActivity(ChromeTabsManagerActivity_1.createStartIntent(this.currentActivity, intent), customTabsIntent.startAnimationBundle);
this.currentActivity.startActivity(createStartIntent(this.currentActivity, intent), customTabsIntent.startAnimationBundle);
return new Promise(function (resolve, reject) {

@@ -122,3 +142,3 @@ InAppBrowserModule.redirectResolve = resolve;

}
ChromeTabsManagerActivity_1.BROWSER_ACTIVITY_EVENTS.off('DismissedEvent');
BROWSER_ACTIVITY_EVENTS.off(DISMISSED_EVENT);
var result = {

@@ -129,8 +149,7 @@ type: 'dismiss'

this.flowDidFinish();
this.currentActivity.startActivity(ChromeTabsManagerActivity_1.createDismissIntent(this.currentActivity));
this.currentActivity.startActivity(createDismissIntent(this.currentActivity));
};
InAppBrowserModule.prototype.openAuth = function (url, redirectUrl, options) {
if (options === void 0) { options = {}; }
return __awaiter(this, void 0, void 0, function () {
var inAppBrowserOptions;
var response;
var _this = this;

@@ -140,13 +159,15 @@ return __generator(this, function (_a) {

case 0:
inAppBrowserOptions = InAppBrowser_common_1.getDefaultOptions(url, options);
response = null;
_a.label = 1;
case 1:
_a.trys.push([1, , 3, 4]);
return [4, utils_android_1.openAuthSessionPolyfillAsync(url, redirectUrl, inAppBrowserOptions, function (startUrl, opt) { return _this.open(startUrl, opt); })];
case 2: return [2, _a.sent()];
return [4 /*yield*/, openAuthSessionPolyfillAsync(function (startUrl, opt) { return _this.open(startUrl, opt); }, url, redirectUrl, options)];
case 2:
response = _a.sent();
return [3 /*break*/, 4];
case 3:
utils_android_1.closeAuthSessionPolyfillAsync();
closeAuthSessionPolyfillAsync();
this.close();
return [7];
case 4: return [2];
return [7 /*endfinally*/];
case 4: return [2 /*return*/, response];
}

@@ -157,7 +178,7 @@ });

InAppBrowserModule.prototype.closeAuth = function () {
utils_android_1.closeAuthSessionPolyfillAsync();
closeAuthSessionPolyfillAsync();
this.close();
};
InAppBrowserModule.prototype.onEvent = function (event) {
ChromeTabsManagerActivity_1.BROWSER_ACTIVITY_EVENTS.off('DismissedEvent');
BROWSER_ACTIVITY_EVENTS.off(DISMISSED_EVENT);
if (!InAppBrowserModule.redirectResolve) {

@@ -175,3 +196,3 @@ throw new AssertionError();

var _this = this;
ChromeTabsManagerActivity_1.BROWSER_ACTIVITY_EVENTS.once('DismissedEvent', function (e) { return _this.onEvent(e); });
BROWSER_ACTIVITY_EVENTS.once(DISMISSED_EVENT, function (e) { return _this.onEvent(e); });
};

@@ -223,5 +244,13 @@ InAppBrowserModule.prototype.resolveAnimationIdentifierIfNeeded = function (context, identifier) {

InAppBrowserModule.KEY_ANIMATION_END_EXIT = "endExit";
InAppBrowserModule.KEY_HAS_BACK_BUTTON = "hasBackButton";
InAppBrowserModule.KEY_BROWSER_PACKAGE = "browserPackage";
InAppBrowserModule.KEY_SHOW_IN_RECENTS = "showInRecents";
return InAppBrowserModule;
}(java.lang.Object));
exports.default = new InAppBrowserModule();
return new InAppBrowserModule();
}
if (typeof InAppBrowserModuleInstance === 'undefined') {
InAppBrowserModuleInstance = setup();
}
export const InAppBrowser = InAppBrowserModuleInstance;
//# sourceMappingURL=InAppBrowser.android.js.map

@@ -0,1 +1,58 @@

export interface RedirectEvent {
url: 'string';
}
export interface BrowserResult {
type: 'cancel' | 'dismiss';
message?: string;
}
export interface RedirectResult {
type: 'success';
url: string;
}
declare type InAppBrowseriOSOptions = {
dismissButtonStyle?: 'done' | 'close' | 'cancel';
preferredBarTintColor?: string;
preferredControlTintColor?: string;
readerMode?: boolean;
animated?: boolean;
modalPresentationStyle?: 'automatic' | 'fullScreen' | 'pageSheet' | 'formSheet' | 'currentContext' | 'custom' | 'overFullScreen' | 'overCurrentContext' | 'popover' | 'none';
modalTransitionStyle?: 'coverVertical' | 'flipHorizontal' | 'crossDissolve' | 'partialCurl';
modalEnabled?: boolean;
enableBarCollapsing?: boolean;
ephemeralWebSession?: boolean;
};
export declare type Animations = {
startEnter: string;
startExit: string;
endEnter: string;
endExit: string;
};
declare type InAppBrowserAndroidOptions = {
showTitle?: boolean;
toolbarColor?: string;
secondaryToolbarColor?: string;
enableUrlBarHiding?: boolean;
enableDefaultShare?: boolean;
forceCloseOnRedirection?: boolean;
animations?: Animations;
headers?: {
[key: string]: string;
};
hasBackButton?: boolean;
browserPackage?: string;
showInRecents?: boolean;
};
export declare type InAppBrowserOptions = InAppBrowserAndroidOptions & InAppBrowseriOSOptions;
export declare type AuthSessionResult = RedirectResult | BrowserResult;
export declare type OpenBrowserAsync = (url: string, options?: InAppBrowserOptions) => Promise<BrowserResult>;
export interface InAppBrowserClassMethods {
open: OpenBrowserAsync;
close: () => void;
openAuth: (url: string, redirectUrl: string, options?: InAppBrowserOptions) => Promise<AuthSessionResult>;
closeAuth: () => void;
isAvailable: () => Promise<boolean>;
}
export declare type RedirectResolve = (value?: AuthSessionResult | PromiseLike<AuthSessionResult>) => void;
export declare type RedirectReject = (reason?: any) => void;
export declare const InAppBrowserErrorMessage = "Another InAppBrowser is already being presented.";
export declare enum BROWSER_TYPES {

@@ -6,14 +63,10 @@ CANCEL = "cancel",

}
export declare type RedirectEvent = {
url: 'string';
};
export declare type BrowserResult = {
type: 'cancel' | 'dismiss';
message?: string;
};
export declare type RedirectResult = {
type: 'success';
export declare enum DISMISS_BUTTON_STYLES {
DONE = "done",
CLOSE = "close",
CANCEL = "cancel"
}
export declare function getDefaultOptions(url: string, options?: InAppBrowserOptions): InAppBrowserOptions & {
url: string;
};
export declare type AuthSessionResult = RedirectResult | BrowserResult;
export declare function getDefaultOptions(url: string, options: any): any;
export {};

@@ -1,4 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var BROWSER_TYPES;
export const InAppBrowserErrorMessage = 'Another InAppBrowser is already being presented.';
export var BROWSER_TYPES;
(function (BROWSER_TYPES) {

@@ -8,7 +7,18 @@ BROWSER_TYPES["CANCEL"] = "cancel";

BROWSER_TYPES["SUCCESS"] = "success";
})(BROWSER_TYPES = exports.BROWSER_TYPES || (exports.BROWSER_TYPES = {}));
function getDefaultOptions(url, options) {
return __assign(__assign({}, options), { url: url, dismissButtonStyle: options.dismissButtonStyle || 'close', readerMode: !!options.readerMode, animated: options.animated !== undefined ? options.animated : true, modalEnabled: options.modalEnabled !== undefined ? options.modalEnabled : true, enableBarCollapsing: !!options.enableBarCollapsing });
})(BROWSER_TYPES || (BROWSER_TYPES = {}));
export var DISMISS_BUTTON_STYLES;
(function (DISMISS_BUTTON_STYLES) {
DISMISS_BUTTON_STYLES["DONE"] = "done";
DISMISS_BUTTON_STYLES["CLOSE"] = "close";
DISMISS_BUTTON_STYLES["CANCEL"] = "cancel";
})(DISMISS_BUTTON_STYLES || (DISMISS_BUTTON_STYLES = {}));
export function getDefaultOptions(url, options = {
animated: true,
modalEnabled: true,
dismissButtonStyle: 'close',
readerMode: false,
enableBarCollapsing: false,
}) {
return Object.assign(Object.assign({}, options), { url });
}
exports.getDefaultOptions = getDefaultOptions;
//# sourceMappingURL=InAppBrowser.common.js.map

@@ -1,39 +0,2 @@

import { BrowserResult, AuthSessionResult } from './InAppBrowser.common';
declare type InAppBrowserOptions = {
dismissButtonStyle?: 'done' | 'close' | 'cancel';
preferredBarTintColor?: string;
preferredControlTintColor?: string;
readerMode?: boolean;
animated?: boolean;
modalPresentationStyle?: 'automatic' | 'fullScreen' | 'pageSheet' | 'formSheet' | 'currentContext' | 'custom' | 'overFullScreen' | 'overCurrentContext' | 'popover' | 'none';
modalTransitionStyle?: 'coverVertical' | 'flipHorizontal' | 'crossDissolve' | 'partialCurl';
modalEnabled?: boolean;
enableBarCollapsing?: boolean;
ephemeralWebSession?: boolean;
};
declare class InAppBrowserModule extends NSObject {
static ObjCProtocols: ({
prototype: SFSafariViewControllerDelegate;
} | {
prototype: UIAdaptivePresentationControllerDelegate;
} | {
prototype: ASWebAuthenticationPresentationContextProviding;
})[];
private safariVC;
private redirectResolve;
private redirectReject;
private authSession;
private animated;
isAvailable(): Promise<boolean>;
open(authURL: string, options?: InAppBrowserOptions): Promise<BrowserResult>;
close(): void;
openAuth(authUrl: string, redirectUrl: string, options?: InAppBrowserOptions): Promise<AuthSessionResult>;
closeAuth(): void;
presentationAnchorForWebAuthenticationSession(session: ASWebAuthenticationSession): UIWindow;
private dismissWithoutAnimation;
safariViewControllerDidFinish(controller: SFSafariViewController): void;
private flowDidFinish;
private initializeWebBrowser;
}
declare const _default: InAppBrowserModule;
export default _default;
import { InAppBrowserClassMethods } from './InAppBrowser.common';
export declare const InAppBrowser: InAppBrowserClassMethods;

@@ -1,39 +0,15 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var color_1 = require("tns-core-modules/color");
var utils_1 = require("tns-core-modules/utils/utils");
var InAppBrowser_common_1 = require("./InAppBrowser.common");
var getPresentationStyle = function (styleKey) {
var styles = {
none: -1,
fullScreen: 0,
pageSheet: 1,
formSheet: 2,
currentContext: 3,
custom: 4,
overFullScreen: 5,
overCurrentContext: 6,
popover: 7
};
var defaultModalPresentationStyle = utils_1.ios.MajorVersion >= 13 ?
-2 : 0;
return styles[styleKey] !== undefined ? styles[styleKey] : defaultModalPresentationStyle;
};
var getTransitionStyle = function (styleKey) {
var styles = {
coverVertical: 0,
flipHorizontal: 1,
crossDissolve: 2,
partialCurl: 3
};
return styles[styleKey] !== undefined ? styles[styleKey] : 0;
};
var DEFAULT_PROTOCOLS = [
import { Color, Utils } from '@nativescript/core';
import { getDefaultOptions, BROWSER_TYPES, DISMISS_BUTTON_STYLES, InAppBrowserErrorMessage, } from './InAppBrowser.common';
import { getTransitionStyle, getPresentationStyle, setModalInPresentation, dismissWithoutAnimation, InAppBrowserOpenAuthErrorMessage, } from './utils.ios';
const DEFAULT_PROTOCOLS = [
SFSafariViewControllerDelegate,
UIAdaptivePresentationControllerDelegate
];
var protocols = utils_1.ios.MajorVersion >= 13 ? __spreadArrays(DEFAULT_PROTOCOLS, [
const protocols = Utils.ios.MajorVersion >= 13 ? [
...DEFAULT_PROTOCOLS,
ASWebAuthenticationPresentationContextProviding
]) : DEFAULT_PROTOCOLS;
var InAppBrowserModule = (function (_super) {
] : DEFAULT_PROTOCOLS;
let InAppBrowserModuleInstance;
function setup() {
var InAppBrowserModule = /** @class */ (function (_super) {
__extends(InAppBrowserModule, _super);

@@ -50,14 +26,22 @@ function InAppBrowserModule() {

InAppBrowserModule.prototype.isAvailable = function () {
return Promise.resolve(utils_1.ios.MajorVersion >= 9);
return Promise.resolve(Utils.ios.MajorVersion >= 9);
};
InAppBrowserModule.prototype.initializeWebBrowser = function (resolve, reject) {
if (this.redirectReject) {
this.redirectReject(InAppBrowserErrorMessage);
return false;
}
this.redirectResolve = resolve;
this.redirectReject = reject;
return true;
};
InAppBrowserModule.prototype.open = function (authURL, options) {
var _this = this;
if (options === void 0) { options = {}; }
return new Promise(function (resolve, reject) {
if (!_this.initializeWebBrowser(resolve, reject))
return;
var inAppBrowserOptions = InAppBrowser_common_1.getDefaultOptions(authURL, options);
var inAppBrowserOptions = getDefaultOptions(authURL, options);
_this.animated = inAppBrowserOptions.animated;
var url = NSURL.URLWithString(inAppBrowserOptions['url']);
if (utils_1.ios.MajorVersion >= 11) {
var url = NSURL.URLWithString(inAppBrowserOptions.url);
if (Utils.ios.MajorVersion >= 11) {
var config = SFSafariViewControllerConfiguration.alloc().init();

@@ -72,19 +56,19 @@ config.barCollapsingEnabled = inAppBrowserOptions.enableBarCollapsing;

_this.safariVC.delegate = _this;
if (utils_1.ios.MajorVersion >= 11) {
if (inAppBrowserOptions.dismissButtonStyle === 'done') {
_this.safariVC.dismissButtonStyle = 0;
if (Utils.ios.MajorVersion >= 11) {
if (inAppBrowserOptions.dismissButtonStyle === DISMISS_BUTTON_STYLES.DONE) {
_this.safariVC.dismissButtonStyle = SFSafariViewControllerDismissButtonStyle.Done;
}
else if (inAppBrowserOptions.dismissButtonStyle === 'close') {
_this.safariVC.dismissButtonStyle = 1;
else if (inAppBrowserOptions.dismissButtonStyle === DISMISS_BUTTON_STYLES.CLOSE) {
_this.safariVC.dismissButtonStyle = SFSafariViewControllerDismissButtonStyle.Close;
}
else if (inAppBrowserOptions.dismissButtonStyle === 'cancel') {
_this.safariVC.dismissButtonStyle = 2;
else if (inAppBrowserOptions.dismissButtonStyle === DISMISS_BUTTON_STYLES.CANCEL) {
_this.safariVC.dismissButtonStyle = SFSafariViewControllerDismissButtonStyle.Cancel;
}
}
if (utils_1.ios.MajorVersion >= 10) {
if (Utils.ios.MajorVersion >= 10) {
if (inAppBrowserOptions.preferredBarTintColor) {
_this.safariVC.preferredBarTintColor = new color_1.Color(inAppBrowserOptions.preferredBarTintColor).ios;
_this.safariVC.preferredBarTintColor = new Color(inAppBrowserOptions.preferredBarTintColor).ios;
}
if (inAppBrowserOptions.preferredControlTintColor) {
_this.safariVC.preferredControlTintColor = new color_1.Color(inAppBrowserOptions.preferredControlTintColor).ios;
_this.safariVC.preferredControlTintColor = new Color(inAppBrowserOptions.preferredControlTintColor).ios;
}

@@ -94,4 +78,8 @@ }

if (inAppBrowserOptions.modalEnabled) {
// This is a hack to present the SafariViewController modally
var safariHackVC = UINavigationController.alloc().initWithRootViewController(_this.safariVC);
safariHackVC.setNavigationBarHiddenAnimated(true, false);
// To disable "Swipe to dismiss" gesture which sometimes causes a bug where `safariViewControllerDidFinish`
// is not called.
_this.safariVC.modalPresentationStyle = UIModalPresentationStyle.OverFullScreen;
safariHackVC.modalPresentationStyle = getPresentationStyle(inAppBrowserOptions.modalPresentationStyle);

@@ -101,6 +89,6 @@ if (_this.animated) {

}
if (utils_1.ios.MajorVersion >= 13) {
if (Utils.ios.MajorVersion >= 13) {
safariHackVC.modalInPresentation = true;
if (safariHackVC['setModalInPresentation'])
safariHackVC['setModalInPresentation'](true);
if (safariHackVC[setModalInPresentation])
safariHackVC[setModalInPresentation](true);
}

@@ -129,3 +117,3 @@ safariHackVC.presentationController.delegate = _this;

if (options === void 0) { options = {}; }
return __awaiter(this, void 0, void 0, function () {
return __awaiter(this, void 0, Promise, function () {
var inAppBrowserOptions, response;

@@ -135,11 +123,11 @@ var _this = this;

inAppBrowserOptions = __assign(__assign({}, options), { ephemeralWebSession: options.ephemeralWebSession !== undefined ? options.ephemeralWebSession : false });
if (utils_1.ios.MajorVersion >= 11) {
return [2, new Promise(function (resolve, reject) {
if (Utils.ios.MajorVersion >= 11) {
return [2 /*return*/, new Promise(function (resolve, reject) {
if (!_this.initializeWebBrowser(resolve, reject))
return;
var url = NSURL.URLWithString(authUrl);
_this.authSession = (utils_1.ios.MajorVersion >= 12 ? ASWebAuthenticationSession : SFAuthenticationSession).alloc().initWithURLCallbackURLSchemeCompletionHandler(url, redirectUrl, function (callbackURL, error) {
_this.authSession = (Utils.ios.MajorVersion >= 12 ? ASWebAuthenticationSession : SFAuthenticationSession).alloc().initWithURLCallbackURLSchemeCompletionHandler(url, redirectUrl, function (callbackURL, error) {
if (!error) {
_this.redirectResolve({
type: 'success',
type: BROWSER_TYPES.SUCCESS,
url: callbackURL.absoluteString

@@ -150,3 +138,3 @@ });

_this.redirectResolve({
type: 'cancel'
type: BROWSER_TYPES.CANCEL
});

@@ -156,4 +144,5 @@ }

});
if (utils_1.ios.MajorVersion >= 13) {
if (Utils.ios.MajorVersion >= 13) {
var webAuthSession = _this.authSession;
// Prevent re-use cookie from last auth session
webAuthSession.prefersEphemeralWebBrowserSession = inAppBrowserOptions.ephemeralWebSession;

@@ -168,8 +157,8 @@ webAuthSession.presentationContextProvider = _this;

response = {
type: 'cancel',
message: 'openAuth requires iOS 11 or greater'
type: BROWSER_TYPES.CANCEL,
message: InAppBrowserOpenAuthErrorMessage
};
return [2, Promise.resolve(response)];
return [2 /*return*/, Promise.resolve(response)];
}
return [2];
return [2 /*return*/];
});

@@ -179,3 +168,3 @@ });

InAppBrowserModule.prototype.closeAuth = function () {
if (utils_1.ios.MajorVersion >= 11) {
if (Utils.ios.MajorVersion >= 11) {
var authSession = this.authSession;

@@ -185,3 +174,3 @@ authSession.cancel();

this.redirectResolve({
type: 'dismiss'
type: BROWSER_TYPES.DISMISS
});

@@ -195,30 +184,15 @@ this.flowDidFinish();

};
InAppBrowserModule.prototype.presentationAnchorForWebAuthenticationSession = function (session) {
InAppBrowserModule.prototype.presentationAnchorForWebAuthenticationSession = function (_) {
return UIApplication.sharedApplication.keyWindow;
};
InAppBrowserModule.prototype.dismissWithoutAnimation = function (controller) {
var transition = CATransition.animation();
transition.duration = 0;
transition.timingFunction = CAMediaTimingFunction.functionWithName(kCAMediaTimingFunctionLinear);
transition.type = kCATransitionFade;
transition.subtype = kCATransitionFromBottom;
controller.view.alpha = 0.05;
controller.view.frame = CGRectMake(0.0, 0.0, 0.5, 0.5);
var ctrl = UIApplication.sharedApplication.keyWindow.rootViewController;
var animationKey = 'dismissInAppBrowser';
ctrl.view.layer.addAnimationForKey(transition, animationKey);
ctrl.dismissViewControllerAnimatedCompletion(false, function () {
ctrl.view.layer.removeAnimationForKey(animationKey);
});
};
InAppBrowserModule.prototype.safariViewControllerDidFinish = function (controller) {
if (!this.animated) {
this.dismissWithoutAnimation(controller);
}
if (this.redirectResolve) {
this.redirectResolve({
type: 'cancel'
type: BROWSER_TYPES.CANCEL
});
this.flowDidFinish();
}
this.flowDidFinish();
if (!this.animated) {
dismissWithoutAnimation(controller);
}
};

@@ -230,15 +204,11 @@ InAppBrowserModule.prototype.flowDidFinish = function () {

};
InAppBrowserModule.prototype.initializeWebBrowser = function (resolve, reject) {
if (this.redirectResolve) {
reject('Another InAppBrowser is already being presented.');
return false;
}
this.redirectResolve = resolve;
this.redirectReject = reject;
return true;
};
InAppBrowserModule.ObjCProtocols = protocols;
return InAppBrowserModule;
}(NSObject));
exports.default = InAppBrowserModule.new();
return InAppBrowserModule.new();
}
if (typeof InAppBrowserModuleInstance === 'undefined') {
InAppBrowserModuleInstance = setup();
}
export const InAppBrowser = InAppBrowserModuleInstance;
//# sourceMappingURL=InAppBrowser.ios.js.map

@@ -1,80 +0,3 @@

declare module 'nativescript-inappbrowser' {
export interface RedirectEvent {
url: 'string';
}
import { InAppBrowserClassMethods } from './InAppBrowser.common';
export interface BrowserResult {
type: 'cancel' | 'dismiss';
}
export interface RedirectResult {
type: 'success';
url: string;
}
type InAppBrowseriOSOptions = {
dismissButtonStyle?: 'done' | 'close' | 'cancel',
preferredBarTintColor?: string,
preferredControlTintColor?: string,
readerMode?: boolean,
animated?: boolean,
modalPresentationStyle?:
| 'automatic'
| 'fullScreen'
| 'pageSheet'
| 'formSheet'
| 'currentContext'
| 'custom'
| 'overFullScreen'
| 'overCurrentContext'
| 'popover'
| 'none',
modalTransitionStyle?:
| 'coverVertical'
| 'flipHorizontal'
| 'crossDissolve'
| 'partialCurl',
modalEnabled?: boolean,
enableBarCollapsing?: boolean,
ephemeralWebSession?: boolean
};
type InAppBrowserAndroidOptions = {
showTitle?: boolean,
toolbarColor?: string,
secondaryToolbarColor?: string,
enableUrlBarHiding?: boolean,
enableDefaultShare?: boolean,
forceCloseOnRedirection?: boolean,
animations?: {
startEnter: string,
startExit: string,
endEnter: string,
endExit: string
},
headers?: { [key: string]: string }
};
export type InAppBrowserOptions = InAppBrowserAndroidOptions | InAppBrowseriOSOptions;
type AuthSessionResult = RedirectResult | BrowserResult;
interface InAppBrowserClassMethods {
open: (
url: string,
options?: InAppBrowserOptions,
) => Promise<BrowserResult>;
close: () => void;
openAuth: (
url: string,
redirectUrl: string,
options?: InAppBrowserOptions,
) => Promise<AuthSessionResult>;
closeAuth: () => void;
isAvailable: () => Promise<boolean>;
}
const InAppBrowser: InAppBrowserClassMethods;
export default InAppBrowser;
}
export const InAppBrowser: InAppBrowserClassMethods;
{
"name": "nativescript-inappbrowser",
"version": "2.3.0",
"version": "3.0.0",
"description": "InAppBrowser for NativeScript",

@@ -18,3 +18,3 @@ "main": "InAppBrowser",

"scripts": {
"tsc": "npm i && tsc",
"tsc": "npm i && ts-patch install && tsc",
"build": "npm run tsc && npm run build.native",

@@ -29,5 +29,5 @@ "build.native": "node scripts/build-native.js",

"demo.android": "npm i && cd ../demo && tns run android",
"demo.reset": "cd ../demo && npx rimraf -- hooks node_modules platforms package-lock.json",
"demo.reset": "cd ../demo && npx rimraf hooks node_modules platforms package-lock.json",
"plugin.prepare": "npm run build && cd ../demo && tns plugin remove nativescript-inappbrowser && tns plugin add ../src",
"clean": "npm run demo.reset && npx rimraf -- node_modules package-lock.json && npm i"
"clean": "npm run demo.reset && npx rimraf node_modules package-lock.json && npm i"
},

@@ -62,12 +62,14 @@ "keywords": [

"devDependencies": {
"tns-core-modules": "^6.5.1",
"tns-platform-declarations": "^6.5.1",
"typescript": "~3.8.3",
"@nativescript/core": "~7.0.0",
"@nativescript/types": "~7.0.0",
"@nativescript/webpack": "~3.0.0",
"typescript": "~3.9.0",
"prompt": "^1.0.0",
"rimraf": "^3.0.2",
"tslint": "^6.1.1",
"ts-node": "^9.0.0",
"ts-patch": "^1.3.0",
"semver": "^7.2.1"
},
"dependencies": {},
"bootstrapper": "nativescript-plugin-seed"
}

@@ -32,6 +32,7 @@ <p align="center">

<h1 align="center">InAppBrowser for NativeScript</h1>
<h3 align="center">Provides access to the system's web browser and supports handling redirects</h3>
<h4 align="center"><a href="https://developer.chrome.com/multidevice/android/customtabs#whatarethey">Chrome Custom Tabs</a> for Android & <a href="https://developer.apple.com/documentation/safariservices">SafariServices</a>/<a href="https://developer.apple.com/documentation/authenticationservices">AuthenticationServices</a> for iOS.</h4>
<p align="center">
<img width="400px" src="img/inappbrowser.png">
<img width="400px" src="https://github.com/proyecto26/nativescript-inappbrowser/blob/develop/img/inappbrowser.png?raw=true">
</p>

@@ -83,9 +84,11 @@

`forceCloseOnRedirection` (Boolean) | Open Custom Tab in a new task to avoid issues redirecting back to app scheme. [`true`/`false`]
`hasBackButton` (Boolean) | Sets a back arrow instead of the default `X` icon to close the custom tab. [`true`/`false`]
`browserPackage` (String) | Package name of a browser to be used to handle Custom Tabs.
`showInRecents` (Boolean) | Determining whether browsed website should be shown as separate entry in Android recents/multitasking view. [`true`/`false`]
### Demo
```javascript
import { openUrl } from 'tns-core-modules/utils/utils'
import { alert } from 'tns-core-modules/ui/dialogs'
import InAppBrowser from 'nativescript-inappbrowser'
```ts
import { Utils, Dialogs } from '@nativescript/core';
import { InAppBrowser } from 'nativescript-inappbrowser';

@@ -105,3 +108,3 @@ ...

modalPresentationStyle: 'fullScreen',
modalTransitionStyle: 'partialCurl',
modalTransitionStyle: 'coverVertical',
modalEnabled: true,

@@ -126,20 +129,23 @@ enableBarCollapsing: false,

'my-custom-header': 'my custom header value'
}
})
alert({
},
hasBackButton: true,
browserPackage: '',
showInRecents: false
});
Dialogs.alert({
title: 'Response',
message: JSON.stringify(result),
okButtonText: 'Ok'
})
});
}
else {
openUrl(url);
Utils.openUrl(url);
}
}
catch(error) {
alert({
Dialogs.alert({
title: 'Error',
message: error.message,
okButtonText: 'Ok'
})
});
}

@@ -161,3 +167,3 @@ }

<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="my-scheme" android:host="my-host" android:pathPrefix="" />
<data android:scheme="my-scheme" android:host="my-host" />
</intent-filter>

@@ -185,6 +191,5 @@ ```

```javascript
import { android } from "tns-core-modules/application";
export const getDeepLink = (path = "") => {
const scheme = 'my-scheme';
const prefix = android ? `${scheme}://my-host/` : `${scheme}://`;
const prefix = global.isAndroid ? `${scheme}://my-host/` : `${scheme}://`;
return prefix + path;

@@ -195,9 +200,9 @@ }

- home-page.ts
```javascript
import { openUrl } from 'tns-core-modules/utils/utils';
import InAppBrowser from 'nativescript-inappbrowser';
```ts
import { Utils, Dialogs } from '@nativescript/core';
import { InAppBrowser } from 'nativescript-inappbrowser';
import { getDeepLink } from './utilities';
...
async onLogin() {
const deepLink = getDeepLink("callback")
const deepLink = getDeepLink('callback')
const url = `https://my-auth-login-page.com?redirect_uri=${deepLink}`

@@ -218,8 +223,8 @@ try {

) {
openUrl(response.url)
Utils.openUrl(response.url)
}
})
} else openUrl(url)
} else Utils.openUrl(url)
} catch (error) {
openUrl(url)
Utils.openUrl(url)
}

@@ -234,11 +239,16 @@ }

## Credits 👍
* **React Native InAppBrowser:** [InAppBrowser for React Native](https://github.com/proyecto26/react-native-inappbrowser)
## Contributors ✨
Please do contribute! Issues and pull requests are welcome.
## Contributors ✨
Thanks goes to these wonderful people:
<!-- CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
### Code Contributors
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
[![](https://sourcerer.io/fame/jdnichollsc/proyecto26/nativescript-inappbrowser/images/0)](https://sourcerer.io/fame/jdnichollsc/proyecto26/nativescript-inappbrowser/links/0)[![](https://sourcerer.io/fame/jdnichollsc/proyecto26/nativescript-inappbrowser/images/1)](https://sourcerer.io/fame/jdnichollsc/proyecto26/nativescript-inappbrowser/links/1)[![](https://sourcerer.io/fame/jdnichollsc/proyecto26/nativescript-inappbrowser/images/2)](https://sourcerer.io/fame/jdnichollsc/proyecto26/nativescript-inappbrowser/links/2)[![](https://sourcerer.io/fame/jdnichollsc/proyecto26/nativescript-inappbrowser/images/3)](https://sourcerer.io/fame/jdnichollsc/proyecto26/nativescript-inappbrowser/links/3)[![](https://sourcerer.io/fame/jdnichollsc/proyecto26/nativescript-inappbrowser/images/4)](https://sourcerer.io/fame/jdnichollsc/proyecto26/nativescript-inappbrowser/links/4)[![](https://sourcerer.io/fame/jdnichollsc/proyecto26/nativescript-inappbrowser/images/5)](https://sourcerer.io/fame/jdnichollsc/proyecto26/nativescript-inappbrowser/links/5)[![](https://sourcerer.io/fame/jdnichollsc/proyecto26/nativescript-inappbrowser/images/6)](https://sourcerer.io/fame/jdnichollsc/proyecto26/nativescript-inappbrowser/links/6)[![](https://sourcerer.io/fame/jdnichollsc/proyecto26/nativescript-inappbrowser/images/7)](https://sourcerer.io/fame/jdnichollsc/proyecto26/nativescript-inappbrowser/links/7)
### Collaborators
<!-- COLLABORATORS-LIST:START - Do not remove or modify this section -->
| [<img alt="jdnichollsc" src="https://avatars3.githubusercontent.com/u/2154886?v=3" width="100" /><br /><sub><b>Juan Nicholls</b></sub>](https://github.com/jdnichollsc)<br />[✉](mailto:jdnichollsc@hotmail.com) | [<img alt="NathanaelA" src="https://avatars3.githubusercontent.com/u/850871?v=3" width="100" /><br /><sub><b>Nathanael Anderson</b></sub>](https://github.com/NathanaelA)<br />[✉](mailto:nathan@master-technology.com) |
| :---: | :---: |
<!-- CONTRIBUTORS-LIST:END -->
<!-- COLLABORATORS-LIST:END -->

@@ -268,7 +278,15 @@ ### Financial Contributors

## Credits 👍
* **React Native InAppBrowser:** [InAppBrowser for React Native](https://github.com/proyecto26/react-native-inappbrowser)
## Supporting 🍻
I believe in Unicorns 🦄
Support [me](http://www.paypal.me/jdnichollsc/2), if you do too.
[Professionally supported nativescript-inappbrowser is coming soon](https://tidelift.com/subscription/pkg/npm-nativescript-inappbrowser?utm_source=npm-nativescript-inappbrowser&utm_medium=referral&utm_campaign=readme)
## Enterprise 💼
Available as part of the Tidelift Subscription.
The maintainers of InAppBrowser for NativeScript and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-nativescript-inappbrowser?utm_source=npm-nativescript-inappbrowser&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
## Security contact information 🚨

@@ -275,0 +293,0 @@ To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.

@@ -1,5 +0,4 @@

/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/@nativescript/types/index.d.ts" />
/// <reference path="./types/android.d.ts" />
/// <reference path="./types/ios.d.ts" />
declare namespace android {
export namespace support {
export namespace customtabs {
export class CustomTabsClient {
static getPackageName(context: android.content.Context, list: java.util.List): string;
}
export class CustomTabsIntent {

@@ -9,2 +12,3 @@ launchUrl(context: android.content.Context, url: android.net.Uri): void;

static EXTRA_TITLE_VISIBILITY_STATE: string;
static EXTRA_ENABLE_URLBAR_HIDING: string;
startAnimationBundle: android.os.Bundle;

@@ -21,4 +25,5 @@ }

enableUrlBarHiding(): this;
setStartAnimations(context: android.content.Context, enterResId: number, exitResId: number);
setExitAnimations(context: android.content.Context, enterResId: number, exitResId: number);
setStartAnimations(context: android.content.Context, enterResId: number, exitResId: number): this;
setExitAnimations(context: android.content.Context, enterResId: number, exitResId: number): this;
setCloseButtonIcon(icon: android.graphics.Bitmap): this;
}

@@ -33,2 +38,5 @@ }

export namespace customtabs {
export class CustomTabsClient {
static getPackageName(context: android.content.Context, list: java.util.List): string;
}
export class CustomTabsIntent {

@@ -39,2 +47,3 @@ launchUrl(context: android.content.Context, url: android.net.Uri): void;

static EXTRA_TITLE_VISIBILITY_STATE: string;
static EXTRA_ENABLE_URLBAR_HIDING: string;
startAnimationBundle: android.os.Bundle;

@@ -51,4 +60,5 @@ }

enableUrlBarHiding(): this;
setStartAnimations(context: android.content.Context, enterResId: number, exitResId: number);
setExitAnimations(context: android.content.Context, enterResId: number, exitResId: number);
setStartAnimations(context: android.content.Context, enterResId: number, exitResId: number): this;
setExitAnimations(context: android.content.Context, enterResId: number, exitResId: number): this;
setCloseButtonIcon(icon: android.graphics.Bitmap): this;
}

@@ -55,0 +65,0 @@ }

import Activity = android.app.Activity;
import { BrowserResult, AuthSessionResult } from './InAppBrowser.common';
import Context = android.content.Context;
import ResolveInfo = android.content.pm.ResolveInfo;
import List = java.util.List;
import { OpenBrowserAsync, AuthSessionResult, InAppBrowserOptions } from './InAppBrowser.common';
export declare type Builder = androidx.browser.customtabs.CustomTabsIntent.Builder;
export declare const CustomTabsIntent: typeof androidx.browser.customtabs.CustomTabsIntent;
export declare const CustomTabsClient: typeof androidx.browser.customtabs.CustomTabsClient;
export declare const ColorUtils: typeof androidx.core.graphics.ColorUtils;
export declare const CHROME_PACKAGE_STABLE = "com.android.chrome";
export declare const CHROME_PACKAGE_BETA = "com.chrome.beta";
export declare const CHROME_PACKAGE_DEV = "com.chrome.dev";
export declare const LOCAL_PACKAGE = "com.google.android.apps.chrome";
export declare const ACTION_CUSTOM_TABS_CONNECTION = "android.support.customtabs.action.CustomTabsService";
export declare const ARROW_BACK_BLACK = "ic_arrow_back_black";
export declare const ARROW_BACK_WHITE = "ic_arrow_back_white";
export declare const DISMISSED_EVENT = "DismissedEvent";
export declare const getDrawableId: typeof import("@nativescript/core/utils").ad.resources.getDrawableId;
export declare function useAndroidX(): typeof androidx.browser;
export declare function getInitialURL(activity: Activity): string;
export declare function openAuthSessionPolyfillAsync(startUrl: string, returnUrl: string, options: any, open: (url: string, options?: any) => Promise<BrowserResult>): Promise<AuthSessionResult>;
export declare function openAuthSessionPolyfillAsync(open: OpenBrowserAsync, startUrl: string, returnUrl: string, options?: InAppBrowserOptions): Promise<AuthSessionResult>;
export declare function closeAuthSessionPolyfillAsync(): void;
export declare function getPreferredPackages(context: Context): List<ResolveInfo>;
export declare function toolbarIsLight(themeColor: string): boolean;
export declare function getDefaultBrowser(context: Context): string;

@@ -1,17 +0,37 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Intent = android.content.Intent;
var NfcAdapter = android.nfc.NfcAdapter;
var application_1 = require("tns-core-modules/application");
var InAppBrowser_common_1 = require("./InAppBrowser.common");
var _redirectHandler;
function getInitialURL(activity) {
var Color = android.graphics.Color;
var Arrays = java.util.Arrays;
import { Utils, Application, AndroidApplication } from '@nativescript/core';
import { BROWSER_TYPES } from './InAppBrowser.common';
export const CustomTabsIntent = (useAndroidX() ? androidx.browser : android.support).customtabs.CustomTabsIntent;
export const CustomTabsClient = (useAndroidX() ? androidx.browser : android.support).customtabs.CustomTabsClient;
export const ColorUtils = (useAndroidX()
? androidx.core.graphics
: android.support.v4.graphics).ColorUtils;
export const CHROME_PACKAGE_STABLE = "com.android.chrome";
export const CHROME_PACKAGE_BETA = "com.chrome.beta";
export const CHROME_PACKAGE_DEV = "com.chrome.dev";
export const LOCAL_PACKAGE = "com.google.android.apps.chrome";
export const ACTION_CUSTOM_TABS_CONNECTION = "android.support.customtabs.action.CustomTabsService";
export const ARROW_BACK_BLACK = 'ic_arrow_back_black';
export const ARROW_BACK_WHITE = 'ic_arrow_back_white';
export const DISMISSED_EVENT = 'DismissedEvent';
let _redirectHandler;
let initialUrl = '';
export const getDrawableId = Utils.ad.resources.getDrawableId;
export function useAndroidX() {
return global.androidx && global.androidx.browser;
}
export function getInitialURL(activity) {
if (activity) {
var intent = activity.getIntent();
var action = intent.getAction();
var uri = intent.getData();
const intent = activity.getIntent();
const action = intent.getAction();
const uri = intent.getData();
if (uri !== null && (Intent.ACTION_VIEW === action ||
NfcAdapter.ACTION_NDEF_DISCOVERED === action)) {
var url = '' + uri;
intent.setData(null);
const url = '' + uri;
if (url === initialUrl)
return null;
initialUrl = url;
return url;

@@ -22,48 +42,74 @@ }

}
exports.getInitialURL = getInitialURL;
function _waitForRedirectAsync(returnUrl) {
return new Promise(function (resolve) {
_redirectHandler = function (args) {
var currentActivity = args.object.foregroundActivity || args.object.startActivity;
var url = getInitialURL(currentActivity);
function waitForRedirectAsync(returnUrl) {
return new Promise(resolve => {
_redirectHandler = (args) => {
const url = getInitialURL(args.android);
if (url && url.startsWith(returnUrl)) {
resolve({ url: url, type: InAppBrowser_common_1.BROWSER_TYPES.SUCCESS });
resolve({ url: url, type: BROWSER_TYPES.SUCCESS });
}
};
application_1.on(application_1.resumeEvent, _redirectHandler);
Application.on(Application.resumeEvent, _redirectHandler);
});
}
function openAuthSessionPolyfillAsync(startUrl, returnUrl, options, open) {
function handleAppStateActiveOnce() {
return new Promise(function (resolve) {
if (!Application.android.paused) {
const activity = Application.android.foregroundActivity || Application.android.startActivity;
return resolve(activity);
}
Application.android.once(AndroidApplication.activityResumedEvent, function (args) {
resolve(args.activity);
});
});
}
async function checkResultAndReturnUrl(returnUrl, result) {
if (Application.android && result.type !== BROWSER_TYPES.CANCEL) {
try {
const activity = await handleAppStateActiveOnce();
const url = getInitialURL(activity);
return url && url.startsWith(returnUrl)
? { url: url, type: BROWSER_TYPES.SUCCESS }
: result;
}
catch (error) {
return result;
}
}
return result;
}
export function openAuthSessionPolyfillAsync(open, startUrl, returnUrl, options) {
return Promise.race([
_waitForRedirectAsync(returnUrl),
waitForRedirectAsync(returnUrl),
open(startUrl, options).then(function (result) {
return _checkResultAndReturnUrl(returnUrl, result);
return checkResultAndReturnUrl(returnUrl, result);
})
]);
}
exports.openAuthSessionPolyfillAsync = openAuthSessionPolyfillAsync;
function _checkResultAndReturnUrl(returnUrl, result) {
return new Promise(function (resolve) {
if (application_1.android && result.type !== InAppBrowser_common_1.BROWSER_TYPES.CANCEL) {
application_1.android.once(application_1.AndroidApplication.activityResumedEvent, function (args) {
var url = getInitialURL(args.activity);
if (url && url.startsWith(returnUrl)) {
return resolve({ url: url, type: InAppBrowser_common_1.BROWSER_TYPES.SUCCESS });
}
else
resolve(result);
});
}
else {
resolve(result);
}
});
}
function closeAuthSessionPolyfillAsync() {
export function closeAuthSessionPolyfillAsync() {
if (_redirectHandler) {
application_1.off(application_1.resumeEvent, _redirectHandler);
Application.off(Application.resumeEvent, _redirectHandler);
_redirectHandler = null;
}
}
exports.closeAuthSessionPolyfillAsync = closeAuthSessionPolyfillAsync;
export function getPreferredPackages(context) {
const serviceIntent = new Intent(ACTION_CUSTOM_TABS_CONNECTION);
const resolveInfos = context.getPackageManager().queryIntentServices(serviceIntent, 0);
return resolveInfos;
}
export function toolbarIsLight(themeColor) {
return ColorUtils.calculateLuminance(Color.parseColor(themeColor)) > 0.5;
}
export function getDefaultBrowser(context) {
const resolveInfos = getPreferredPackages(context);
const packageName = CustomTabsClient.getPackageName(context, Arrays.asList([
CHROME_PACKAGE_STABLE,
CHROME_PACKAGE_BETA,
CHROME_PACKAGE_DEV,
LOCAL_PACKAGE
]));
if (packageName == null && resolveInfos != null && resolveInfos.size() > 0) {
return resolveInfos.get(0).serviceInfo.packageName;
}
return packageName;
}
//# sourceMappingURL=utils.android.js.map

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc