From 96c070495d8065e8d58beba4cd511262e3d7f940 Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Thu, 9 Aug 2018 14:32:00 +0300 Subject: [PATCH] Button color (#3713) * Revert "merging buttons fix" This reverts commit 74077bbc5592a7fd1e718cc3bab4b1012403ad91. * Revert "fix undefined buttons" This reverts commit e3b4d15a06aa96f6c4995172abbe371381c2174c. * Revert "fix e2e" This reverts commit 05b3f5808f690e74f9ba59fae2ad92efae9e464f. * Revert "Handle merge buttons style" This reverts commit 9c705402ebd3eaa1a014bdbf0428fa23ff0b022e. * Add background component with MATCH_PARENT height * temporary solution for merging button color This commit introduces two temporary options to control button colors * rightButtonColor * leftButtonColor These options can be used to color buttons. Colors defined in buttons take precedence over these two options. * Get buttonColor options from resolved options * leftButtonColor & rightButtonColor support - iOS * Disabled color * disabled buttons color support * Rebase fixes * empty commit --- .../parse/TopBarOptions.java | 30 +++- .../parse/params/Button.java | 9 +- .../presentation/StackOptionsPresenter.java | 63 ++++++--- .../TopBarButtonController.java | 8 +- .../stack/StackController.java | 2 +- .../views/topbar/TopBar.java | 8 +- .../StackOptionsPresenterTest.java | 126 +++++++++++++++-- .../views/TopBarBackgroundComponentTest.java | 2 +- lib/ios/RNNNavigationButtons.m | 12 +- lib/ios/RNNTopBarOptions.h | 5 +- lib/ios/RNNTopBarOptions.m | 23 +++- lib/src/commands/LayoutTreeCrawler.test.ts | 130 ------------------ lib/src/commands/LayoutTreeCrawler.ts | 37 ----- playground/src/screens/PushedScreen.js | 3 +- 14 files changed, 236 insertions(+), 222 deletions(-) diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/parse/TopBarOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/parse/TopBarOptions.java index 8b810f33df7..1e065e40172 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/parse/TopBarOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/parse/TopBarOptions.java @@ -43,6 +43,9 @@ public static TopBarOptions parse(TypefaceLoader typefaceLoader, JSONObject json options.elevation = FractionParser.parse(json, "elevation"); options.buttons = TopBarButtons.parse(typefaceLoader, json); + options.rightButtonColor = ColorParser.parse(json, "rightButtonColor"); + options.leftButtonColor = ColorParser.parse(json, "leftButtonColor"); + options.validate(); return options; } @@ -61,6 +64,18 @@ public static TopBarOptions parse(TypefaceLoader typefaceLoader, JSONObject json public Fraction borderHeight = new NullFraction(); public Color borderColor = new NullColor(); + // Deprecated + public Color rightButtonColor = new NullColor(); + public Color leftButtonColor = new NullColor(); + public Color rightButtonDisabledColor = new NullColor(); + public Color leftButtonDisabledColor = new NullColor(); + + public TopBarOptions copy() { + TopBarOptions result = new TopBarOptions(); + result.mergeWith(this); + return result; + } + void mergeWith(final TopBarOptions other) { title.mergeWith(other.title); subtitle.mergeWith(other.subtitle); @@ -75,10 +90,16 @@ void mergeWith(final TopBarOptions other) { if (other.borderHeight.hasValue()) borderHeight = other.borderHeight; if (other.borderColor.hasValue()) borderColor = other.borderColor; if (other.elevation.hasValue()) elevation = other.elevation; + + if (other.rightButtonColor.hasValue()) rightButtonColor = other.rightButtonColor; + if (other.leftButtonColor.hasValue()) leftButtonColor = other.leftButtonColor; + if (other.rightButtonDisabledColor.hasValue()) rightButtonDisabledColor = other.rightButtonDisabledColor; + if (other.leftButtonDisabledColor.hasValue()) leftButtonDisabledColor = other.leftButtonDisabledColor; + validate(); } - void mergeWithDefault(TopBarOptions defaultOptions) { + public TopBarOptions mergeWithDefault(TopBarOptions defaultOptions) { title.mergeWithDefault(defaultOptions.title); subtitle.mergeWithDefault(defaultOptions.subtitle); background.mergeWithDefault(defaultOptions.background); @@ -92,7 +113,14 @@ void mergeWithDefault(TopBarOptions defaultOptions) { if (!borderHeight.hasValue()) borderHeight = defaultOptions.borderHeight; if (!borderColor.hasValue()) borderColor = defaultOptions.borderColor; if (!elevation.hasValue()) elevation = defaultOptions.elevation; + + if (!rightButtonColor.hasValue()) rightButtonColor = defaultOptions.rightButtonColor; + if (!leftButtonColor.hasValue()) leftButtonColor = defaultOptions.leftButtonColor; + if (!rightButtonDisabledColor.hasValue()) rightButtonDisabledColor = defaultOptions.rightButtonDisabledColor; + if (!leftButtonDisabledColor.hasValue()) leftButtonDisabledColor = defaultOptions.leftButtonDisabledColor; + validate(); + return this; } public void validate() { diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/parse/params/Button.java b/lib/android/app/src/main/java/com/reactnativenavigation/parse/params/Button.java index dddcc71aa46..7db847a4df1 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/parse/params/Button.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/parse/params/Button.java @@ -31,7 +31,7 @@ public class Button { public Text testId = new NullText(); public Component component = new Component(); - protected static Button parseJson(JSONObject json, TypefaceLoader typefaceManager) { + private static Button parseJson(JSONObject json, TypefaceLoader typefaceManager) { Button button = new Button(); button.id = json.optString("id"); button.text = TextParser.parse(json, "text"); @@ -78,6 +78,12 @@ private static ArrayList