Skip to content

Commit

Permalink
Merge pull request #281 from proyecto26/fix/error-cannot-find-symbol
Browse files Browse the repository at this point in the history
fix(android): 279 - Fix error cannot find symbol
  • Loading branch information
jdnichollsc authored Jul 3, 2021
2 parents 2d0a13f + 2c6400e commit bbb711d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 38 deletions.
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

0 comments on commit bbb711d

Please sign in to comment.