Skip to content

Commit

Permalink
Merge pull request #109 from aitorct/hasBackButton
Browse files Browse the repository at this point in the history
hasBackButton property
  • Loading branch information
jdnichollsc authored Jun 25, 2020
2 parents 2dea12a + 1004bda commit 6ebc3e7
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,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 @@ -8,9 +8,11 @@
import android.content.Intent;
import android.content.pm.ResolveInfo;
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 @@ -40,8 +42,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 @@ -68,6 +72,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 @@ -94,6 +99,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 @@ -226,4 +236,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.

0 comments on commit 6ebc3e7

Please sign in to comment.