Merge pull request #109 from aitorct/hasBackButton

hasBackButton property
This commit is contained in:
Juan David Nicholls Cardona 2020-06-25 00:50:30 -05:00 committed by GitHub
commit 6ebc3e7e16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 15 additions and 0 deletions

View File

@ -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`]

View File

@ -8,9 +8,11 @@ import android.content.Context;
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 class RNInAppBrowser {
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 class RNInAppBrowser {
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 @@ public class RNInAppBrowser {
EventBus.getDefault().unregister(this);
}
}
private Boolean toolbarIsLight(String themeColor) {
return ColorUtils.calculateLuminance(Color.parseColor(themeColor)) > 0.5;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 B