From b9dfb67f6db2a0227d7a75ee553160e3f149b71a Mon Sep 17 00:00:00 2001 From: Juan David Nicholls Cardona Date: Sat, 3 Jul 2021 15:20:11 -0500 Subject: [PATCH 1/5] fix(android): 279 - Fix error cannot find symbol builder.setNavigationBarColor --- .../inappbrowser/RNInAppBrowser.java | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java b/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java index 10f07c3..1884b4b 100644 --- a/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java +++ b/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java @@ -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; @@ -62,6 +63,33 @@ public class RNInAppBrowser { private Activity currentActivity; private static final Pattern animationIdentifierPattern = Pattern.compile("^.+:.+/"); + public void setNavigationColors(CustomTabsIntent.Builder builder, final ReadableMap options) { + if (options.hasKey(KEY_NAVIGATION_BAR_COLOR)) { + final String colorString = options.getString(KEY_NAVIGATION_BAR_COLOR); + try { + Method setNavigationBarColor = builder.getClass().getDeclaredMethod("setNavigationBarColor", int.class); + setNavigationBarColor.invoke(builder, Color.parseColor(colorString)); + } catch (Exception e) { + if (e instanceof IllegalArgumentException) { + 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 { + Method setNavigationBarDividerColor = builder.getClass().getDeclaredMethod("setNavigationBarDividerColor", int.class); + setNavigationBarDividerColor.invoke(builder, Color.parseColor(colorString)); + } catch (Exception e) { + if (e instanceof IllegalArgumentException) { + throw new JSApplicationIllegalArgumentException( + "Invalid navigation bar divider color '" + colorString + "': " + e.getMessage()); + } + } + } + } + public void open(Context context, final ReadableMap options, final Promise promise, Activity activity) { final String url = options.getString("url"); currentActivity = activity; @@ -101,24 +129,8 @@ public void open(Context context, final ReadableMap options, final Promise promi "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()); - } - } + setNavigationColors(builder, options); + if (options.hasKey(KEY_DEFAULT_SHARE_MENU_ITEM) && options.getBoolean(KEY_DEFAULT_SHARE_MENU_ITEM)) { builder.addDefaultShareMenuItem(); From 8ad35ab55d01b959dc3bbb786a3d844169114b55 Mon Sep 17 00:00:00 2001 From: Juan David Nicholls Cardona Date: Sat, 3 Jul 2021 17:25:12 -0500 Subject: [PATCH 2/5] Code review --- .../inappbrowser/RNInAppBrowser.java | 66 +++++++------------ 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java b/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java index 1884b4b..d0334a6 100644 --- a/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java +++ b/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java @@ -63,30 +63,23 @@ public class RNInAppBrowser { private Activity currentActivity; private static final Pattern animationIdentifierPattern = Pattern.compile("^.+:.+/"); - public void setNavigationColors(CustomTabsIntent.Builder builder, final ReadableMap options) { - if (options.hasKey(KEY_NAVIGATION_BAR_COLOR)) { - final String colorString = options.getString(KEY_NAVIGATION_BAR_COLOR); - try { - Method setNavigationBarColor = builder.getClass().getDeclaredMethod("setNavigationBarColor", int.class); - setNavigationBarColor.invoke(builder, Color.parseColor(colorString)); - } catch (Exception e) { - if (e instanceof IllegalArgumentException) { - throw new JSApplicationIllegalArgumentException( - "Invalid navigation bar color '" + colorString + "': " + e.getMessage()); - } + public Integer setColor(CustomTabsIntent.Builder builder, final ReadableMap options, String key, String method, String colorName) { + String colorString = ""; + Integer color = null; + try { + if (options.hasKey(key)) { + colorString = options.getString(key); + color = Color.parseColor(colorString); + Method findMethod = builder.getClass().getDeclaredMethod(method, int.class); + findMethod.invoke(builder, color); } - } - if (options.hasKey(KEY_NAVIGATION_BAR_DIVIDER_COLOR)) { - final String colorString = options.getString(KEY_NAVIGATION_BAR_DIVIDER_COLOR); - try { - Method setNavigationBarDividerColor = builder.getClass().getDeclaredMethod("setNavigationBarDividerColor", int.class); - setNavigationBarDividerColor.invoke(builder, Color.parseColor(colorString)); - } catch (Exception e) { - if (e instanceof IllegalArgumentException) { - throw new JSApplicationIllegalArgumentException( - "Invalid navigation bar divider color '" + colorString + "': " + e.getMessage()); - } + } catch (Exception e) { + if (e instanceof IllegalArgumentException) { + throw new JSApplicationIllegalArgumentException( + "Invalid " + colorName + " color '" + colorString + "': " + e.getMessage()); } + } finally { + return color; } } @@ -110,26 +103,13 @@ 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()); - } + final Integer toolBarColor = setColor(builder, options, KEY_TOOLBAR_COLOR, "setToolbarColor", "toolbar"); + if (toolBarColor != null) { + isLightTheme = toolbarIsLight(toolBarColor); } - setNavigationColors(builder, options); + 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)) { @@ -304,8 +284,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 getPreferredPackages(Context context) { From a9f8029937b03b624c3c02b11d48c476219fbbe6 Mon Sep 17 00:00:00 2001 From: Juan David Nicholls Cardona Date: Sat, 3 Jul 2021 17:28:37 -0500 Subject: [PATCH 3/5] Update CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c079255..033ae67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From d6083e220d28af5597d37d4da6a49baf1f651a4d Mon Sep 17 00:00:00 2001 From: Juan David Nicholls Cardona Date: Sat, 3 Jul 2021 17:31:22 -0500 Subject: [PATCH 4/5] Code review --- .../java/com/proyecto26/inappbrowser/RNInAppBrowser.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java b/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java index d0334a6..50d514f 100644 --- a/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java +++ b/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java @@ -103,9 +103,9 @@ public void open(Context context, final ReadableMap options, final Promise promi CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); isLightTheme = false; - final Integer toolBarColor = setColor(builder, options, KEY_TOOLBAR_COLOR, "setToolbarColor", "toolbar"); - if (toolBarColor != null) { - isLightTheme = toolbarIsLight(toolBarColor); + 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"); From 2c6400e3d689c1962e7a730dc49de5c2f4cf309e Mon Sep 17 00:00:00 2001 From: Juan David Nicholls Cardona Date: Sat, 3 Jul 2021 18:55:02 -0500 Subject: [PATCH 5/5] Code review --- .../java/com/proyecto26/inappbrowser/RNInAppBrowser.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java b/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java index 50d514f..745abe0 100644 --- a/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java +++ b/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java @@ -64,11 +64,10 @@ public class RNInAppBrowser { private static final Pattern animationIdentifierPattern = Pattern.compile("^.+:.+/"); public Integer setColor(CustomTabsIntent.Builder builder, final ReadableMap options, String key, String method, String colorName) { - String colorString = ""; + String colorString = options.getString(key); Integer color = null; try { - if (options.hasKey(key)) { - colorString = options.getString(key); + if (colorString != null) { color = Color.parseColor(colorString); Method findMethod = builder.getClass().getDeclaredMethod(method, int.class); findMethod.invoke(builder, color);