Skip to content

Commit

Permalink
Merge pull request #52 from proyecto26/develop
Browse files Browse the repository at this point in the history
Release 3.0.1
  • Loading branch information
jdnichollsc authored Nov 30, 2020
2 parents 71db068 + 8fc9255 commit efe2ebe
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 20 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
25 changes: 16 additions & 9 deletions src/InAppBrowser.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -39,6 +38,8 @@ import {
closeAuthSessionPolyfillAsync,
} from './utils.android';

import { parseColor } from './utils.common';

declare let global: any;

let InAppBrowserModuleInstance: InAppBrowserClassMethods;
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions src/InAppBrowser.common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from "@nativescript/core";

export interface RedirectEvent {
url: 'string';
}
Expand All @@ -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?:
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions src/InAppBrowser.ios.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Color, Utils } from '@nativescript/core';
import { parseColor } from './utils.common';

import {
BrowserResult,
Expand Down Expand Up @@ -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;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/utils.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ export function getPreferredPackages(context: Context): List<ResolveInfo> {
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 {
Expand Down
8 changes: 8 additions & 0 deletions src/utils.common.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit efe2ebe

Please sign in to comment.