@@ -38,6 +38,8 @@ import {
3838 closeAuthSessionPolyfillAsync ,
3939} from './utils.android' ;
4040
41+ import { parseColor } from './utils.common' ;
42+
4143declare let global : any ;
4244
4345let InAppBrowserModuleInstance : InAppBrowserClassMethods ;
@@ -100,25 +102,30 @@ function setup() {
100102 const inAppBrowserOptions = getDefaultOptions ( url , options ) ;
101103
102104 const builder = new CustomTabsIntent . Builder ( ) ;
103- if ( inAppBrowserOptions [ InAppBrowserModule . KEY_TOOLBAR_COLOR ] ) {
104- const colorString = inAppBrowserOptions [ InAppBrowserModule . KEY_TOOLBAR_COLOR ] ;
105- const color = colorString instanceof Color ? colorString : new Color ( colorString ) ;
106- try {
107- builder . setToolbarColor ( color . android ) ;
108- this . isLightTheme = toolbarIsLight ( color . android ) ;
109- } catch ( error ) {
110- throw new Error (
111- "Invalid toolbar color '" + colorString + "': " + error . message ) ;
105+ let colorString = inAppBrowserOptions [ InAppBrowserModule . KEY_TOOLBAR_COLOR ] ;
106+ if ( colorString ) {
107+ const color = parseColor ( colorString ) ;
108+ if ( color ) {
109+ try {
110+ builder . setToolbarColor ( color . android ) ;
111+ this . isLightTheme = toolbarIsLight ( color . android ) ;
112+ } catch ( error ) {
113+ throw new Error (
114+ "Invalid toolbar color '" + colorString + "': " + error . message ) ;
115+ }
112116 }
117+
113118 }
114- if ( inAppBrowserOptions [ InAppBrowserModule . KEY_SECONDARY_TOOLBAR_COLOR ] ) {
115- const colorString = inAppBrowserOptions [ InAppBrowserModule . KEY_SECONDARY_TOOLBAR_COLOR ] ;
116- const color = colorString instanceof Color ? colorString : new Color ( colorString ) ;
117- try {
118- builder . setSecondaryToolbarColor ( color . android ) ;
119- } catch ( error ) {
120- throw new Error (
121- "Invalid secondary toolbar color '" + colorString + "': " + error . message ) ;
119+ colorString = inAppBrowserOptions [ InAppBrowserModule . KEY_SECONDARY_TOOLBAR_COLOR ] ;
120+ if ( colorString ) {
121+ const color = parseColor ( colorString ) ;
122+ if ( color ) {
123+ try {
124+ builder . setSecondaryToolbarColor ( color . android ) ;
125+ } catch ( error ) {
126+ throw new Error (
127+ "Invalid secondary toolbar color '" + colorString + "': " + error . message ) ;
128+ }
122129 }
123130 }
124131
0 commit comments