Skip to content

Commit 6ebc3e7

Browse files
authored
Merge pull request #109 from aitorct/hasBackButton
hasBackButton property
2 parents 2dea12a + 1004bda commit 6ebc3e7

File tree

10 files changed

+15
-0
lines changed

10 files changed

+15
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Property | Description
150150
Property | Description
151151
-------------- | ------
152152
`showTitle` (Boolean) | Sets whether the title should be shown in the custom tab. [`true`/`false`]
153+
`hasBackButton` (Boolean) | Sets a back arrow instead of the default X icon to close the custom tab. [`true`/`false`]
153154
`toolbarColor` (String) | Sets the toolbar color. [`gray`/`#808080`]
154155
`secondaryToolbarColor` (String) | Sets the color of the secondary toolbar. [`white`/`#FFFFFF`]
155156
`enableUrlBarHiding` (Boolean) | Enables the url bar to hide as the user scrolls down on the page. [`true`/`false`]

android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import android.content.Intent;
99
import android.content.pm.ResolveInfo;
1010
import android.graphics.Color;
11+
import android.graphics.BitmapFactory;
1112
import android.provider.Browser;
1213
import androidx.annotation.Nullable;
1314
import androidx.browser.customtabs.CustomTabsIntent;
15+
import androidx.core.graphics.ColorUtils;
1416

1517
import com.facebook.react.bridge.Arguments;
1618
import 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
}
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)