Skip to content

fix(android): 279 - Fix error cannot find symbol #281

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 5 commits into from
Jul 3, 2021
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ in case of vulnerabilities.

## [Unreleased]

### Fixed
- Fix `Build failed. Error cannot find symbol builder.setNavigationBarColor` error for Android Support ([#281](https://github.com/proyecto26/react-native-inappbrowser/pull/281)).

## [3.6.1] - 2021-06-27

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.regex.Pattern;
import java.util.List;
Expand Down Expand Up @@ -62,6 +63,25 @@ public class RNInAppBrowser {
private Activity currentActivity;
private static final Pattern animationIdentifierPattern = Pattern.compile("^.+:.+/");

public Integer setColor(CustomTabsIntent.Builder builder, final ReadableMap options, String key, String method, String colorName) {
String colorString = options.getString(key);
Integer color = null;
try {
if (colorString != null) {
color = Color.parseColor(colorString);
Method findMethod = builder.getClass().getDeclaredMethod(method, int.class);
findMethod.invoke(builder, color);
}
} catch (Exception e) {
if (e instanceof IllegalArgumentException) {
throw new JSApplicationIllegalArgumentException(
"Invalid " + colorName + " color '" + colorString + "': " + e.getMessage());
}
} finally {
return color;
}
}

public void open(Context context, final ReadableMap options, final Promise promise, Activity activity) {
final String url = options.getString("url");
currentActivity = activity;
Expand All @@ -82,43 +102,14 @@ public void open(Context context, final ReadableMap options, final Promise promi

CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
isLightTheme = false;
if (options.hasKey(KEY_TOOLBAR_COLOR)) {
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());
}
}
if (options.hasKey(KEY_SECONDARY_TOOLBAR_COLOR)) {
final String colorString = options.getString(KEY_SECONDARY_TOOLBAR_COLOR);
try {
builder.setSecondaryToolbarColor(Color.parseColor(colorString));
} catch (IllegalArgumentException e) {
throw new JSApplicationIllegalArgumentException(
"Invalid secondary toolbar color '" + colorString + "': " + e.getMessage());
}
}
if (options.hasKey(KEY_NAVIGATION_BAR_COLOR)) {
final String colorString = options.getString(KEY_NAVIGATION_BAR_COLOR);
try {
builder.setNavigationBarColor(Color.parseColor(colorString));
} catch (IllegalArgumentException e) {
throw new JSApplicationIllegalArgumentException(
"Invalid navigation bar color '" + colorString + "': " + e.getMessage());
}
}
if (options.hasKey(KEY_NAVIGATION_BAR_DIVIDER_COLOR)) {
final String colorString = options.getString(KEY_NAVIGATION_BAR_DIVIDER_COLOR);
try {
builder.setNavigationBarDividerColor(Color.parseColor(colorString));
} catch (IllegalArgumentException e) {
throw new JSApplicationIllegalArgumentException(
"Invalid navigation bar divider color '" + colorString + "': " + e.getMessage());
}
final Integer toolbarColor = setColor(builder, options, KEY_TOOLBAR_COLOR, "setToolbarColor", "toolbar");
if (toolbarColor != null) {
isLightTheme = toolbarIsLight(toolbarColor);
}
setColor(builder, options, KEY_SECONDARY_TOOLBAR_COLOR, "setSecondaryToolbarColor", "secondary toolbar");
setColor(builder, options, KEY_NAVIGATION_BAR_COLOR, "setNavigationBarColor", "navigation bar");
setColor(builder, options, KEY_NAVIGATION_BAR_DIVIDER_COLOR, "setNavigationBarDividerColor", "navigation bar divider");

if (options.hasKey(KEY_DEFAULT_SHARE_MENU_ITEM) &&
options.getBoolean(KEY_DEFAULT_SHARE_MENU_ITEM)) {
builder.addDefaultShareMenuItem();
Expand Down Expand Up @@ -292,8 +283,8 @@ private void unRegisterEventBus() {
}
}

private Boolean toolbarIsLight(String themeColor) {
return ColorUtils.calculateLuminance(Color.parseColor(themeColor)) > 0.5;
private Boolean toolbarIsLight(int themeColor) {
return ColorUtils.calculateLuminance(themeColor) > 0.5;
}

private List<ResolveInfo> getPreferredPackages(Context context) {
Expand Down