nativescript-inappbrowser
Advanced tools
Comparing version 3.1.2 to 3.2.0
import Context = android.content.Context; | ||
import Intent = android.content.Intent; | ||
import Bundle = android.os.Bundle; | ||
import { Observable } from '@nativescript/core'; | ||
export declare class ChromeTabsEvent extends Observable { | ||
import { Observable } from "@nativescript/core"; | ||
declare class ChromeTabsEvent extends Observable { | ||
message: string; | ||
@@ -10,4 +10,4 @@ resultType: string; | ||
} | ||
export declare const BROWSER_ACTIVITY_EVENTS: ChromeTabsEvent; | ||
export declare class ChromeTabsManagerActivity extends android.app.Activity { | ||
declare const BROWSER_ACTIVITY_EVENTS: ChromeTabsEvent; | ||
declare class ChromeTabsManagerActivity extends android.app.Activity { | ||
private mOpened; | ||
@@ -24,4 +24,5 @@ private resultType; | ||
} | ||
export declare const createStartIntent: (context: Context, authIntent: Intent) => Intent; | ||
export declare const createDismissIntent: (context: Context) => Intent; | ||
export declare const createBaseIntent: (context: Context) => Intent; | ||
declare const createStartIntent: (context: Context, authIntent: Intent) => Intent; | ||
declare const createDismissIntent: (context: Context) => Intent; | ||
declare const createBaseIntent: (context: Context) => Intent; | ||
export { BROWSER_ACTIVITY_EVENTS, ChromeTabsEvent, createStartIntent, createDismissIntent, createBaseIntent, ChromeTabsManagerActivity, }; |
var Intent = android.content.Intent; | ||
import { Observable } from '@nativescript/core'; | ||
import { BROWSER_TYPES } from './InAppBrowser.common'; | ||
import { DISMISSED_EVENT } from './utils.android'; | ||
import { log } from './utils.common'; | ||
export class ChromeTabsEvent extends Observable { | ||
var Log = android.util.Log; | ||
import { Observable } from "@nativescript/core"; | ||
import { BROWSER_TYPES } from "./InAppBrowser.common"; | ||
import { DISMISSED_EVENT } from "./utils.android"; | ||
class ChromeTabsEvent extends Observable { | ||
} | ||
export const BROWSER_ACTIVITY_EVENTS = new ChromeTabsEvent(); | ||
const KEY_BROWSER_INTENT = 'browserIntent'; | ||
const BROWSER_RESULT_TYPE = 'browserResultType'; | ||
const BROWSER_ACTIVITY_EVENTS = new ChromeTabsEvent(); | ||
const KEY_BROWSER_INTENT = "browserIntent"; | ||
const BROWSER_RESULT_TYPE = "browserResultType"; | ||
const DEFAULT_RESULT_TYPE = BROWSER_TYPES.DISMISS; | ||
const TAG = "ChromeTabsManagerActivity"; | ||
const notifyMessage = (message, resultType, isError = false) => { | ||
BROWSER_ACTIVITY_EVENTS.set('message', message); | ||
BROWSER_ACTIVITY_EVENTS.set('resultType', resultType); | ||
BROWSER_ACTIVITY_EVENTS.set('isError', isError); | ||
BROWSER_ACTIVITY_EVENTS.set("message", message); | ||
BROWSER_ACTIVITY_EVENTS.set("resultType", resultType); | ||
BROWSER_ACTIVITY_EVENTS.set("isError", isError); | ||
BROWSER_ACTIVITY_EVENTS.notify({ | ||
eventName: DISMISSED_EVENT, | ||
object: BROWSER_ACTIVITY_EVENTS | ||
object: BROWSER_ACTIVITY_EVENTS, | ||
}); | ||
}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ChromeTabsManagerActivity = void 0; | ||
var ChromeTabsManagerActivity = /** @class */ (function (_super) { | ||
@@ -39,5 +37,6 @@ __extends(ChromeTabsManagerActivity, _super); | ||
// in order to close the intent that was started previously so we just close this. | ||
if (this.getIntent().hasExtra(KEY_BROWSER_INTENT) | ||
&& (!savedInstanceState || !savedInstanceState.getString(BROWSER_RESULT_TYPE))) { | ||
var browserIntent = this.getIntent().getParcelableExtra(KEY_BROWSER_INTENT); | ||
if (this.getIntent().hasExtra(KEY_BROWSER_INTENT) && | ||
(!savedInstanceState || | ||
!savedInstanceState.getString(BROWSER_RESULT_TYPE))) { | ||
var browserIntent = (this.getIntent().getParcelableExtra(KEY_BROWSER_INTENT)); | ||
browserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | ||
@@ -53,5 +52,5 @@ this.startActivity(browserIntent); | ||
this.isError = true; | ||
notifyMessage('Unable to open url.', this.resultType, this.isError); | ||
notifyMessage("Unable to open url.", this.resultType, this.isError); | ||
this.finish(); | ||
log("InAppBrowser: " + error); | ||
Log.e(TAG, error.message); | ||
} | ||
@@ -76,6 +75,6 @@ }; | ||
case BROWSER_TYPES.CANCEL: | ||
notifyMessage('chrome tabs activity closed', this.resultType, this.isError); | ||
notifyMessage("chrome tabs activity closed", this.resultType, this.isError); | ||
break; | ||
default: | ||
notifyMessage('chrome tabs activity destroyed', DEFAULT_RESULT_TYPE, this.isError); | ||
notifyMessage("chrome tabs activity destroyed", DEFAULT_RESULT_TYPE, this.isError); | ||
break; | ||
@@ -100,8 +99,7 @@ } | ||
ChromeTabsManagerActivity = __decorate([ | ||
JavaProxy('com.proyecto26.inappbrowser.ChromeTabsManagerActivity') | ||
JavaProxy("com.proyecto26.inappbrowser.ChromeTabsManagerActivity") | ||
], ChromeTabsManagerActivity); | ||
return ChromeTabsManagerActivity; | ||
}(android.app.Activity)); | ||
exports.ChromeTabsManagerActivity = ChromeTabsManagerActivity; | ||
export const createStartIntent = (context, authIntent) => { | ||
const createStartIntent = (context, authIntent) => { | ||
let intent = createBaseIntent(context); | ||
@@ -111,3 +109,3 @@ intent.putExtra(KEY_BROWSER_INTENT, authIntent); | ||
}; | ||
export const createDismissIntent = (context) => { | ||
const createDismissIntent = (context) => { | ||
let intent = createBaseIntent(context); | ||
@@ -117,5 +115,6 @@ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | ||
}; | ||
export const createBaseIntent = (context) => { | ||
const createBaseIntent = (context) => { | ||
return new Intent(context, ChromeTabsManagerActivity.class); | ||
}; | ||
export { BROWSER_ACTIVITY_EVENTS, ChromeTabsEvent, createStartIntent, createDismissIntent, createBaseIntent, ChromeTabsManagerActivity, }; | ||
//# sourceMappingURL=ChromeTabsManagerActivity.js.map |
@@ -1,2 +0,1 @@ | ||
import { InAppBrowserClassMethods } from './InAppBrowser.common'; | ||
export declare const InAppBrowser: InAppBrowserClassMethods; | ||
export declare const InAppBrowser: any; |
var Uri = android.net.Uri; | ||
var Build = android.os.Build; | ||
var Bundle = android.os.Bundle; | ||
@@ -8,7 +9,10 @@ var TextUtils = android.text.TextUtils; | ||
var Pattern = java.util.regex.Pattern; | ||
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'; | ||
import { tryParseColor } from './utils.common'; | ||
var ArrayList = java.util.ArrayList; | ||
var Log = android.util.Log; | ||
import { Application, Utils } from "@nativescript/core"; | ||
import { BROWSER_ACTIVITY_EVENTS, createDismissIntent, createStartIntent, } from "./ChromeTabsManagerActivity"; | ||
import { CustomTabsController } from "./CustomTabsServiceConnection"; | ||
import { BROWSER_TYPES, getDefaultOptions, } from "./InAppBrowser.common"; | ||
import { ARROW_BACK_BLACK, ARROW_BACK_WHITE, closeAuthSessionPolyfillAsync, CustomTabsCallback, CustomTabsClient, CustomTabsIntent, CustomTabsService, DISMISSED_EVENT, getDefaultBrowser, getDrawableId, getPreferredPackages, openAuthSessionPolyfillAsync, toolbarIsLight, } from "./utils.android"; | ||
import { tryParseColor } from "./utils.common"; | ||
let InAppBrowserModuleInstance; | ||
@@ -20,3 +24,3 @@ function setup() { | ||
var _this = _super.call(this) || this; | ||
_this.animationIdentifierPattern = Pattern.compile('^.+:.+/'); | ||
_this.animationIdentifierPattern = Pattern.compile("^.+:.+/"); | ||
return global.__native(_this); | ||
@@ -37,7 +41,9 @@ } | ||
result_1 = { | ||
type: BROWSER_TYPES.CANCEL | ||
type: BROWSER_TYPES.CANCEL, | ||
}; | ||
return [2 /*return*/, Promise.resolve(result_1)]; | ||
} | ||
this.currentActivity = Application.android.foregroundActivity || Application.android.startActivity; | ||
this.currentActivity = | ||
Application.android.foregroundActivity || | ||
Application.android.startActivity; | ||
if (!this.currentActivity) { | ||
@@ -55,3 +61,3 @@ return [2 /*return*/, Promise.reject(new Error(InAppBrowserModule.ERROR_CODE))]; | ||
if (colorString) { | ||
color = tryParseColor(colorString, 'Invalid toolbar color'); | ||
color = tryParseColor(colorString, "Invalid toolbar color"); | ||
if (color) { | ||
@@ -62,5 +68,6 @@ builder.setToolbarColor(color.android); | ||
} | ||
colorString = inAppBrowserOptions[InAppBrowserModule.KEY_SECONDARY_TOOLBAR_COLOR]; | ||
colorString = | ||
inAppBrowserOptions[InAppBrowserModule.KEY_SECONDARY_TOOLBAR_COLOR]; | ||
if (colorString) { | ||
color = tryParseColor(colorString, 'Invalid secondary toolbar color'); | ||
color = tryParseColor(colorString, "Invalid secondary toolbar color"); | ||
if (color) { | ||
@@ -70,5 +77,6 @@ builder.setSecondaryToolbarColor(color.android); | ||
} | ||
colorString = inAppBrowserOptions[InAppBrowserModule.KEY_NAVIGATION_BAR_COLOR]; | ||
colorString = | ||
inAppBrowserOptions[InAppBrowserModule.KEY_NAVIGATION_BAR_COLOR]; | ||
if (colorString) { | ||
color = tryParseColor(colorString, 'Invalid navigation bar color'); | ||
color = tryParseColor(colorString, "Invalid navigation bar color"); | ||
if (color) { | ||
@@ -78,5 +86,6 @@ builder.setNavigationBarColor(color.android); | ||
} | ||
colorString = inAppBrowserOptions[InAppBrowserModule.KEY_NAVIGATION_BAR_DIVIDER_COLOR]; | ||
colorString = | ||
inAppBrowserOptions[InAppBrowserModule.KEY_NAVIGATION_BAR_DIVIDER_COLOR]; | ||
if (colorString) { | ||
color = tryParseColor(colorString, 'Invalid navigation bar divider color'); | ||
color = tryParseColor(colorString, "Invalid navigation bar divider color"); | ||
if (color) { | ||
@@ -120,3 +129,4 @@ builder.setNavigationBarDividerColor(color.android); | ||
try { | ||
if (inAppBrowserOptions[InAppBrowserModule.KEY_BROWSER_PACKAGE] !== undefined) { | ||
if (inAppBrowserOptions[InAppBrowserModule.KEY_BROWSER_PACKAGE] !== | ||
undefined) { | ||
packageName = inAppBrowserOptions[InAppBrowserModule.KEY_BROWSER_PACKAGE]; | ||
@@ -128,3 +138,3 @@ if (!TextUtils.isEmpty(packageName)) { | ||
else { | ||
packageName = inAppBrowserOptions[InAppBrowserModule.KEY_BROWSER_PACKAGE]; | ||
packageName = getDefaultBrowser(context); | ||
intent.setPackage(packageName); | ||
@@ -146,2 +156,6 @@ } | ||
} | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && | ||
inAppBrowserOptions[InAppBrowserModule.KEY_INCLUDE_REFERRER]) { | ||
intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse("android-app://" + context.getApplicationContext().getPackageName())); | ||
} | ||
this.currentActivity.startActivity(createStartIntent(this.currentActivity, intent), customTabsIntent.startAnimationBundle); | ||
@@ -163,3 +177,3 @@ return [2 /*return*/, result]; | ||
var result = { | ||
type: 'dismiss' | ||
type: "dismiss", | ||
}; | ||
@@ -172,3 +186,2 @@ InAppBrowserModule.redirectResolve(result); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response; | ||
var _this = this; | ||
@@ -178,15 +191,10 @@ return __generator(this, function (_a) { | ||
case 0: | ||
response = null; | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, , 3, 4]); | ||
return [4 /*yield*/, openAuthSessionPolyfillAsync(function (startUrl, opt) { return _this.open(startUrl, opt); }, url, redirectUrl, options)]; | ||
_a.trys.push([0, , 2, 3]); | ||
return [4 /*yield*/, openAuthSessionPolyfillAsync(function () { return _this.open(url, options); }, redirectUrl)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
response = _a.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
closeAuthSessionPolyfillAsync(); | ||
this.close(); | ||
return [7 /*endfinally*/]; | ||
case 4: return [2 /*return*/, response]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
@@ -212,3 +220,3 @@ }); | ||
type: browserEvent.resultType, | ||
message: browserEvent.message | ||
message: browserEvent.message, | ||
}); | ||
@@ -227,3 +235,5 @@ } | ||
else { | ||
return context.getResources().getIdentifier(identifier, 'anim', context.getPackageName()); | ||
return context | ||
.getResources() | ||
.getIdentifier(identifier, "anim", context.getPackageName()); | ||
} | ||
@@ -255,20 +265,57 @@ }; | ||
}; | ||
InAppBrowserModule.ERROR_CODE = 'InAppBrowser'; | ||
InAppBrowserModule.KEY_TOOLBAR_COLOR = 'toolbarColor'; | ||
InAppBrowserModule.KEY_SECONDARY_TOOLBAR_COLOR = 'secondaryToolbarColor'; | ||
InAppBrowserModule.KEY_NAVIGATION_BAR_COLOR = 'navigationBarColor'; | ||
InAppBrowserModule.KEY_NAVIGATION_BAR_DIVIDER_COLOR = 'navigationBarDividerColor'; | ||
InAppBrowserModule.KEY_ENABLE_URL_BAR_HIDING = 'enableUrlBarHiding'; | ||
InAppBrowserModule.KEY_SHOW_PAGE_TITLE = 'showTitle'; | ||
InAppBrowserModule.KEY_DEFAULT_SHARE_MENU_ITEM = 'enableDefaultShare'; | ||
InAppBrowserModule.KEY_FORCE_CLOSE_ON_REDIRECTION = 'forceCloseOnRedirection'; | ||
InAppBrowserModule.KEY_ANIMATIONS = 'animations'; | ||
InAppBrowserModule.KEY_HEADERS = 'headers'; | ||
InAppBrowserModule.KEY_ANIMATION_START_ENTER = 'startEnter'; | ||
InAppBrowserModule.KEY_ANIMATION_START_EXIT = 'startExit'; | ||
InAppBrowserModule.KEY_ANIMATION_END_ENTER = 'endEnter'; | ||
InAppBrowserModule.KEY_ANIMATION_END_EXIT = 'endExit'; | ||
InAppBrowserModule.KEY_HAS_BACK_BUTTON = 'hasBackButton'; | ||
InAppBrowserModule.KEY_BROWSER_PACKAGE = 'browserPackage'; | ||
InAppBrowserModule.KEY_SHOW_IN_RECENTS = 'showInRecents'; | ||
InAppBrowserModule.prototype.onStart = function () { | ||
var context = Utils.android.getApplicationContext(); | ||
var connection = new CustomTabsController(context); | ||
var packageName = getDefaultBrowser(context); | ||
if (packageName) { | ||
CustomTabsClient.bindCustomTabsService(context, packageName, connection); | ||
} | ||
else { | ||
Log.e(InAppBrowserModule.ERROR_CODE, "No browser supported to bind custom tab service"); | ||
} | ||
}; | ||
InAppBrowserModule.prototype.warmup = function () { | ||
var customTabsClient = CustomTabsController.customTabsClient; | ||
if (customTabsClient) { | ||
return customTabsClient.warmup(long(0)); | ||
} | ||
return false; | ||
}; | ||
InAppBrowserModule.prototype.mayLaunchUrl = function (mostLikelyUrl, otherUrls) { | ||
var customTabsClient = CustomTabsController.customTabsClient; | ||
if (customTabsClient) { | ||
var customTabsSession = customTabsClient.newSession(new CustomTabsCallback()); | ||
if (customTabsSession != null) { | ||
var otherUrlBundles = new ArrayList(otherUrls.length); | ||
for (var index = 0; index < otherUrls.length; index++) { | ||
var link = otherUrls[index]; | ||
if (link) { | ||
var bundle = new Bundle(); | ||
bundle.putParcelable(CustomTabsService.KEY_URL, Uri.parse(link)); | ||
otherUrlBundles.add(bundle); | ||
} | ||
} | ||
customTabsSession.mayLaunchUrl(Uri.parse(mostLikelyUrl), null, otherUrlBundles); | ||
} | ||
} | ||
}; | ||
InAppBrowserModule.ERROR_CODE = "InAppBrowser"; | ||
InAppBrowserModule.KEY_TOOLBAR_COLOR = "toolbarColor"; | ||
InAppBrowserModule.KEY_SECONDARY_TOOLBAR_COLOR = "secondaryToolbarColor"; | ||
InAppBrowserModule.KEY_NAVIGATION_BAR_COLOR = "navigationBarColor"; | ||
InAppBrowserModule.KEY_NAVIGATION_BAR_DIVIDER_COLOR = "navigationBarDividerColor"; | ||
InAppBrowserModule.KEY_ENABLE_URL_BAR_HIDING = "enableUrlBarHiding"; | ||
InAppBrowserModule.KEY_SHOW_PAGE_TITLE = "showTitle"; | ||
InAppBrowserModule.KEY_DEFAULT_SHARE_MENU_ITEM = "enableDefaultShare"; | ||
InAppBrowserModule.KEY_FORCE_CLOSE_ON_REDIRECTION = "forceCloseOnRedirection"; | ||
InAppBrowserModule.KEY_ANIMATIONS = "animations"; | ||
InAppBrowserModule.KEY_HEADERS = "headers"; | ||
InAppBrowserModule.KEY_ANIMATION_START_ENTER = "startEnter"; | ||
InAppBrowserModule.KEY_ANIMATION_START_EXIT = "startExit"; | ||
InAppBrowserModule.KEY_ANIMATION_END_ENTER = "endEnter"; | ||
InAppBrowserModule.KEY_ANIMATION_END_EXIT = "endExit"; | ||
InAppBrowserModule.KEY_HAS_BACK_BUTTON = "hasBackButton"; | ||
InAppBrowserModule.KEY_BROWSER_PACKAGE = "browserPackage"; | ||
InAppBrowserModule.KEY_SHOW_IN_RECENTS = "showInRecents"; | ||
InAppBrowserModule.KEY_INCLUDE_REFERRER = "includeReferrer"; | ||
return InAppBrowserModule; | ||
@@ -278,3 +325,3 @@ }(java.lang.Object)); | ||
} | ||
if (typeof InAppBrowserModuleInstance === 'undefined') { | ||
if (typeof InAppBrowserModuleInstance === "undefined") { | ||
InAppBrowserModuleInstance = setup(); | ||
@@ -281,0 +328,0 @@ } |
import { Color } from "@nativescript/core"; | ||
export interface RedirectEvent { | ||
url: 'string'; | ||
url: "string"; | ||
} | ||
export interface BrowserResult { | ||
type: 'cancel' | 'dismiss'; | ||
type: "cancel" | "dismiss"; | ||
message?: string; | ||
} | ||
export interface RedirectResult { | ||
type: 'success'; | ||
type: "success"; | ||
url: string; | ||
} | ||
declare type InAppBrowseriOSOptions = { | ||
dismissButtonStyle?: 'done' | 'close' | 'cancel'; | ||
dismissButtonStyle?: "done" | "close" | "cancel"; | ||
preferredBarTintColor?: string | Color; | ||
@@ -19,7 +19,11 @@ preferredControlTintColor?: string | Color; | ||
animated?: boolean; | ||
modalPresentationStyle?: 'automatic' | 'fullScreen' | 'pageSheet' | 'formSheet' | 'currentContext' | 'custom' | 'overFullScreen' | 'overCurrentContext' | 'popover' | 'none'; | ||
modalTransitionStyle?: 'coverVertical' | 'flipHorizontal' | 'crossDissolve' | 'partialCurl'; | ||
modalPresentationStyle?: "automatic" | "fullScreen" | "pageSheet" | "formSheet" | "currentContext" | "custom" | "overFullScreen" | "overCurrentContext" | "popover" | "none"; | ||
modalTransitionStyle?: "coverVertical" | "flipHorizontal" | "crossDissolve" | "partialCurl"; | ||
modalEnabled?: boolean; | ||
enableBarCollapsing?: boolean; | ||
ephemeralWebSession?: boolean; | ||
formSheetPreferredContentSize?: { | ||
width: number; | ||
height: number; | ||
}; | ||
}; | ||
@@ -48,2 +52,3 @@ export declare type Animations = { | ||
showInRecents?: boolean; | ||
includeReferrer?: boolean; | ||
}; | ||
@@ -59,2 +64,5 @@ export declare type InAppBrowserOptions = InAppBrowserAndroidOptions & InAppBrowseriOSOptions; | ||
isAvailable: () => Promise<boolean>; | ||
onStart(): void; | ||
warmup: () => boolean; | ||
mayLaunchUrl: (mostLikelyUrl: string, otherUrls: Array<string>) => void; | ||
} | ||
@@ -61,0 +69,0 @@ export declare type RedirectResolve = (value?: AuthSessionResult | PromiseLike<AuthSessionResult>) => void; |
@@ -1,2 +0,2 @@ | ||
export const InAppBrowserErrorMessage = 'Another InAppBrowser is already being presented.'; | ||
export const InAppBrowserErrorMessage = "Another InAppBrowser is already being presented."; | ||
export var BROWSER_TYPES; | ||
@@ -17,3 +17,3 @@ (function (BROWSER_TYPES) { | ||
modalEnabled: true, | ||
dismissButtonStyle: 'close', | ||
dismissButtonStyle: "close", | ||
readerMode: false, | ||
@@ -20,0 +20,0 @@ enableBarCollapsing: false, |
@@ -1,2 +0,2 @@ | ||
import { InAppBrowserClassMethods } from './InAppBrowser.common'; | ||
import { InAppBrowserClassMethods } from "./InAppBrowser.common"; | ||
export declare const InAppBrowser: InAppBrowserClassMethods; |
@@ -1,13 +0,12 @@ | ||
import { Utils } from '@nativescript/core'; | ||
import { parseColor, log } from './utils.common'; | ||
import { getDefaultOptions, BROWSER_TYPES, DISMISS_BUTTON_STYLES, InAppBrowserErrorMessage, } from './InAppBrowser.common'; | ||
import { getTransitionStyle, getPresentationStyle, setModalInPresentation, dismissWithoutAnimation, InAppBrowserOpenAuthErrorMessage, } from './utils.ios'; | ||
import { Utils } from "@nativescript/core"; | ||
import { parseColor, log } from "./utils.common"; | ||
import { getDefaultOptions, BROWSER_TYPES, DISMISS_BUTTON_STYLES, InAppBrowserErrorMessage, } from "./InAppBrowser.common"; | ||
import { getTransitionStyle, getPresentationStyle, setModalInPresentation, dismissWithoutAnimation, InAppBrowserOpenAuthErrorMessage, getWindow, } from "./utils.ios"; | ||
const DEFAULT_PROTOCOLS = [ | ||
SFSafariViewControllerDelegate, | ||
UIAdaptivePresentationControllerDelegate | ||
UIAdaptivePresentationControllerDelegate, | ||
]; | ||
const protocols = Utils.ios.MajorVersion >= 13 ? [ | ||
...DEFAULT_PROTOCOLS, | ||
ASWebAuthenticationPresentationContextProviding | ||
] : DEFAULT_PROTOCOLS; | ||
const protocols = Utils.ios.MajorVersion >= 13 | ||
? [...DEFAULT_PROTOCOLS, ASWebAuthenticationPresentationContextProviding] | ||
: DEFAULT_PROTOCOLS; | ||
let InAppBrowserModuleInstance; | ||
@@ -43,15 +42,17 @@ function setup() { | ||
return; | ||
var inAppBrowserOptions = getDefaultOptions(authURL, options); | ||
_this.animated = inAppBrowserOptions.animated; | ||
var _a = getDefaultOptions(authURL, options), url = _a.url, animated = _a.animated, enableBarCollapsing = _a.enableBarCollapsing, readerMode = _a.readerMode, dismissButtonStyle = _a.dismissButtonStyle, preferredBarTintColor = _a.preferredBarTintColor, preferredControlTintColor = _a.preferredControlTintColor, modalEnabled = _a.modalEnabled, modalPresentationStyle = _a.modalPresentationStyle, modalTransitionStyle = _a.modalTransitionStyle, formSheetPreferredContentSize = _a.formSheetPreferredContentSize; | ||
_this.animated = animated; | ||
try { | ||
// Safari View Controller to authorize request | ||
var url = NSURL.URLWithString(inAppBrowserOptions.url); | ||
var authURL_1 = NSURL.URLWithString(url); | ||
if (Utils.ios.MajorVersion >= 11) { | ||
var config = SFSafariViewControllerConfiguration.alloc().init(); | ||
config.barCollapsingEnabled = inAppBrowserOptions.enableBarCollapsing; | ||
config.entersReaderIfAvailable = inAppBrowserOptions.readerMode; | ||
_this.safariVC = SFSafariViewController.alloc().initWithURLConfiguration(url, config); | ||
config.barCollapsingEnabled = enableBarCollapsing; | ||
config.entersReaderIfAvailable = readerMode; | ||
_this.safariVC = | ||
SFSafariViewController.alloc().initWithURLConfiguration(authURL_1, config); | ||
} | ||
else { | ||
_this.safariVC = SFSafariViewController.alloc().initWithURLEntersReaderIfAvailable(url, inAppBrowserOptions.readerMode); | ||
_this.safariVC = | ||
SFSafariViewController.alloc().initWithURLEntersReaderIfAvailable(authURL_1, readerMode); | ||
} | ||
@@ -62,3 +63,3 @@ } | ||
_this.flowDidFinish(); | ||
log("InAppBrowser: " + error); | ||
log("InAppBrowser: ".concat(error)); | ||
return; | ||
@@ -68,15 +69,18 @@ } | ||
if (Utils.ios.MajorVersion >= 11) { | ||
if (inAppBrowserOptions.dismissButtonStyle === DISMISS_BUTTON_STYLES.DONE) { | ||
_this.safariVC.dismissButtonStyle = SFSafariViewControllerDismissButtonStyle.Done; | ||
if (dismissButtonStyle === DISMISS_BUTTON_STYLES.DONE) { | ||
_this.safariVC.dismissButtonStyle = | ||
SFSafariViewControllerDismissButtonStyle.Done; | ||
} | ||
else if (inAppBrowserOptions.dismissButtonStyle === DISMISS_BUTTON_STYLES.CLOSE) { | ||
_this.safariVC.dismissButtonStyle = SFSafariViewControllerDismissButtonStyle.Close; | ||
else if (dismissButtonStyle === DISMISS_BUTTON_STYLES.CLOSE) { | ||
_this.safariVC.dismissButtonStyle = | ||
SFSafariViewControllerDismissButtonStyle.Close; | ||
} | ||
else if (inAppBrowserOptions.dismissButtonStyle === DISMISS_BUTTON_STYLES.CANCEL) { | ||
_this.safariVC.dismissButtonStyle = SFSafariViewControllerDismissButtonStyle.Cancel; | ||
else if (dismissButtonStyle === DISMISS_BUTTON_STYLES.CANCEL) { | ||
_this.safariVC.dismissButtonStyle = | ||
SFSafariViewControllerDismissButtonStyle.Cancel; | ||
} | ||
} | ||
if (Utils.ios.MajorVersion >= 10) { | ||
if (inAppBrowserOptions.preferredBarTintColor) { | ||
var color = parseColor(inAppBrowserOptions.preferredBarTintColor); | ||
if (preferredBarTintColor) { | ||
var color = parseColor(preferredBarTintColor); | ||
if (color) { | ||
@@ -86,4 +90,4 @@ _this.safariVC.preferredBarTintColor = color.ios; | ||
} | ||
if (inAppBrowserOptions.preferredControlTintColor) { | ||
var color = parseColor(inAppBrowserOptions.preferredControlTintColor); | ||
if (preferredControlTintColor) { | ||
var color = parseColor(preferredControlTintColor); | ||
if (color) { | ||
@@ -94,4 +98,5 @@ _this.safariVC.preferredControlTintColor = color.ios; | ||
} | ||
var ctrl = UIApplication.sharedApplication.keyWindow.rootViewController; | ||
if (inAppBrowserOptions.modalEnabled) { | ||
var window = getWindow(); | ||
var ctrl = window.rootViewController; | ||
if (modalEnabled) { | ||
// This is a hack to present the SafariViewController modally | ||
@@ -102,7 +107,18 @@ var safariHackVC = UINavigationController.alloc().initWithRootViewController(_this.safariVC); | ||
// is not called. | ||
_this.safariVC.modalPresentationStyle = UIModalPresentationStyle.OverFullScreen; | ||
safariHackVC.modalPresentationStyle = getPresentationStyle(inAppBrowserOptions.modalPresentationStyle); | ||
_this.safariVC.modalPresentationStyle = | ||
UIModalPresentationStyle.OverFullScreen; | ||
safariHackVC.modalPresentationStyle = getPresentationStyle(modalPresentationStyle); | ||
if (_this.animated) { | ||
safariHackVC.modalTransitionStyle = getTransitionStyle(inAppBrowserOptions.modalTransitionStyle); | ||
safariHackVC.modalTransitionStyle = | ||
getTransitionStyle(modalTransitionStyle); | ||
} | ||
if (safariHackVC.modalPresentationStyle === | ||
UIModalPresentationStyle.FormSheet && | ||
formSheetPreferredContentSize) { | ||
var width = formSheetPreferredContentSize.width; | ||
var height = formSheetPreferredContentSize.height; | ||
if (width && height) { | ||
safariHackVC.preferredContentSize = CGSizeMake(width, height); | ||
} | ||
} | ||
if (Utils.ios.MajorVersion >= 13) { | ||
@@ -114,6 +130,6 @@ safariHackVC.modalInPresentation = true; | ||
safariHackVC.presentationController.delegate = _this; | ||
ctrl.presentViewControllerAnimatedCompletion(safariHackVC, inAppBrowserOptions.animated, null); | ||
ctrl.presentViewControllerAnimatedCompletion(safariHackVC, animated, null); | ||
} | ||
else { | ||
ctrl.presentViewControllerAnimatedCompletion(_this.safariVC, inAppBrowserOptions.animated, null); | ||
ctrl.presentViewControllerAnimatedCompletion(_this.safariVC, animated, null); | ||
} | ||
@@ -124,7 +140,8 @@ }); | ||
var _this = this; | ||
var ctrl = UIApplication.sharedApplication.keyWindow.rootViewController; | ||
var window = getWindow(); | ||
var ctrl = window.rootViewController; | ||
ctrl.dismissViewControllerAnimatedCompletion(this.animated, function () { | ||
if (_this.redirectResolve) { | ||
_this.redirectResolve({ | ||
type: 'dismiss' | ||
type: "dismiss", | ||
}); | ||
@@ -136,8 +153,7 @@ _this.flowDidFinish(); | ||
InAppBrowserModule.prototype.openAuth = function (authUrl, redirectUrl, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, Promise, function () { | ||
var inAppBrowserOptions, response; | ||
var ephemeralWebSession, response; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
inAppBrowserOptions = __assign(__assign({}, options), { ephemeralWebSession: options.ephemeralWebSession !== undefined ? options.ephemeralWebSession : false }); | ||
ephemeralWebSession = !!(options === null || options === void 0 ? void 0 : options.ephemeralWebSession); | ||
if (Utils.ios.MajorVersion >= 11) { | ||
@@ -148,4 +164,11 @@ return [2 /*return*/, new Promise(function (resolve, reject) { | ||
var url = NSURL.URLWithString(authUrl); | ||
var escapedRedirectURL = NSURL.URLWithString(redirectUrl).scheme; | ||
_this.authSession = (Utils.ios.MajorVersion >= 12 ? ASWebAuthenticationSession : SFAuthenticationSession).alloc().initWithURLCallbackURLSchemeCompletionHandler(url, escapedRedirectURL, function (callbackURL, error) { | ||
var escapedRedirectURL = null; | ||
if (redirectUrl) { | ||
escapedRedirectURL = NSURL.URLWithString(redirectUrl).scheme; | ||
} | ||
_this.authSession = (Utils.ios.MajorVersion >= 12 | ||
? ASWebAuthenticationSession | ||
: SFAuthenticationSession) | ||
.alloc() | ||
.initWithURLCallbackURLSchemeCompletionHandler(url, escapedRedirectURL, function (callbackURL, error) { | ||
if (_this.redirectResolve) { | ||
@@ -155,3 +178,3 @@ if (!error) { | ||
type: BROWSER_TYPES.SUCCESS, | ||
url: callbackURL.absoluteString | ||
url: callbackURL.absoluteString, | ||
}); | ||
@@ -161,3 +184,3 @@ } | ||
_this.redirectResolve({ | ||
type: BROWSER_TYPES.CANCEL | ||
type: BROWSER_TYPES.CANCEL, | ||
}); | ||
@@ -169,5 +192,7 @@ } | ||
if (Utils.ios.MajorVersion >= 13) { | ||
var webAuthSession = _this.authSession; | ||
var webAuthSession = _this | ||
.authSession; | ||
// Prevent re-use cookie from last auth session | ||
webAuthSession.prefersEphemeralWebBrowserSession = inAppBrowserOptions.ephemeralWebSession; | ||
webAuthSession.prefersEphemeralWebBrowserSession = | ||
ephemeralWebSession; | ||
webAuthSession.presentationContextProvider = _this; | ||
@@ -182,3 +207,3 @@ } | ||
type: BROWSER_TYPES.CANCEL, | ||
message: InAppBrowserOpenAuthErrorMessage | ||
message: InAppBrowserOpenAuthErrorMessage, | ||
}; | ||
@@ -197,3 +222,3 @@ return [2 /*return*/, Promise.resolve(response)]; | ||
this.redirectResolve({ | ||
type: BROWSER_TYPES.DISMISS | ||
type: BROWSER_TYPES.DISMISS, | ||
}); | ||
@@ -208,3 +233,3 @@ this.flowDidFinish(); | ||
InAppBrowserModule.prototype.presentationAnchorForWebAuthenticationSession = function (_) { | ||
return UIApplication.sharedApplication.keyWindow; | ||
return getWindow(); | ||
}; | ||
@@ -214,3 +239,3 @@ InAppBrowserModule.prototype.safariViewControllerDidFinish = function (controller) { | ||
this.redirectResolve({ | ||
type: BROWSER_TYPES.CANCEL | ||
type: BROWSER_TYPES.CANCEL, | ||
}); | ||
@@ -228,2 +253,9 @@ } | ||
}; | ||
InAppBrowserModule.prototype.onStart = function () { }; | ||
InAppBrowserModule.prototype.warmup = function () { | ||
return false; | ||
}; | ||
InAppBrowserModule.prototype.mayLaunchUrl = function (url, otherUrls) { | ||
log("mayLaunchUrl is not supported on iOS. url: ".concat(url, ", otherUrls: ").concat(otherUrls)); | ||
}; | ||
InAppBrowserModule.ObjCProtocols = protocols; | ||
@@ -234,6 +266,6 @@ return InAppBrowserModule; | ||
} | ||
if (typeof InAppBrowserModuleInstance === 'undefined') { | ||
if (typeof InAppBrowserModuleInstance === "undefined") { | ||
InAppBrowserModuleInstance = setup(); | ||
} | ||
export const InAppBrowser = InAppBrowserModuleInstance; | ||
export const InAppBrowser = (InAppBrowserModuleInstance); | ||
//# sourceMappingURL=InAppBrowser.ios.js.map |
{ | ||
"name": "nativescript-inappbrowser", | ||
"version": "3.1.2", | ||
"version": "3.2.0", | ||
"description": "InAppBrowser for NativeScript", | ||
@@ -18,15 +18,12 @@ "main": "InAppBrowser", | ||
"scripts": { | ||
"setup": "npm i && ts-patch install", | ||
"tsc": "npm i && ts-patch install && tsc", | ||
"build": "npm run tsc && npm run build.native", | ||
"build.native": "node scripts/build-native.js", | ||
"test.android": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build android && tns test android --justlaunch", | ||
"test.ios": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build ios && tns test ios --justlaunch", | ||
"setup": "ts-patch install", | ||
"tsc": "ts-patch install && tsc", | ||
"test.android": "npm run tsc && npm run tslint && ns --path ../demo build android && ns --path ../demo test android --justlaunch", | ||
"test.ios": "npm run tsc && npm run tslint && ns --path ../demo build ios && ns --path ../demo test ios --justlaunch", | ||
"tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\"", | ||
"ci.tslint": "npm i && tslint '**/*.ts' --config '../tslint.json' --exclude '**/node_modules/**' --exclude '**/platforms/**'", | ||
"prepack": "npm run build.native", | ||
"demo.ios": "npm i && cd ../demo && tns run ios --inspector", | ||
"demo.android": "npm i && cd ../demo && tns run android", | ||
"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", | ||
"ci.tslint": "tslint '**/*.ts' --config '../tslint.json' --exclude '**/node_modules/**' --exclude '**/platforms/**'", | ||
"demo.ios": "ns --path ../demo debug ios", | ||
"demo.android": "ns --path ../demo debug android", | ||
"demo.reset": "ns --path ../demo clean", | ||
"plugin.prepare": "ns --path ../demo plugin remove nativescript-inappbrowser && ns --path ../demo plugin add .", | ||
"clean": "npm run demo.reset && npx rimraf node_modules package-lock.json && npm i" | ||
@@ -62,14 +59,16 @@ }, | ||
"devDependencies": { | ||
"@nativescript/core": "~7.0.0", | ||
"@nativescript/types": "~7.0.0", | ||
"@nativescript/webpack": "~3.0.0", | ||
"typescript": "~3.9.0", | ||
"prompt": "^1.0.0", | ||
"@nativescript/core": "~8.3.1", | ||
"@nativescript/types": "~8.3.1", | ||
"@nativescript/webpack": "~5.0.8", | ||
"@nativescript/types-ios": "~8.3.1", | ||
"@nativescript/types-android": "~8.3.1", | ||
"typescript": "~4.7.3", | ||
"prompt": "^1.2.0", | ||
"rimraf": "^3.0.2", | ||
"tslint": "^6.1.1", | ||
"ts-node": "^9.0.0", | ||
"ts-patch": "^1.3.0", | ||
"semver": "^7.2.1" | ||
"tslint": "^6.1.3", | ||
"ts-node": "^10.4.0", | ||
"ts-patch": "^1.4.5", | ||
"semver": "^7.3.5" | ||
}, | ||
"bootstrapper": "nativescript-plugin-seed" | ||
} |
@@ -50,3 +50,3 @@ <p align="center"> | ||
```javascript | ||
tns plugin add nativescript-inappbrowser | ||
ns plugin add nativescript-inappbrowser | ||
``` | ||
@@ -96,2 +96,5 @@ | ||
`isAvailable` | Detect if the device supports this plugin. | ||
`onStart` | Initialize a bound background service so the application can communicate its intention to the browser. After the service is connected, the client can be used to Warms up the browser to make navigation faster and indicates that a given URL may be loaded in the future. - Android Only. | ||
`warmup` | Warm up the browser process - Android Only. | ||
`mayLaunchUrl` | Tells the browser of a likely future navigation to a URL. The most likely URL has to be specified first. Optionally, a list of other likely URLs can be provided. They are treated as less likely than the first one, and have to be sorted in decreasing priority order. These additional URLs may be ignored. All previous calls to this method will be deprioritized - Android Only. | ||
@@ -112,2 +115,3 @@ ### iOS Options | ||
`ephemeralWebSession` (Boolean) | Prevent re-use cookies of previous session (openAuth only) [`true`/`false`] | ||
`formSheetPreferredContentSize` (Object) | Custom size for iPad `formSheet` modals [`{width: 400, height: 500}`] | ||
@@ -130,2 +134,3 @@ ### Android Options | ||
`showInRecents` (Boolean) | Determining whether browsed website should be shown as separate entry in Android recents/multitasking view. [`true`/`false`] | ||
`includeReferrer` (Boolean) | Determining whether to include your package name as referrer for the website to track. [`true`/`false`] | ||
@@ -199,2 +204,32 @@ ### Demo | ||
### Android Optimizations | ||
On Android, you can warmup the in app browser client to make it launch siginificantly faster. To do so, add the following to your [Custom Android Activity](https://docs.nativescript.org/advanced-concepts.html#extending-android-activity). | ||
```ts | ||
import { InAppBrowser } from "nativescript-inappbrowser"; | ||
@NativeClass() | ||
@JavaProxy("org.nativescript.demo.MainActivity") | ||
export class Activity extends androidx.appcompat.app.AppCompatActivity { | ||
public onStart(): void { | ||
// InAppBrowser initialization for CustomTabsServiceConnection | ||
InAppBrowser.onStart(); | ||
} | ||
} | ||
``` | ||
You can further optimize performance and pre-render pages [by providing the urls that the user is likely to open](https://developer.chrome.com/docs/android/custom-tabs/best-practices/#pre-render-content). | ||
```ts | ||
constructor() { | ||
super(); | ||
// Do not call this every time the component render | ||
InAppBrowser.mayLaunchUrl(this._url, [ | ||
"https://twitter.com/NativeScript", | ||
"https://github.com/NativeScript/NativeScript", | ||
"https://openjsf.org" | ||
]); | ||
} | ||
``` | ||
### Authentication Flow using Deep Linking | ||
@@ -201,0 +236,0 @@ |
@@ -1,4 +0,4 @@ | ||
/// <reference path="./node_modules/@nativescript/types/index.d.ts" /> | ||
/// <reference path="./node_modules/@nativescript/types-ios/complete.d.ts" /> | ||
/// <reference path="./node_modules/@nativescript/types-android/lib/android-29.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 CustomTabsCallback extends java.lang.Object {} | ||
export class CustomTabsSession extends java.lang.Object { | ||
mayLaunchUrl( | ||
url: android.net.Uri, | ||
extras: android.os.Bundle, | ||
otherLikelyBundles: java.util.List<android.os.Bundle> | ||
): boolean; | ||
} | ||
export class CustomTabsIntent { | ||
export class CustomTabsClient extends java.lang.Object { | ||
static getPackageName( | ||
context: android.content.Context, | ||
packages: java.util.List<string> | ||
): string; | ||
static bindCustomTabsService( | ||
context: android.content.Context, | ||
packageName: string, | ||
connection: CustomTabsServiceConnection | ||
): CustomTabsClient; | ||
warmup(flags: java.lang.Long): boolean; | ||
newSession(callback: CustomTabsCallback): CustomTabsSession; | ||
} | ||
export class CustomTabsIntent extends java.lang.Object { | ||
launchUrl(context: android.content.Context, url: android.net.Uri): void; | ||
@@ -16,5 +34,4 @@ intent: android.content.Intent; | ||
namespace CustomTabsIntent { | ||
export class Builder { | ||
constructor(); | ||
build(): android.support.customtabs.CustomTabsIntent; | ||
export class Builder extends java.lang.Object { | ||
build(): CustomTabsIntent; | ||
setShowTitle(showTitle: boolean): this; | ||
@@ -27,7 +44,25 @@ setToolbarColor(color: number): this; | ||
enableUrlBarHiding(): this; | ||
setStartAnimations(context: android.content.Context, enterResId: number, exitResId: number): this; | ||
setExitAnimations(context: android.content.Context, enterResId: number, exitResId: number): this; | ||
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; | ||
} | ||
} | ||
export class CustomTabsService extends android.app.Service { | ||
static KEY_URL: string; | ||
} | ||
export class CustomTabsServiceConnection extends android.content | ||
.ServiceConnection { | ||
onCustomTabsServiceConnected( | ||
name: android.content.ComponentName, | ||
client: CustomTabsClient | ||
): void; | ||
} | ||
} | ||
@@ -40,6 +75,24 @@ } | ||
export namespace customtabs { | ||
export class CustomTabsClient { | ||
static getPackageName(context: android.content.Context, list: java.util.List): string; | ||
export class CustomTabsCallback extends java.lang.Object {} | ||
export class CustomTabsSession extends java.lang.Object { | ||
mayLaunchUrl( | ||
url: android.net.Uri, | ||
extras: android.os.Bundle, | ||
otherLikelyBundles: java.util.List<android.os.Bundle> | ||
): boolean; | ||
} | ||
export class CustomTabsIntent { | ||
export class CustomTabsClient extends java.lang.Object { | ||
static getPackageName( | ||
context: android.content.Context, | ||
packages: java.util.List<string> | ||
): string; | ||
static bindCustomTabsService( | ||
context: android.content.Context, | ||
packageName: string, | ||
connection: CustomTabsServiceConnection | ||
): void; | ||
warmup(flags: java.lang.Long): boolean; | ||
newSession(callback: CustomTabsCallback): CustomTabsSession; | ||
} | ||
export class CustomTabsIntent extends java.lang.Object { | ||
launchUrl(context: android.content.Context, url: android.net.Uri): void; | ||
@@ -53,5 +106,4 @@ intent: android.content.Intent; | ||
namespace CustomTabsIntent { | ||
export class Builder { | ||
constructor(); | ||
build(): android.support.customtabs.CustomTabsIntent; | ||
export class Builder extends java.lang.Object { | ||
build(): CustomTabsIntent; | ||
setShowTitle(showTitle: boolean): this; | ||
@@ -64,9 +116,27 @@ setToolbarColor(color: number): this; | ||
enableUrlBarHiding(): this; | ||
setStartAnimations(context: android.content.Context, enterResId: number, exitResId: number): this; | ||
setExitAnimations(context: android.content.Context, enterResId: number, exitResId: number): this; | ||
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; | ||
} | ||
} | ||
export class CustomTabsService extends android.app.Service { | ||
static KEY_URL: string; | ||
} | ||
export class CustomTabsServiceConnection extends android.content | ||
.ServiceConnection { | ||
onCustomTabsServiceConnected( | ||
name: android.content.ComponentName, | ||
client: CustomTabsClient | ||
): void; | ||
} | ||
} | ||
} | ||
} | ||
} |
@@ -5,6 +5,10 @@ import Activity = android.app.Activity; | ||
import List = java.util.List; | ||
import { OpenBrowserAsync, AuthSessionResult, InAppBrowserOptions } from './InAppBrowser.common'; | ||
import { AuthSessionResult, BrowserResult } from "./InAppBrowser.common"; | ||
export declare function useAndroidX(): typeof androidx.browser; | ||
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 CustomTabsServiceConnection: typeof androidx.browser.customtabs.CustomTabsServiceConnection; | ||
export declare const CustomTabsService: typeof androidx.browser.customtabs.CustomTabsService; | ||
export declare const CustomTabsCallback: typeof androidx.browser.customtabs.CustomTabsCallback; | ||
export declare const ColorUtils: typeof androidx.core.graphics.ColorUtils; | ||
@@ -20,5 +24,4 @@ export declare const CHROME_PACKAGE_STABLE = "com.android.chrome"; | ||
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(open: OpenBrowserAsync, startUrl: string, returnUrl: string, options?: InAppBrowserOptions): Promise<AuthSessionResult>; | ||
export declare function openAuthSessionPolyfillAsync(open: () => Promise<BrowserResult>, returnUrl: string): Promise<AuthSessionResult>; | ||
export declare function closeAuthSessionPolyfillAsync(): void; | ||
@@ -25,0 +28,0 @@ export declare function getPreferredPackages(context: Context): List<ResolveInfo>; |
var Intent = android.content.Intent; | ||
var NfcAdapter = android.nfc.NfcAdapter; | ||
var Arrays = java.util.Arrays; | ||
import { Utils, Application, AndroidApplication } from '@nativescript/core'; | ||
import { BROWSER_TYPES } from './InAppBrowser.common'; | ||
import { AndroidApplication, Application, Utils, } from "@nativescript/core"; | ||
import { BROWSER_TYPES, } from "./InAppBrowser.common"; | ||
export function useAndroidX() { | ||
return global.androidx && global.androidx.browser; | ||
} | ||
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 CustomTabsServiceConnection = (useAndroidX() ? androidx.browser : android.support).customtabs.CustomTabsServiceConnection; | ||
export const CustomTabsService = (useAndroidX() ? androidx.browser : android.support).customtabs.CustomTabsService; | ||
export const CustomTabsCallback = (useAndroidX() ? androidx.browser : android.support).customtabs.CustomTabsCallback; | ||
export const ColorUtils = (useAndroidX() ? androidx.core.graphics : android.support.v4.graphics).ColorUtils; | ||
export const CHROME_PACKAGE_STABLE = "com.android.chrome"; | ||
@@ -16,11 +20,8 @@ export const CHROME_PACKAGE_BETA = "com.chrome.beta"; | ||
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'; | ||
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 = ''; | ||
let initialUrl = ""; | ||
export const getDrawableId = Utils.ad.resources.getDrawableId; | ||
export function useAndroidX() { | ||
return global.androidx && global.androidx.browser; | ||
} | ||
export function getInitialURL(activity) { | ||
@@ -31,5 +32,6 @@ if (activity) { | ||
const uri = intent.getData(); | ||
if (uri !== null && (Intent.ACTION_VIEW === action || | ||
NfcAdapter.ACTION_NDEF_DISCOVERED === action)) { | ||
const url = '' + uri; | ||
if (uri !== null && | ||
(Intent.ACTION_VIEW === action || | ||
NfcAdapter.ACTION_NDEF_DISCOVERED === action)) { | ||
const url = "" + uri; | ||
if (url === initialUrl) | ||
@@ -44,3 +46,3 @@ return null; | ||
function waitForRedirectAsync(returnUrl) { | ||
return new Promise(resolve => { | ||
return new Promise((resolve) => { | ||
_redirectHandler = (args) => { | ||
@@ -57,9 +59,9 @@ const url = getInitialURL(args.android); | ||
return new Promise(function (resolve) { | ||
if (!Application.android.paused) { | ||
const activity = Application.android.foregroundActivity || Application.android.startActivity; | ||
return resolve(activity); | ||
if (!Application.android.paused && Application.android.foregroundActivity) { | ||
resolve(Application.android.foregroundActivity); | ||
} | ||
Application.android.once(AndroidApplication.activityResumedEvent, function (args) { | ||
function handleAppStateChange(args) { | ||
resolve(args.activity); | ||
}); | ||
} | ||
Application.android.once(AndroidApplication.activityResumedEvent, handleAppStateChange); | ||
}); | ||
@@ -82,8 +84,8 @@ } | ||
} | ||
export function openAuthSessionPolyfillAsync(open, startUrl, returnUrl, options) { | ||
return Promise.race([ | ||
export async function openAuthSessionPolyfillAsync(open, returnUrl) { | ||
return await Promise.race([ | ||
open().then(function (result) { | ||
return checkResultAndReturnUrl(returnUrl, result); | ||
}), | ||
waitForRedirectAsync(returnUrl), | ||
open(startUrl, options).then(function (result) { | ||
return checkResultAndReturnUrl(returnUrl, result); | ||
}) | ||
]); | ||
@@ -99,3 +101,5 @@ } | ||
const serviceIntent = new Intent(ACTION_CUSTOM_TABS_CONNECTION); | ||
const resolveInfos = context.getPackageManager().queryIntentServices(serviceIntent, 0); | ||
const resolveInfos = context | ||
.getPackageManager() | ||
.queryIntentServices(serviceIntent, 0); | ||
return resolveInfos; | ||
@@ -112,3 +116,3 @@ } | ||
CHROME_PACKAGE_DEV, | ||
LOCAL_PACKAGE | ||
LOCAL_PACKAGE, | ||
])); | ||
@@ -115,0 +119,0 @@ if (packageName == null && resolveInfos != null && resolveInfos.size() > 0) { |
@@ -1,2 +0,2 @@ | ||
import { Color } from "@nativescript/core"; | ||
import { Application, Color } from "@nativescript/core"; | ||
export function parseColor(color) { | ||
@@ -21,4 +21,7 @@ if (color && !(color instanceof Color)) { | ||
} | ||
if (Application.android) { | ||
android.util.Log.d("JS", message); | ||
} | ||
console.log(message, ...optionalParams); | ||
} | ||
//# sourceMappingURL=utils.common.js.map |
@@ -5,2 +5,3 @@ export declare const setModalInPresentation = "setModalInPresentation"; | ||
export declare function getTransitionStyle(styleKey: string): UIModalTransitionStyle; | ||
export declare function getWindow(): UIWindow; | ||
export declare function dismissWithoutAnimation(controller: SFSafariViewController): void; |
@@ -1,2 +0,2 @@ | ||
import { Utils } from '@nativescript/core'; | ||
import { Utils } from "@nativescript/core"; | ||
const presentationStyles = { | ||
@@ -11,6 +11,7 @@ none: -1, | ||
overCurrentContext: 6, | ||
popover: 7 | ||
popover: 7, | ||
}; | ||
const defaultModalPresentationStyle = Utils.ios.MajorVersion >= 13 ? | ||
-2 : 0; | ||
const defaultModalPresentationStyle = Utils.ios.MajorVersion >= 13 | ||
? -2 | ||
: 0; | ||
const transitionStyles = { | ||
@@ -20,7 +21,7 @@ coverVertical: 0, | ||
crossDissolve: 2, | ||
partialCurl: 3 | ||
partialCurl: 3, | ||
}; | ||
const animationKey = 'dismissInAppBrowser'; | ||
export const setModalInPresentation = 'setModalInPresentation'; | ||
export const InAppBrowserOpenAuthErrorMessage = 'openAuth requires iOS 11 or greater'; | ||
const animationKey = "dismissInAppBrowser"; | ||
export const setModalInPresentation = "setModalInPresentation"; | ||
export const InAppBrowserOpenAuthErrorMessage = "openAuth requires iOS 11 or greater"; | ||
export function getPresentationStyle(styleKey) { | ||
@@ -32,4 +33,13 @@ return presentationStyles[styleKey] !== undefined | ||
export function getTransitionStyle(styleKey) { | ||
return transitionStyles[styleKey] !== undefined ? transitionStyles[styleKey] : 0; | ||
return transitionStyles[styleKey] !== undefined | ||
? transitionStyles[styleKey] | ||
: 0; | ||
} | ||
export function getWindow() { | ||
const sharedApplication = UIApplication.sharedApplication; | ||
if (sharedApplication.windows.count > 0 && sharedApplication.windows[0]) { | ||
return sharedApplication.windows[0]; | ||
} | ||
return sharedApplication.keyWindow; | ||
} | ||
export function dismissWithoutAnimation(controller) { | ||
@@ -43,3 +53,4 @@ const transition = CATransition.animation(); | ||
controller.view.frame = CGRectMake(0.0, 0.0, 0.5, 0.5); | ||
const ctrl = UIApplication.sharedApplication.keyWindow.rootViewController; | ||
const window = getWindow(); | ||
const ctrl = window.rootViewController; | ||
ctrl.view.layer.addAnimationForKey(transition, animationKey); | ||
@@ -46,0 +57,0 @@ ctrl.dismissViewControllerAnimatedCompletion(false, () => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
92312
41
1282
391
12