Skip to content

hasBackButton property #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ Property | Description
Property | Description
-------------- | ------
`showTitle` (Boolean) | Sets whether the title should be shown in the custom tab. [`true`/`false`]
`hasBackButton` (Boolean) | Sets a back arrow instead of the default X icon to close the custom tab. [`true`/`false`]
`toolbarColor` (String) | Sets the toolbar color. [`gray`/`#808080`]
`secondaryToolbarColor` (String) | Sets the color of the secondary toolbar. [`white`/`#FFFFFF`]
`enableUrlBarHiding` (Boolean) | Enables the url bar to hide as the user scrolls down on the page. [`true`/`false`]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.BitmapFactory;
import android.provider.Browser;
import androidx.annotation.Nullable;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.core.graphics.ColorUtils;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
Expand Down Expand Up @@ -38,8 +40,10 @@ public class RNInAppBrowser {
private static final String KEY_ANIMATION_START_EXIT = "startExit";
private static final String KEY_ANIMATION_END_ENTER = "endEnter";
private static final String KEY_ANIMATION_END_EXIT = "endExit";
private static final String HASBACKBUTTON = "hasBackButton";

private @Nullable Promise mOpenBrowserPromise;
private Boolean isLightTheme;
private Activity currentActivity;
private static final Pattern animationIdentifierPattern = Pattern.compile("^.+:.+/");

Expand All @@ -66,6 +70,7 @@ public void open(Context context, final ReadableMap options, final Promise promi
final String colorString = options.getString(KEY_TOOLBAR_COLOR);
try {
builder.setToolbarColor(Color.parseColor(colorString));
isLightTheme = toolbarIsLight(colorString);
} catch (IllegalArgumentException e) {
throw new JSApplicationIllegalArgumentException(
"Invalid toolbar color '" + colorString + "': " + e.getMessage());
Expand All @@ -92,6 +97,11 @@ public void open(Context context, final ReadableMap options, final Promise promi
final ReadableMap animations = options.getMap(KEY_ANIMATIONS);
applyAnimation(context, builder, animations);
}
if (options.hasKey(HASBACKBUTTON) &&
options.getBoolean(HASBACKBUTTON)) {
builder.setCloseButtonIcon(BitmapFactory.decodeResource(
context.getResources(), isLightTheme ? R.drawable.ic_arrow_back_black : R.drawable.ic_arrow_back_white));
}

CustomTabsIntent customTabsIntent = builder.build();

Expand Down Expand Up @@ -218,4 +228,8 @@ private void unRegisterEventBus() {
EventBus.getDefault().unregister(this);
}
}

private Boolean toolbarIsLight(String themeColor) {
return ColorUtils.calculateLuminance(Color.parseColor(themeColor)) > 0.5;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.