nativescript-inappbrowser
Advanced tools
Comparing version 1.0.2 to 2.0.0
@@ -9,3 +9,2 @@ "use strict"; | ||
var AssertionError = java.lang.AssertionError; | ||
var CustomTabsIntent = android.support.customtabs.CustomTabsIntent; | ||
var color_1 = require("tns-core-modules/color"); | ||
@@ -16,2 +15,6 @@ var utils_1 = require("tns-core-modules/utils/utils"); | ||
var InAppBrowser_common_1 = require("./InAppBrowser.common"); | ||
var CustomTabsIntent = (useAndroidX() ? androidx.browser : android.support).customtabs.CustomTabsIntent; | ||
function useAndroidX() { | ||
return global.androidx && global.androidx.browser; | ||
} | ||
var InAppBrowserModule = (function (_super) { | ||
@@ -32,4 +35,6 @@ __extends(InAppBrowserModule, _super); | ||
this.flowDidFinish(); | ||
var response = { type: 'cancel' }; | ||
return Promise.resolve(response); | ||
var result = { | ||
type: 'cancel' | ||
}; | ||
return Promise.resolve(result); | ||
} | ||
@@ -85,2 +90,3 @@ this.currentActivity = application_1.android.foregroundActivity || application_1.android.startActivity; | ||
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); | ||
} | ||
@@ -112,4 +118,6 @@ var intent = customTabsIntent.intent; | ||
ChromeTabsManagerActivity_1.BROWSER_ACTIVITY_EVENTS.off('DismissedEvent'); | ||
var response = { type: 'dismiss' }; | ||
InAppBrowserModule.redirectResolve(response); | ||
var result = { | ||
type: 'dismiss' | ||
}; | ||
InAppBrowserModule.redirectResolve(result); | ||
this.flowDidFinish(); | ||
@@ -116,0 +124,0 @@ this.currentActivity.startActivity(ChromeTabsManagerActivity_1.createDismissIntent(this.currentActivity)); |
@@ -5,3 +5,3 @@ "use strict"; | ||
function getDefaultOptions(url, options) { | ||
return __assign({}, options, { url: url, dismissButtonStyle: options.dismissButtonStyle || 'close', readerMode: options.readerMode !== undefined ? options.readerMode : false }); | ||
return __assign({}, options, { url: url, dismissButtonStyle: options.dismissButtonStyle || 'close', readerMode: options.readerMode !== undefined ? options.readerMode : false, animated: options.animated !== undefined ? options.animated : true, modalEnabled: options.modalEnabled !== undefined ? options.modalEnabled : true }); | ||
} | ||
@@ -8,0 +8,0 @@ exports.getDefaultOptions = getDefaultOptions; |
@@ -6,2 +6,25 @@ "use strict"; | ||
var InAppBrowser_common_1 = require("./InAppBrowser.common"); | ||
var getPresentationStyle = function (styleKey) { | ||
var styles = { | ||
fullScreen: 0, | ||
pageSheet: 1, | ||
formSheet: 2, | ||
currentContext: 3, | ||
custom: 4, | ||
overFullScreen: 5, | ||
overCurrentContext: 6, | ||
popover: 7, | ||
none: -1 | ||
}; | ||
return styles[styleKey] || 5; | ||
}; | ||
var getTransitionStyle = function (styleKey) { | ||
var styles = { | ||
coverVertical: 0, | ||
flipHorizontal: 1, | ||
crossDissolve: 2, | ||
partialCurl: 3 | ||
}; | ||
return styles[styleKey] || 0; | ||
}; | ||
var InAppBrowser = NSObject.extend({ | ||
@@ -11,2 +34,3 @@ redirectResolve: null, | ||
authSession: null, | ||
animated: false, | ||
isAvailable: function () { | ||
@@ -22,3 +46,4 @@ return Promise.resolve(utils_1.ios.MajorVersion >= 9); | ||
var options = InAppBrowser_common_1.getDefaultOptions(url, inAppBrowserOptions); | ||
var safariVC = SFSafariViewController.alloc().initWithURLEntersReaderIfAvailable(NSURL.URLWithString(options.url), options.readerMode); | ||
self.animated = options.animated; | ||
var safariVC = SFSafariViewController.alloc().initWithURLEntersReaderIfAvailable(NSURL.URLWithString(options['url']), options.readerMode); | ||
safariVC.delegate = self; | ||
@@ -44,7 +69,15 @@ if (utils_1.ios.MajorVersion >= 11) { | ||
} | ||
safariVC.modalPresentationStyle = 5; | ||
var safariHackVC = UINavigationController.alloc().initWithRootViewController(safariVC); | ||
safariHackVC.setNavigationBarHiddenAnimated(true, false); | ||
var app = utils_1.ios.getter(UIApplication, UIApplication.sharedApplication); | ||
app.keyWindow.rootViewController.presentViewControllerAnimatedCompletion(safariHackVC, true, null); | ||
var ctrl = UIApplication.sharedApplication.keyWindow.rootViewController; | ||
if (options.modalEnabled) { | ||
safariVC.modalPresentationStyle = getPresentationStyle(options.modalPresentationStyle); | ||
if (options.animated) { | ||
safariVC.modalTransitionStyle = getTransitionStyle(options.modalTransitionStyle); | ||
} | ||
var safariHackVC = UINavigationController.alloc().initWithRootViewController(safariVC); | ||
safariHackVC.setNavigationBarHiddenAnimated(true, false); | ||
ctrl.presentViewControllerAnimatedCompletion(safariHackVC, options.animated, null); | ||
} | ||
else { | ||
ctrl.presentViewControllerAnimatedCompletion(safariVC, options.animated, null); | ||
} | ||
}); | ||
@@ -54,8 +87,10 @@ }, | ||
var self = this; | ||
var app = utils_1.ios.getter(UIApplication, UIApplication.sharedApplication); | ||
app.keyWindow.rootViewController.dismissViewControllerAnimatedCompletion(true, function () { | ||
self.redirectResolve({ | ||
type: 'dismiss' | ||
}); | ||
self.flowDidFinish(); | ||
var ctrl = UIApplication.sharedApplication.keyWindow.rootViewController; | ||
ctrl.dismissViewControllerAnimatedCompletion(self.animated, function () { | ||
if (self.redirectResolve) { | ||
self.redirectResolve({ | ||
type: 'dismiss' | ||
}); | ||
self.flowDidFinish(); | ||
} | ||
}); | ||
@@ -117,3 +152,21 @@ }, | ||
}, | ||
dismissWithoutAnimation: function (controller) { | ||
var transition = CATransition.animation(); | ||
transition.duration = 0.0; | ||
transition.timingFunction = CAMediaTimingFunction.functionWithName(kCAMediaTimingFunctionEaseInEaseOut); | ||
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); | ||
}); | ||
}, | ||
safariViewControllerDidFinish: function (controller) { | ||
if (!this.animated) { | ||
this.dismissWithoutAnimation(controller); | ||
} | ||
if (this.redirectResolve) { | ||
@@ -120,0 +173,0 @@ this.redirectResolve({ |
@@ -15,13 +15,33 @@ declare module 'nativescript-inappbrowser' { | ||
export interface InAppBrowserOptions { | ||
dismissButtonStyle?: 'done' | 'close' | 'cancel'; | ||
preferredBarTintColor?: string; | ||
preferredControlTintColor?: string; | ||
readerMode?: boolean; | ||
showTitle?: boolean; | ||
toolbarColor?: string; | ||
secondaryToolbarColor?: string; | ||
enableUrlBarHiding?: boolean; | ||
enableDefaultShare?: boolean; | ||
forceCloseOnRedirection?: boolean; | ||
type InAppBrowseriOSOptions = { | ||
dismissButtonStyle?: 'done' | 'close' | 'cancel', | ||
preferredBarTintColor?: string, | ||
preferredControlTintColor?: string, | ||
readerMode?: boolean, | ||
animated?: boolean, | ||
modalPresentationStyle?: | ||
| 'fullScreen' | ||
| 'pageSheet' | ||
| 'formSheet' | ||
| 'currentContext' | ||
| 'custom' | ||
| 'overFullScreen' | ||
| 'overCurrentContext' | ||
| 'popover' | ||
| 'none', | ||
modalTransitionStyle?: | ||
| 'coverVertical' | ||
| 'flipHorizontal' | ||
| 'crossDissolve' | ||
| 'partialCurl', | ||
modalEnabled?: boolean | ||
}; | ||
type InAppBrowserAndroidOptions = { | ||
showTitle?: boolean, | ||
toolbarColor?: string, | ||
secondaryToolbarColor?: string, | ||
enableUrlBarHiding?: boolean, | ||
enableDefaultShare?: boolean, | ||
forceCloseOnRedirection?: boolean, | ||
animations?: { | ||
@@ -32,6 +52,8 @@ startEnter: string, | ||
endExit: string | ||
}; | ||
headers?: { [key: string]: string }; | ||
} | ||
}, | ||
headers?: { [key: string]: string } | ||
}; | ||
export type InAppBrowserOptions = InAppBrowserAndroidOptions | InAppBrowseriOSOptions; | ||
type AuthSessionResult = RedirectResult | BrowserResult; | ||
@@ -38,0 +60,0 @@ |
125
package.json
{ | ||
"name": "nativescript-inappbrowser", | ||
"version": "1.0.2", | ||
"description": "InAppBrowser for NativeScript", | ||
"main": "InAppBrowser", | ||
"typings": "index.d.ts", | ||
"nativescript": { | ||
"platforms": { | ||
"android": "5.2.0", | ||
"ios": "5.2.0" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/proyecto26/nativescript-inappbrowser.git" | ||
}, | ||
"scripts": { | ||
"tsc": "npm install && tsc", | ||
"build": "npm run tsc && npm run build.native", | ||
"build.native": "node scripts/build-native.js", | ||
"postclone": "npm i && node scripts/postclone.js && cd ../demo && npm i && npx rimraf -- package-lock.json && cd ../src", | ||
"test.android": "npm run tsc && npm run tslint && cd ../demo && tns build android && tns test android --justlaunch", | ||
"test.ios": "npm run tsc && npm run tslint && cd ../demo && tns build ios && tns test ios --justlaunch", | ||
"tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\"", | ||
"plugin.tscwatch": "npm run tsc -- -w", | ||
"demo.ios": "npm run tsc && cd ../demo && tns run ios --syncAllFiles --emulator", | ||
"demo.android": "npm run tsc && cd ../demo && tns run android --syncAllFiles --emulator", | ||
"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", | ||
"ci.tslint": "npm i && tslint '**/*.ts' --config '../tslint.json' --exclude '**/node_modules/**' --exclude '**/platforms/**'", | ||
"prepack": "npm run build.native" | ||
}, | ||
"keywords": [ | ||
"NativeScript", | ||
"JavaScript", | ||
"Android", | ||
"iOS", | ||
"browser", | ||
"inappbrowser", | ||
"in-app-browser", | ||
"InAppBrowser" | ||
], | ||
"author": { | ||
"name": "Juan David Nicholls Cardona", | ||
"email": "jdnichollsc@hotmail.com" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/proyecto26/nativescript-inappbrowser/issues" | ||
}, | ||
"license": "MIT", | ||
"homepage": "https://github.com/proyecto26/nativescript-inappbrowser", | ||
"readmeFilename": "README.md", | ||
"devDependencies": { | ||
"tns-core-modules": "^5.0.0", | ||
"tns-platform-declarations": "^5.0.0", | ||
"typescript": "~3.3.3", | ||
"prompt": "^1.0.0", | ||
"rimraf": "^2.6.3", | ||
"tslint": "^5.12.1", | ||
"semver": "^5.6.0" | ||
}, | ||
"dependencies": {}, | ||
"bootstrapper": "nativescript-plugin-seed" | ||
"name": "nativescript-inappbrowser", | ||
"version": "2.0.0", | ||
"description": "InAppBrowser for NativeScript", | ||
"main": "InAppBrowser", | ||
"typings": "index.d.ts", | ||
"nativescript": { | ||
"platforms": { | ||
"android": "6.0.0", | ||
"ios": "6.0.1" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/proyecto26/nativescript-inappbrowser.git" | ||
}, | ||
"scripts": { | ||
"tsc": "npm install && tsc", | ||
"build": "npm run tsc && npm run build.native", | ||
"build.native": "node scripts/build-native.js", | ||
"postclone": "npm i && node scripts/postclone.js && cd ../demo && npm i && npx rimraf -- package-lock.json && cd ../src", | ||
"test.android": "npm run tsc && npm run tslint && cd ../demo && tns build android && tns test android --justlaunch", | ||
"test.ios": "npm run tsc && npm run tslint && cd ../demo && tns build ios && tns test ios --justlaunch", | ||
"tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\"", | ||
"demo.ios": "npm run tsc && cd ../demo && tns run ios --emulator", | ||
"demo.android": "npm run tsc && cd ../demo && tns run android --emulator", | ||
"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", | ||
"ci.tslint": "npm i && tslint '**/*.ts' --config '../tslint.json' --exclude '**/node_modules/**' --exclude '**/platforms/**'", | ||
"prepack": "npm run build.native" | ||
}, | ||
"keywords": [ | ||
"NativeScript", | ||
"JavaScript", | ||
"Android", | ||
"iOS", | ||
"browser", | ||
"inappbrowser", | ||
"in-app-browser", | ||
"InAppBrowser" | ||
], | ||
"author": { | ||
"name": "Juan David Nicholls Cardona", | ||
"email": "jdnichollsc@hotmail.com" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/proyecto26/nativescript-inappbrowser/issues" | ||
}, | ||
"license": "MIT", | ||
"homepage": "https://github.com/proyecto26/nativescript-inappbrowser", | ||
"readmeFilename": "README.md", | ||
"devDependencies": { | ||
"prompt": "^1.0.0", | ||
"rimraf": "^2.6.3", | ||
"semver": "^6.3.0", | ||
"tns-core-modules": "^6.0.2", | ||
"tns-platform-declarations": "^6.0.2", | ||
"tslint": "^5.18.0", | ||
"typescript": "~3.5.3" | ||
}, | ||
"dependencies": {}, | ||
"bootstrapper": "nativescript-plugin-seed" | ||
} |
@@ -11,2 +11,5 @@ <p align="center"> | ||
</a> | ||
<a href="https://opencollective.com/proyecto26" alt="Financial Contributors on Open Collective"> | ||
<img src="https://opencollective.com/proyecto26/all/badge.svg?label=financial+contributors" /> | ||
</a> | ||
<a href="https://travis-ci.org/proyecto26/nativescript-inappbrowser"> | ||
@@ -57,2 +60,6 @@ <img src="https://travis-ci.org/proyecto26/nativescript-inappbrowser.svg?branch=master" alt="Build Status" /> | ||
`readerMode` (Boolean) | A value that specifies whether Safari should enter Reader mode, if it is available. [`true`/`false`] | ||
`animated` (Boolean) | Animate the presentation. [`true`/`false`] | ||
`modalPresentationStyle` (String) | The presentation style for modally presented view controllers. [`none`/`fullScreen`/`pageSheet`/`formSheet`/`currentContext`/`custom`/`overFullScreen`/`overCurrentContext`/`popover`] | ||
`modalTransitionStyle` (String) | The transition style to use when presenting the view controller. [`coverVertical`/`flipHorizontal`/`crossDissolve`/`partialCurl`] | ||
`modalEnabled` (Boolean) | Present the **SafariViewController** modally or as push instead. [`true`/`false`] | ||
@@ -69,2 +76,3 @@ ### Android Options | ||
`headers` (Object) | The data are key/value pairs, they will be sent in the HTTP request headers for the provided url. [`{ 'Authorization': 'Bearer ...' }`] | ||
`forceCloseOnRedirection` (Boolean) | Open Custom Tab in a new task to avoid issues redirecting back to app scheme. [`true`/`false`] | ||
@@ -86,5 +94,9 @@ ### Demo | ||
dismissButtonStyle: 'cancel', | ||
preferredBarTintColor: 'gray', | ||
preferredBarTintColor: '#453AA4', | ||
preferredControlTintColor: 'white', | ||
readerMode: false, | ||
animated: true, | ||
modalPresentationStyle: 'overFullScreen', | ||
modalTransitionStyle: 'partialCurl', | ||
modalEnabled: true, | ||
// Android Properties | ||
@@ -103,3 +115,3 @@ showTitle: true, | ||
endEnter: 'slide_in_left', | ||
endExit: 'slide_out_right', | ||
endExit: 'slide_out_right' | ||
}, | ||
@@ -140,3 +152,26 @@ headers: { | ||
<!-- CONTRIBUTORS-LIST:END --> | ||
### Financial Contributors | ||
Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/proyecto26/contribute)] | ||
#### Individuals | ||
<a href="https://opencollective.com/proyecto26"><img src="https://opencollective.com/proyecto26/individuals.svg?width=890"></a> | ||
#### Organizations | ||
Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/proyecto26/contribute)] | ||
<a href="https://opencollective.com/proyecto26/organization/0/website"><img src="https://opencollective.com/proyecto26/organization/0/avatar.svg"></a> | ||
<a href="https://opencollective.com/proyecto26/organization/1/website"><img src="https://opencollective.com/proyecto26/organization/1/avatar.svg"></a> | ||
<a href="https://opencollective.com/proyecto26/organization/2/website"><img src="https://opencollective.com/proyecto26/organization/2/avatar.svg"></a> | ||
<a href="https://opencollective.com/proyecto26/organization/3/website"><img src="https://opencollective.com/proyecto26/organization/3/avatar.svg"></a> | ||
<a href="https://opencollective.com/proyecto26/organization/4/website"><img src="https://opencollective.com/proyecto26/organization/4/avatar.svg"></a> | ||
<a href="https://opencollective.com/proyecto26/organization/5/website"><img src="https://opencollective.com/proyecto26/organization/5/avatar.svg"></a> | ||
<a href="https://opencollective.com/proyecto26/organization/6/website"><img src="https://opencollective.com/proyecto26/organization/6/avatar.svg"></a> | ||
<a href="https://opencollective.com/proyecto26/organization/7/website"><img src="https://opencollective.com/proyecto26/organization/7/avatar.svg"></a> | ||
<a href="https://opencollective.com/proyecto26/organization/8/website"><img src="https://opencollective.com/proyecto26/organization/8/avatar.svg"></a> | ||
<a href="https://opencollective.com/proyecto26/organization/9/website"><img src="https://opencollective.com/proyecto26/organization/9/avatar.svg"></a> | ||
## Supporting 🍻 | ||
@@ -143,0 +178,0 @@ I believe in Unicorns 🦄 |
@@ -26,2 +26,29 @@ declare namespace android { | ||
} | ||
} | ||
declare namespace androidx { | ||
export namespace browser { | ||
export namespace customtabs { | ||
export class CustomTabsIntent { | ||
launchUrl(context: android.content.Context, url: android.net.Uri): void; | ||
intent: android.content.Intent; | ||
static NO_TITLE: number; | ||
static EXTRA_TITLE_VISIBILITY_STATE: string; | ||
startAnimationBundle: android.os.Bundle; | ||
} | ||
namespace CustomTabsIntent { | ||
export class Builder { | ||
constructor(); | ||
build(): android.support.customtabs.CustomTabsIntent; | ||
setShowTitle(showTitle: boolean): this; | ||
setToolbarColor(color: number): this; | ||
setSecondaryToolbarColor(color: number): this; | ||
addDefaultShareMenuItem(): this; | ||
enableUrlBarHiding(): this; | ||
setStartAnimations(context: android.content.Context, enterResId: number, exitResId: number); | ||
setExitAnimations(context: android.content.Context, enterResId: number, exitResId: number); | ||
} | ||
} | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
49098
724
179