diff --git a/README.md b/README.md index 78ea549..2e3275f 100644 --- a/README.md +++ b/README.md @@ -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`] diff --git a/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java b/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java index 907abde..d42172f 100644 --- a/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java +++ b/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java @@ -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; @@ -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("^.+:.+/"); @@ -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()); @@ -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(); @@ -226,4 +236,8 @@ private void unRegisterEventBus() { EventBus.getDefault().unregister(this); } } + + private Boolean toolbarIsLight(String themeColor) { + return ColorUtils.calculateLuminance(Color.parseColor(themeColor)) > 0.5; + } } diff --git a/android/src/main/res/drawable-hdpi/ic_arrow_back_black.png b/android/src/main/res/drawable-hdpi/ic_arrow_back_black.png new file mode 100644 index 0000000..3353538 Binary files /dev/null and b/android/src/main/res/drawable-hdpi/ic_arrow_back_black.png differ diff --git a/android/src/main/res/drawable-hdpi/ic_arrow_back_white.png b/android/src/main/res/drawable-hdpi/ic_arrow_back_white.png new file mode 100644 index 0000000..a39e3b5 Binary files /dev/null and b/android/src/main/res/drawable-hdpi/ic_arrow_back_white.png differ diff --git a/android/src/main/res/drawable-mdpi/ic_arrow_back_black.png b/android/src/main/res/drawable-mdpi/ic_arrow_back_black.png new file mode 100644 index 0000000..0beceed Binary files /dev/null and b/android/src/main/res/drawable-mdpi/ic_arrow_back_black.png differ diff --git a/android/src/main/res/drawable-mdpi/ic_arrow_back_white.png b/android/src/main/res/drawable-mdpi/ic_arrow_back_white.png new file mode 100644 index 0000000..1909865 Binary files /dev/null and b/android/src/main/res/drawable-mdpi/ic_arrow_back_white.png differ diff --git a/android/src/main/res/drawable-xhdpi/ic_arrow_back_black.png b/android/src/main/res/drawable-xhdpi/ic_arrow_back_black.png new file mode 100644 index 0000000..57606fe Binary files /dev/null and b/android/src/main/res/drawable-xhdpi/ic_arrow_back_black.png differ diff --git a/android/src/main/res/drawable-xhdpi/ic_arrow_back_white.png b/android/src/main/res/drawable-xhdpi/ic_arrow_back_white.png new file mode 100644 index 0000000..7ffa22f Binary files /dev/null and b/android/src/main/res/drawable-xhdpi/ic_arrow_back_white.png differ diff --git a/android/src/main/res/drawable-xxhdpi/ic_arrow_back_black.png b/android/src/main/res/drawable-xxhdpi/ic_arrow_back_black.png new file mode 100644 index 0000000..5fc11c8 Binary files /dev/null and b/android/src/main/res/drawable-xxhdpi/ic_arrow_back_black.png differ diff --git a/android/src/main/res/drawable-xxhdpi/ic_arrow_back_white.png b/android/src/main/res/drawable-xxhdpi/ic_arrow_back_white.png new file mode 100644 index 0000000..61765ce Binary files /dev/null and b/android/src/main/res/drawable-xxhdpi/ic_arrow_back_white.png differ