Merge pull request #109 from aitorct/hasBackButton
hasBackButton property
@ -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`]
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
BIN
android/src/main/res/drawable-hdpi/ic_arrow_back_black.png
Normal file
|
After Width: | Height: | Size: 146 B |
BIN
android/src/main/res/drawable-hdpi/ic_arrow_back_white.png
Normal file
|
After Width: | Height: | Size: 146 B |
BIN
android/src/main/res/drawable-mdpi/ic_arrow_back_black.png
Normal file
|
After Width: | Height: | Size: 109 B |
BIN
android/src/main/res/drawable-mdpi/ic_arrow_back_white.png
Normal file
|
After Width: | Height: | Size: 111 B |
BIN
android/src/main/res/drawable-xhdpi/ic_arrow_back_black.png
Normal file
|
After Width: | Height: | Size: 156 B |
BIN
android/src/main/res/drawable-xhdpi/ic_arrow_back_white.png
Normal file
|
After Width: | Height: | Size: 153 B |
BIN
android/src/main/res/drawable-xxhdpi/ic_arrow_back_black.png
Normal file
|
After Width: | Height: | Size: 193 B |
BIN
android/src/main/res/drawable-xxhdpi/ic_arrow_back_white.png
Normal file
|
After Width: | Height: | Size: 195 B |