diff --git a/CHANGELOG.md b/CHANGELOG.md index a3c7f74..ef4c42c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,8 +22,13 @@ in case of vulnerabilities. ## [Unreleased] +## [3.0.1] - 2020-11-30 +### Fixed +- Fix colors not working with instance of Color by [@farfromrefug](https://github.com/farfromrefug) ([#50](https://github.com/proyecto26/nativescript-inappbrowser/pull/50)). + ## [3.0.0] - 2020-10-30 ### Added +- {N} 7 updates by [@NathanWalker](https://github.com/NathanWalker) ([#40](https://github.com/proyecto26/nativescript-inappbrowser/pull/40)). - Added `hasBackButton` option to sets a back arrow instead of the default X icon to close the custom tab. - Added default browser configuration for custom tab if any. - Added `browserPackage` option to use a Package name of a browser to be used to handle Custom Tabs. @@ -78,7 +83,8 @@ in case of vulnerabilities. - Methods to open and close external urls to authenticate the user **(openAuth, closeAuth)** using deep linking. - `isAvailable` method to detect if the device supports the plugin. -[Unreleased]: https://github.com/proyecto26/nativescript-inappbrowser/compare/v3.0.0...HEAD +[Unreleased]: https://github.com/proyecto26/nativescript-inappbrowser/compare/v3.0.1...HEAD +[3.0.1]: https://github.com/proyecto26/nativescript-inappbrowser/compare/v3.0.0...v3.0.1 [3.0.0]: https://github.com/proyecto26/nativescript-inappbrowser/compare/v2.3.0...v3.0.0 [2.3.0]: https://github.com/proyecto26/nativescript-inappbrowser/compare/v2.2.0...v2.3.0 [2.2.0]: https://github.com/proyecto26/nativescript-inappbrowser/compare/v2.1.1...v2.2.0 diff --git a/src/InAppBrowser.android.ts b/src/InAppBrowser.android.ts index d7781c7..974556f 100644 --- a/src/InAppBrowser.android.ts +++ b/src/InAppBrowser.android.ts @@ -3,13 +3,12 @@ import Bundle = android.os.Bundle; import TextUtils = android.text.TextUtils; import Intent = android.content.Intent; import Context = android.content.Context; -import Color = android.graphics.Color; import BitmapFactory = android.graphics.BitmapFactory; import Browser = android.provider.Browser; import Pattern = java.util.regex.Pattern; import AssertionError = java.lang.AssertionError; -import { Utils, Application, EventData } from '@nativescript/core'; +import { Utils, Application, EventData, Color } from '@nativescript/core'; import { ChromeTabsEvent, BROWSER_ACTIVITY_EVENTS, @@ -39,6 +38,8 @@ import { closeAuthSessionPolyfillAsync, } from './utils.android'; +import { parseColor } from './utils.common'; + declare let global: any; let InAppBrowserModuleInstance: InAppBrowserClassMethods; @@ -101,20 +102,26 @@ function setup() { const inAppBrowserOptions = getDefaultOptions(url, options); const builder = new CustomTabsIntent.Builder(); - if (inAppBrowserOptions[InAppBrowserModule.KEY_TOOLBAR_COLOR]) { - const colorString = inAppBrowserOptions[InAppBrowserModule.KEY_TOOLBAR_COLOR]; + let colorString = inAppBrowserOptions[InAppBrowserModule.KEY_TOOLBAR_COLOR]; + if (colorString) { try { - builder.setToolbarColor(Color.parseColor(colorString)); - this.isLightTheme = toolbarIsLight(colorString); + const color = parseColor(colorString); + if (color) { + builder.setToolbarColor(color.android); + this.isLightTheme = toolbarIsLight(color.android); + } } catch (error) { throw new Error( "Invalid toolbar color '" + colorString + "': " + error.message); } } - if (inAppBrowserOptions[InAppBrowserModule.KEY_SECONDARY_TOOLBAR_COLOR]) { - const colorString = inAppBrowserOptions[InAppBrowserModule.KEY_SECONDARY_TOOLBAR_COLOR]; + colorString = inAppBrowserOptions[InAppBrowserModule.KEY_SECONDARY_TOOLBAR_COLOR]; + if (colorString) { try { - builder.setSecondaryToolbarColor(Color.parseColor(colorString)); + const color = parseColor(colorString); + if (color) { + builder.setSecondaryToolbarColor(color.android); + } } catch (error) { throw new Error( "Invalid secondary toolbar color '" + colorString + "': " + error.message); diff --git a/src/InAppBrowser.common.ts b/src/InAppBrowser.common.ts index 4b028ba..d71f86f 100644 --- a/src/InAppBrowser.common.ts +++ b/src/InAppBrowser.common.ts @@ -1,3 +1,5 @@ +import { Color } from "@nativescript/core"; + export interface RedirectEvent { url: 'string'; } @@ -14,8 +16,8 @@ export interface RedirectResult { type InAppBrowseriOSOptions = { dismissButtonStyle?: 'done' | 'close' | 'cancel', - preferredBarTintColor?: string, - preferredControlTintColor?: string, + preferredBarTintColor?: string | Color, + preferredControlTintColor?: string | Color, readerMode?: boolean, animated?: boolean, modalPresentationStyle?: @@ -48,8 +50,8 @@ export type Animations = { type InAppBrowserAndroidOptions = { showTitle?: boolean, - toolbarColor?: string, - secondaryToolbarColor?: string, + toolbarColor?: string | Color, + secondaryToolbarColor?: string | Color, enableUrlBarHiding?: boolean, enableDefaultShare?: boolean, forceCloseOnRedirection?: boolean, diff --git a/src/InAppBrowser.ios.ts b/src/InAppBrowser.ios.ts index e5bca34..a0f7c09 100644 --- a/src/InAppBrowser.ios.ts +++ b/src/InAppBrowser.ios.ts @@ -1,4 +1,5 @@ import { Color, Utils } from '@nativescript/core'; +import { parseColor } from './utils.common'; import { BrowserResult, @@ -98,10 +99,16 @@ function setup() { if (Utils.ios.MajorVersion >= 10) { if (inAppBrowserOptions.preferredBarTintColor) { - this.safariVC.preferredBarTintColor = new Color(inAppBrowserOptions.preferredBarTintColor).ios; + const color = parseColor(inAppBrowserOptions.preferredBarTintColor); + if (color) { + this.safariVC.preferredBarTintColor = color.ios; + } } if (inAppBrowserOptions.preferredControlTintColor) { - this.safariVC.preferredControlTintColor = new Color(inAppBrowserOptions.preferredControlTintColor).ios; + const color = parseColor(inAppBrowserOptions.preferredBarTintColor); + if (color) { + this.safariVC.preferredControlTintColor = color.ios; + } } } diff --git a/src/package-lock.json b/src/package-lock.json index fe75c21..a522010 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -1,6 +1,6 @@ { "name": "nativescript-inappbrowser", - "version": "3.0.0", + "version": "3.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/package.json b/src/package.json index 70ed96e..22dd478 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-inappbrowser", - "version": "3.0.0", + "version": "3.0.1", "description": "InAppBrowser for NativeScript", "main": "InAppBrowser", "typings": "index.d.ts", diff --git a/src/utils.android.ts b/src/utils.android.ts index 3e19229..ab12595 100644 --- a/src/utils.android.ts +++ b/src/utils.android.ts @@ -156,8 +156,8 @@ export function getPreferredPackages(context: Context): List { return resolveInfos; } -export function toolbarIsLight(themeColor: string): boolean { - return ColorUtils.calculateLuminance(Color.parseColor(themeColor)) > 0.5; +export function toolbarIsLight(themeColor: number): boolean { + return ColorUtils.calculateLuminance(themeColor) > 0.5; } export function getDefaultBrowser(context: Context): string { diff --git a/src/utils.common.ts b/src/utils.common.ts new file mode 100644 index 0000000..9fab213 --- /dev/null +++ b/src/utils.common.ts @@ -0,0 +1,8 @@ +import { Color } from "@nativescript/core"; + +export function parseColor(color: string | Color) { + if (color && !(color instanceof Color)) { + return new Color(color); + } + return color as Color; +} \ No newline at end of file