88import android .content .Intent ;
99import android .content .pm .ResolveInfo ;
1010import android .graphics .Color ;
11+ import android .graphics .BitmapFactory ;
1112import android .provider .Browser ;
1213import androidx .annotation .Nullable ;
1314import androidx .browser .customtabs .CustomTabsIntent ;
15+ import androidx .core .graphics .ColorUtils ;
1416
1517import com .facebook .react .bridge .Arguments ;
1618import com .facebook .react .bridge .Promise ;
@@ -40,8 +42,10 @@ public class RNInAppBrowser {
4042 private static final String KEY_ANIMATION_START_EXIT = "startExit" ;
4143 private static final String KEY_ANIMATION_END_ENTER = "endEnter" ;
4244 private static final String KEY_ANIMATION_END_EXIT = "endExit" ;
45+ private static final String HASBACKBUTTON = "hasBackButton" ;
4346
4447 private @ Nullable Promise mOpenBrowserPromise ;
48+ private Boolean isLightTheme ;
4549 private Activity currentActivity ;
4650 private static final Pattern animationIdentifierPattern = Pattern .compile ("^.+:.+/" );
4751
@@ -68,6 +72,7 @@ public void open(Context context, final ReadableMap options, final Promise promi
6872 final String colorString = options .getString (KEY_TOOLBAR_COLOR );
6973 try {
7074 builder .setToolbarColor (Color .parseColor (colorString ));
75+ isLightTheme = toolbarIsLight (colorString );
7176 } catch (IllegalArgumentException e ) {
7277 throw new JSApplicationIllegalArgumentException (
7378 "Invalid toolbar color '" + colorString + "': " + e .getMessage ());
@@ -94,6 +99,11 @@ public void open(Context context, final ReadableMap options, final Promise promi
9499 final ReadableMap animations = options .getMap (KEY_ANIMATIONS );
95100 applyAnimation (context , builder , animations );
96101 }
102+ if (options .hasKey (HASBACKBUTTON ) &&
103+ options .getBoolean (HASBACKBUTTON )) {
104+ builder .setCloseButtonIcon (BitmapFactory .decodeResource (
105+ context .getResources (), isLightTheme ? R .drawable .ic_arrow_back_black : R .drawable .ic_arrow_back_white ));
106+ }
97107
98108 CustomTabsIntent customTabsIntent = builder .build ();
99109
@@ -226,4 +236,8 @@ private void unRegisterEventBus() {
226236 EventBus .getDefault ().unregister (this );
227237 }
228238 }
239+
240+ private Boolean toolbarIsLight (String themeColor ) {
241+ return ColorUtils .calculateLuminance (Color .parseColor (themeColor )) > 0.5 ;
242+ }
229243}
0 commit comments