77import android .content .Context ;
88import android .content .Intent ;
99import android .graphics .Color ;
10+ import android .graphics .BitmapFactory ;
1011import android .provider .Browser ;
1112import androidx .annotation .Nullable ;
1213import androidx .browser .customtabs .CustomTabsIntent ;
14+ import androidx .core .graphics .ColorUtils ;
1315
1416import com .facebook .react .bridge .Arguments ;
1517import com .facebook .react .bridge .Promise ;
@@ -38,8 +40,10 @@ public class RNInAppBrowser {
3840 private static final String KEY_ANIMATION_START_EXIT = "startExit" ;
3941 private static final String KEY_ANIMATION_END_ENTER = "endEnter" ;
4042 private static final String KEY_ANIMATION_END_EXIT = "endExit" ;
43+ private static final String HASBACKBUTTON = "hasBackButton" ;
4144
4245 private @ Nullable Promise mOpenBrowserPromise ;
46+ private Boolean isLightTheme ;
4347 private Activity currentActivity ;
4448 private static final Pattern animationIdentifierPattern = Pattern .compile ("^.+:.+/" );
4549
@@ -66,6 +70,7 @@ public void open(Context context, final ReadableMap options, final Promise promi
6670 final String colorString = options .getString (KEY_TOOLBAR_COLOR );
6771 try {
6872 builder .setToolbarColor (Color .parseColor (colorString ));
73+ isLightTheme = toolbarIsLight (colorString );
6974 } catch (IllegalArgumentException e ) {
7075 throw new JSApplicationIllegalArgumentException (
7176 "Invalid toolbar color '" + colorString + "': " + e .getMessage ());
@@ -92,6 +97,11 @@ public void open(Context context, final ReadableMap options, final Promise promi
9297 final ReadableMap animations = options .getMap (KEY_ANIMATIONS );
9398 applyAnimation (context , builder , animations );
9499 }
100+ if (options .hasKey (HASBACKBUTTON ) &&
101+ options .getBoolean (HASBACKBUTTON )) {
102+ builder .setCloseButtonIcon (BitmapFactory .decodeResource (
103+ context .getResources (), isLightTheme ? R .drawable .ic_arrow_back_black : R .drawable .ic_arrow_back_white ));
104+ }
95105
96106 CustomTabsIntent customTabsIntent = builder .build ();
97107
@@ -218,4 +228,8 @@ private void unRegisterEventBus() {
218228 EventBus .getDefault ().unregister (this );
219229 }
220230 }
231+
232+ private Boolean toolbarIsLight (String themeColor ) {
233+ return ColorUtils .calculateLuminance (Color .parseColor (themeColor )) > 0.5 ;
234+ }
221235}
0 commit comments