From 793fdf531b79c6e0617247e9c828c19b8d8d06be Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Wed, 2 Nov 2022 15:30:36 +0200 Subject: [PATCH] Support merging icon background color --- .../options/TopBarOptions.java | 8 +++++ .../viewcontrollers/stack/StackPresenter.java | 14 +++++--- .../stack/topbar/button/ButtonController.kt | 2 ++ .../stack/topbar/button/ButtonPresenter.kt | 5 +++ .../utils/ButtonPresenterTest.java | 19 ++++++++++ lib/ios/RNNButtonOptions.h | 4 ++- lib/ios/RNNButtonOptions.m | 10 ++++-- lib/ios/RNNButtonsPresenter.h | 8 +++-- lib/ios/RNNButtonsPresenter.m | 20 ++++++++--- lib/ios/RNNComponentPresenter.m | 12 +++++-- lib/ios/RNNIconDrawer.m | 2 +- lib/ios/RNNTitleViewHelper.h | 8 +++++ lib/ios/RNNTitleViewHelper.m | 16 +++++++++ lib/ios/RNNTopBarOptions.h | 2 ++ lib/ios/RNNTopBarOptions.m | 6 ++++ lib/ios/RNNUIBarButtonItem.h | 3 +- lib/ios/RNNUIBarButtonItem.m | 35 +++++++++++++++---- lib/ios/TopBarTitlePresenter.m | 7 ++++ lib/src/interfaces/Options.ts | 2 ++ .../NavigationTests/RNNButtonsPresenterTest.m | 8 ++--- 20 files changed, 163 insertions(+), 28 deletions(-) diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarOptions.java index f8878985f9e..9a731004854 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarOptions.java @@ -50,6 +50,8 @@ public static TopBarOptions parse(Context context, TypefaceLoader typefaceLoader options.leftButtonColor = ThemeColour.parse(context, json.optJSONObject("leftButtonColor")); options.leftButtonDisabledColor = ThemeColour.parse(context, json.optJSONObject("leftButtonDisabledColor")); options.rightButtonDisabledColor = ThemeColour.parse(context, json.optJSONObject("rightButtonDisabledColor")); + options.leftButtonBackgroundColor = ThemeColour.parse(context, json.optJSONObject("leftButtonBackgroundColor")); + options.rightButtonBackgroundColor = ThemeColour.parse(context, json.optJSONObject("rightButtonBackgroundColor")); options.validate(); return options; @@ -76,6 +78,8 @@ public static TopBarOptions parse(Context context, TypefaceLoader typefaceLoader public ThemeColour leftButtonColor = new NullThemeColour(); public ThemeColour rightButtonDisabledColor = new NullThemeColour(); public ThemeColour leftButtonDisabledColor = new NullThemeColour(); + public ThemeColour rightButtonBackgroundColor = new NullThemeColour(); + public ThemeColour leftButtonBackgroundColor = new NullThemeColour(); public TopBarOptions copy() { TopBarOptions result = new TopBarOptions(); @@ -94,6 +98,8 @@ void mergeWith(final TopBarOptions other) { if (other.leftButtonColor.hasValue()) leftButtonColor = other.leftButtonColor; if (other.rightButtonDisabledColor.hasValue()) rightButtonDisabledColor = other.rightButtonDisabledColor; if (other.leftButtonDisabledColor.hasValue()) leftButtonDisabledColor = other.leftButtonDisabledColor; + if (other.rightButtonBackgroundColor.hasValue()) rightButtonBackgroundColor = other.rightButtonBackgroundColor; + if (other.leftButtonBackgroundColor.hasValue()) rightButtonBackgroundColor = other.rightButtonBackgroundColor; if (other.testId.hasValue()) testId = other.testId; if (other.visible.hasValue()) visible = other.visible; @@ -122,6 +128,8 @@ public TopBarOptions mergeWithDefault(TopBarOptions defaultOptions) { if (!leftButtonColor.hasValue()) leftButtonColor = defaultOptions.leftButtonColor; if (!rightButtonDisabledColor.hasValue()) rightButtonDisabledColor = defaultOptions.rightButtonDisabledColor; if (!leftButtonDisabledColor.hasValue()) leftButtonDisabledColor = defaultOptions.leftButtonDisabledColor; + if (!rightButtonBackgroundColor.hasValue()) rightButtonBackgroundColor = defaultOptions.rightButtonBackgroundColor; + if (!leftButtonBackgroundColor.hasValue()) rightButtonBackgroundColor = defaultOptions.rightButtonBackgroundColor; if (!visible.hasValue()) visible = defaultOptions.visible; if (!animate.hasValue()) animate = defaultOptions.animate; diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackPresenter.java b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackPresenter.java index a14a038c9a6..e41e0a2d39a 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackPresenter.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackPresenter.java @@ -458,12 +458,12 @@ private void mergeOrientation(OrientationOptions orientationOptions) { private void mergeButtons(TopBarOptions options, TopBarOptions optionsToMerge, View child, StackController stack) { mergeRightButtons(options, optionsToMerge.buttons, child); mergeLeftButton(options, optionsToMerge.buttons, child); - mergeLeftButtonsColor(child, optionsToMerge.leftButtonColor, optionsToMerge.leftButtonDisabledColor); - mergeRightButtonsColor(child, optionsToMerge.rightButtonColor, optionsToMerge.rightButtonDisabledColor); + mergeLeftButtonsColor(child, optionsToMerge.leftButtonColor, optionsToMerge.leftButtonDisabledColor, optionsToMerge.leftButtonBackgroundColor); + mergeRightButtonsColor(child, optionsToMerge.rightButtonColor, optionsToMerge.rightButtonDisabledColor, optionsToMerge.rightButtonBackgroundColor); mergeBackButton(optionsToMerge.buttons, stack); } - private void mergeLeftButtonsColor(View child, ThemeColour color, ThemeColour disabledColor) { + private void mergeLeftButtonsColor(View child, ThemeColour color, ThemeColour disabledColor, ThemeColour backgroundColor) { if (color.hasValue() || disabledColor.hasValue()) { Map stringButtonControllerMap = componentLeftButtons.get(child); if (stringButtonControllerMap != null) { @@ -474,12 +474,15 @@ private void mergeLeftButtonsColor(View child, ThemeColour color, ThemeColour di if (disabledColor.hasValue()) { btnController.applyDisabledColor(topBarController.getView().getLeftButtonBar(), disabledColor); } + if (backgroundColor.hasValue()) { + btnController.applyBackgroundColor(topBarController.getView().getLeftButtonBar(), backgroundColor); + } }); } } } - private void mergeRightButtonsColor(View child, ThemeColour color, ThemeColour disabledColor) { + private void mergeRightButtonsColor(View child, ThemeColour color, ThemeColour disabledColor, ThemeColour backgroundColor) { if (color.hasValue() || disabledColor.hasValue()) { Map stringButtonControllerMap = componentRightButtons.get(child); if (stringButtonControllerMap != null) { @@ -490,6 +493,9 @@ private void mergeRightButtonsColor(View child, ThemeColour color, ThemeColour d if (disabledColor.hasValue()) { btnController.applyDisabledColor(topBarController.getView().getRightButtonBar(), disabledColor); } + if (backgroundColor.hasValue()) { + btnController.applyBackgroundColor(topBarController.getView().getRightButtonBar(), backgroundColor); + } }); } } diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonController.kt b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonController.kt index b18cb11b987..384c93fc559 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonController.kt +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonController.kt @@ -81,6 +81,8 @@ open class ButtonController(activity: Activity, open fun applyDisabledColor(toolbar: Toolbar, disabledColour: ThemeColour) = this.menuItem?.let { presenter.applyDisabledColor(toolbar, it, disabledColour) } + open fun applyBackgroundColor(toolbar: Toolbar, color: ThemeColour) = this.menuItem?.let { presenter.applyBackgroundColor(toolbar, it, color) } + fun addToMenu(buttonBar: ButtonBar, order: Int) { if (button.component.hasValue() && buttonBar.containsButton(menuItem, order)) return buttonBar.menu.removeItem(button.intId) diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonPresenter.kt b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonPresenter.kt index 7fd4637a2d3..93b3b8e5690 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonPresenter.kt +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonPresenter.kt @@ -71,6 +71,11 @@ open class ButtonPresenter(private val context: Context, private val button: But } } + fun applyBackgroundColor(toolbar: Toolbar, menuItem: MenuItem, color: ThemeColour) { + button.iconBackground.color = color + applyIcon(menuItem) + } + private fun applyAccessibilityLabel(menuItem: MenuItem) { if (button.accessibilityLabel.hasValue()) { if (button.component.hasValue()) { diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/utils/ButtonPresenterTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/utils/ButtonPresenterTest.java index 329c4dc7627..a32c64b76fd 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/utils/ButtonPresenterTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/utils/ButtonPresenterTest.java @@ -117,6 +117,25 @@ public void applyColor_shouldChangeColor() { assertThat(findButtonView().getCurrentTextColor()).isEqualTo(Color.RED); } + @Test + public void applyBackgroundColor_shouldChangeBackgroundColor() { + IconBackgroundDrawable mockD = mock(IconBackgroundDrawable.class); + initUUt(ImageLoaderMock.mock(mockD)); + button.enabled = new Bool(true); + button.icon = new Text("icon"); + button.color = new ThemeColour(new Colour(Color.RED), new Colour(Color.RED)); + IconBackgroundOptions iconBackground = new IconBackgroundOptions(); + iconBackground.color = new ThemeColour(new Colour(Color.GREEN),new Colour(Color.GREEN)); + button.iconBackground = iconBackground; + MenuItem menuItem = spy(addMenuButton()); + uut.applyOptions(titleBar, menuItem, buttonController::getView); + + assertThat(((IconBackgroundDrawable)menuItem.getIcon()).getBackgroundColor()).isEqualTo(Color.GREEN); + + uut.applyBackgroundColor(titleBar, menuItem, new ThemeColour(new Colour(Color.BLACK),new Colour(Color.BLACK))); + assertThat(((IconBackgroundDrawable)menuItem.getIcon()).getBackgroundColor()).isEqualTo(Color.BLACK); + } + @Test public void applyOptions_shouldChangeIconColorTint() { IconBackgroundDrawable mockD = mock(IconBackgroundDrawable.class); diff --git a/lib/ios/RNNButtonOptions.h b/lib/ios/RNNButtonOptions.h index ba761192db1..27dd551d94f 100644 --- a/lib/ios/RNNButtonOptions.h +++ b/lib/ios/RNNButtonOptions.h @@ -25,7 +25,7 @@ - (RNNButtonOptions *)withDefault:(RNNButtonOptions *)defaultOptions; -- (UIColor *)resolveColor; +- (Color *)resolveColor; - (RNNButtonOptions *)withDefaultColor:(Color *)color disabledColor:(Color *)disabledColor; @@ -33,4 +33,6 @@ - (BOOL)isEnabled; +- (UIControlState)state; + @end diff --git a/lib/ios/RNNButtonOptions.m b/lib/ios/RNNButtonOptions.m index a3119131d8d..98be424b7a2 100644 --- a/lib/ios/RNNButtonOptions.m +++ b/lib/ios/RNNButtonOptions.m @@ -93,11 +93,11 @@ - (BOOL)isEnabled { return [self.enabled withDefault:YES]; } -- (UIColor *)resolveColor { +- (Color *)resolveColor { if (![_enabled withDefault:YES] && _disabledColor.hasValue) - return _disabledColor.get; + return _disabledColor; else - return [_color withDefault:nil]; + return _color; } - (RNNButtonOptions *)withDefault:(RNNButtonOptions *)defaultOptions { @@ -116,4 +116,8 @@ - (RNNButtonOptions *)withDefaultColor:(Color *)color disabledColor:(Color *)dis return self; } +- (UIControlState)state { + return self.isEnabled ? UIControlStateNormal : UIControlStateDisabled; +} + @end diff --git a/lib/ios/RNNButtonsPresenter.h b/lib/ios/RNNButtonsPresenter.h index 5c07d798fe9..cb397a28bd6 100644 --- a/lib/ios/RNNButtonsPresenter.h +++ b/lib/ios/RNNButtonsPresenter.h @@ -20,9 +20,13 @@ defaultDisabledColor:(Color *)defaultDisabledColor animated:(BOOL)animated; -- (void)applyLeftButtonsColor:(UIColor *)color; +- (void)applyLeftButtonsColor:(Color *)color; -- (void)applyRightButtonsColor:(UIColor *)color; +- (void)applyRightButtonsColor:(Color *)color; + +- (void)applyLeftButtonsBackgroundColor:(Color *)color; + +- (void)applyRightButtonsBackgroundColor:(Color *)color; - (void)componentWillAppear; diff --git a/lib/ios/RNNButtonsPresenter.m b/lib/ios/RNNButtonsPresenter.m index c426fea8e85..3132df061c3 100644 --- a/lib/ios/RNNButtonsPresenter.m +++ b/lib/ios/RNNButtonsPresenter.m @@ -47,15 +47,27 @@ - (void)applyRightButtons:(NSArray *)rightButtons defaultDisabledColor:defaultDisabledColor]; } -- (void)applyLeftButtonsColor:(UIColor *)color { +- (void)applyLeftButtonsColor:(Color *)color { for (RNNUIBarButtonItem *button in self.viewController.navigationItem.leftBarButtonItems) { - [button applyColor:color]; + [button mergeColor:color]; } } -- (void)applyRightButtonsColor:(UIColor *)color { +- (void)applyRightButtonsColor:(Color *)color { for (RNNUIBarButtonItem *button in self.viewController.navigationItem.rightBarButtonItems) { - [button applyColor:color]; + [button mergeColor:color]; + } +} + +- (void)applyRightButtonsBackgroundColor:(Color *)color { + for (RNNUIBarButtonItem *button in self.viewController.navigationItem.rightBarButtonItems) { + [button mergeBackgroundColor:color]; + } +} + +- (void)applyLeftButtonsBackgroundColor:(Color *)color { + for (RNNUIBarButtonItem *button in self.viewController.navigationItem.leftBarButtonItems) { + [button mergeBackgroundColor:color]; } } diff --git a/lib/ios/RNNComponentPresenter.m b/lib/ios/RNNComponentPresenter.m index c41bfc86a26..ae6187eafc5 100644 --- a/lib/ios/RNNComponentPresenter.m +++ b/lib/ios/RNNComponentPresenter.m @@ -209,11 +209,19 @@ - (void)mergeOptions:(RNNNavigationOptions *)mergeOptions } if (mergeOptions.topBar.leftButtonColor.hasValue) { - [_buttonsPresenter applyLeftButtonsColor:mergeOptions.topBar.leftButtonColor.get]; + [_buttonsPresenter applyLeftButtonsColor:mergeOptions.topBar.leftButtonColor]; } if (mergeOptions.topBar.rightButtonColor.hasValue) { - [_buttonsPresenter applyRightButtonsColor:mergeOptions.topBar.rightButtonColor.get]; + [_buttonsPresenter applyRightButtonsColor:mergeOptions.topBar.rightButtonColor]; + } + + if (mergeOptions.topBar.rightButtonBackgroundColor.hasValue) { + [_buttonsPresenter applyRightButtonsBackgroundColor:mergeOptions.topBar.rightButtonBackgroundColor]; + } + + if (mergeOptions.topBar.leftButtonBackgroundColor.hasValue) { + [_buttonsPresenter applyLeftButtonsBackgroundColor:mergeOptions.topBar.leftButtonBackgroundColor]; } if (mergeOptions.overlay.interceptTouchOutside.hasValue) { diff --git a/lib/ios/RNNIconDrawer.m b/lib/ios/RNNIconDrawer.m index 424cdbcd60a..a787d3e1b4a 100644 --- a/lib/ios/RNNIconDrawer.m +++ b/lib/ios/RNNIconDrawer.m @@ -29,7 +29,7 @@ - (UIImage *)draw:(UIImage *)image UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); - return [newImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; + return newImage; } @end diff --git a/lib/ios/RNNTitleViewHelper.h b/lib/ios/RNNTitleViewHelper.h index c4f7a270bdf..c42ee4c929c 100644 --- a/lib/ios/RNNTitleViewHelper.h +++ b/lib/ios/RNNTitleViewHelper.h @@ -8,6 +8,10 @@ @property(nonatomic, strong) UILabel *subtitleLabel; +- (void)setTitleColor:(UIColor *)color; + +- (void)setSubtitleColor:(UIColor *)color; + @end @interface RNNTitleViewHelper : NSObject @@ -21,4 +25,8 @@ - (void)setup; +- (void)setTitleColor:(UIColor *)color; + +- (void)setSubtitleColor:(UIColor *)color; + @end diff --git a/lib/ios/RNNTitleViewHelper.m b/lib/ios/RNNTitleViewHelper.m index a62e4d4c9fe..0a5a43b61cf 100644 --- a/lib/ios/RNNTitleViewHelper.m +++ b/lib/ios/RNNTitleViewHelper.m @@ -16,6 +16,14 @@ - (void)layoutSubviews { self.frame.size.width, _subtitleLabel.frame.size.height)]; } +- (void)setTitleColor:(UIColor *)color { + _titleLabel.textColor = color; +} + +- (void)setSubtitleColor:(UIColor *)color { + _subtitleLabel.textColor = color; +} + @end @interface RNNTitleViewHelper () @@ -170,4 +178,12 @@ - (UILabel *)setupTitle { return titleLabel; } +- (void)setTitleColor:(UIColor *)color { + [_titleView setTitleColor:color]; +} + +- (void)setSubtitleColor:(UIColor *)color { + [_titleView setSubtitleColor:color]; +} + @end diff --git a/lib/ios/RNNTopBarOptions.h b/lib/ios/RNNTopBarOptions.h index bc66ff8fc16..65486393372 100644 --- a/lib/ios/RNNTopBarOptions.h +++ b/lib/ios/RNNTopBarOptions.h @@ -20,6 +20,8 @@ @property(nonatomic, strong) Color *rightButtonColor; @property(nonatomic, strong) Color *leftButtonDisabledColor; @property(nonatomic, strong) Color *rightButtonDisabledColor; +@property(nonatomic, strong) Color *leftButtonBackgroundColor; +@property(nonatomic, strong) Color *rightButtonBackgroundColor; @property(nonatomic, strong) Bool *drawBehind; @property(nonatomic, strong) Bool *noBorder; @property(nonatomic, strong) Color *borderColor; diff --git a/lib/ios/RNNTopBarOptions.m b/lib/ios/RNNTopBarOptions.m index 432606d6736..0eb7c220a4a 100644 --- a/lib/ios/RNNTopBarOptions.m +++ b/lib/ios/RNNTopBarOptions.m @@ -14,6 +14,8 @@ - (instancetype)initWithDict:(NSDictionary *)dict { self.rightButtonColor = [ColorParser parse:dict key:@"rightButtonColor"]; self.leftButtonDisabledColor = [ColorParser parse:dict key:@"leftButtonDisabledColor"]; self.rightButtonDisabledColor = [ColorParser parse:dict key:@"rightButtonDisabledColor"]; + self.leftButtonBackgroundColor = [ColorParser parse:dict key:@"leftButtonBackgroundColor"]; + self.rightButtonBackgroundColor = [ColorParser parse:dict key:@"rightButtonBackgroundColor"]; self.drawBehind = [BoolParser parse:dict key:@"drawBehind"]; self.noBorder = [BoolParser parse:dict key:@"noBorder"]; self.borderColor = [ColorParser parse:dict key:@"borderColor"]; @@ -63,6 +65,10 @@ - (void)mergeOptions:(RNNTopBarOptions *)options { self.leftButtonDisabledColor = options.leftButtonDisabledColor; if (options.rightButtonDisabledColor.hasValue) self.rightButtonDisabledColor = options.rightButtonDisabledColor; + if (options.leftButtonBackgroundColor.hasValue) + self.leftButtonBackgroundColor = options.leftButtonBackgroundColor; + if (options.rightButtonBackgroundColor.hasValue) + self.rightButtonBackgroundColor = options.rightButtonBackgroundColor; if (options.drawBehind.hasValue) self.drawBehind = options.drawBehind; if (options.noBorder.hasValue) diff --git a/lib/ios/RNNUIBarButtonItem.h b/lib/ios/RNNUIBarButtonItem.h index 47ffde69581..8751652e9b7 100644 --- a/lib/ios/RNNUIBarButtonItem.h +++ b/lib/ios/RNNUIBarButtonItem.h @@ -26,7 +26,8 @@ typedef void (^RNNButtonPressCallback)(NSString *buttonId); - (instancetype)initWithSystemItem:(RNNButtonOptions *)buttonOptions onPress:(RNNButtonPressCallback)onPress; -- (void)applyColor:(UIColor *)color; +- (void)mergeColor:(Color *)color; +- (void)mergeBackgroundColor:(Color *)color; - (void)notifyWillAppear; - (void)notifyDidAppear; diff --git a/lib/ios/RNNUIBarButtonItem.m b/lib/ios/RNNUIBarButtonItem.m index 02c9cab1516..30138d205c0 100644 --- a/lib/ios/RNNUIBarButtonItem.m +++ b/lib/ios/RNNUIBarButtonItem.m @@ -11,7 +11,10 @@ @interface RNNUIBarButtonItem () @end -@implementation RNNUIBarButtonItem +@implementation RNNUIBarButtonItem { + RNNIconCreator* _iconCreator; + RNNButtonOptions* _buttonOptions; +} - (instancetype)init { self = [super init]; @@ -52,7 +55,8 @@ - (instancetype)initWithIcon:(RNNButtonOptions *)buttonOptions - (instancetype)initCustomIcon:(RNNButtonOptions *)buttonOptions iconCreator:(RNNIconCreator *)iconCreator onPress:(RNNButtonPressCallback)onPress { - UIImage *icon = [iconCreator create:buttonOptions]; + _iconCreator = iconCreator; + UIImage *icon = [_iconCreator create:buttonOptions]; UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, icon.size.width, icon.size.height)]; [button addTarget:self @@ -125,6 +129,7 @@ - (instancetype)initWithSystemItem:(RNNButtonOptions *)buttonOptions } - (void)applyOptions:(RNNButtonOptions *)buttonOptions { + _buttonOptions = buttonOptions; self.buttonId = buttonOptions.identifier.get; self.accessibilityLabel = [buttonOptions.accessibilityLabel withDefault:nil]; self.enabled = [buttonOptions.enabled withDefault:YES]; @@ -134,17 +139,35 @@ - (void)applyOptions:(RNNButtonOptions *)buttonOptions { [self applyDisabledTitleTextAttributes:buttonOptions]; } -- (void)applyColor:(UIColor *)color { - if (color) { +- (void)applyColor:(Color *)color { + if (color.hasValue) { NSMutableDictionary *titleTextAttributes = [NSMutableDictionary dictionaryWithDictionary:[self titleTextAttributesForState:UIControlStateNormal]]; - [titleTextAttributes setValue:color forKey:NSForegroundColorAttributeName]; + [titleTextAttributes setValue:color.get forKey:NSForegroundColorAttributeName]; [self setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal]; [self setTitleTextAttributes:titleTextAttributes forState:UIControlStateHighlighted]; } else self.image = [self.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; - self.tintColor = color; + self.tintColor = color.get; +} + +- (void)mergeBackgroundColor:(Color *)color { + _buttonOptions.iconBackground.color = color; + [self redrawIcon]; +} + +- (void)mergeColor:(Color *)color { + _buttonOptions.color = color; + [self applyColor:color]; + [self redrawIcon]; +} + +- (void)redrawIcon { + if (_buttonOptions.icon.hasValue && [self.customView isKindOfClass:UIButton.class]) { + UIImage* icon = [_iconCreator create:_buttonOptions]; + [(UIButton *)self.customView setImage:icon forState:_buttonOptions.state]; + } } - (void)applyTitleTextAttributes:(RNNButtonOptions *)button { diff --git a/lib/ios/TopBarTitlePresenter.m b/lib/ios/TopBarTitlePresenter.m index df444241087..9741b132114 100644 --- a/lib/ios/TopBarTitlePresenter.m +++ b/lib/ios/TopBarTitlePresenter.m @@ -33,6 +33,13 @@ - (void)mergeOptions:(RNNTopBarOptions *)options [self removeTitleComponents]; self.boundViewController.navigationItem.title = resolvedOptions.title.text.get; } + + if (options.title.color.hasValue) { + [_titleViewHelper setTitleColor:options.title.color.get]; + } + if (options.subtitle.color.hasValue) { + [_titleViewHelper setSubtitleColor:options.subtitle.color.get]; + } } - (void)setTitleViewWithSubtitle:(RNNTopBarOptions *)options { diff --git a/lib/src/interfaces/Options.ts b/lib/src/interfaces/Options.ts index a8e219677a2..ef5db9d3863 100644 --- a/lib/src/interfaces/Options.ts +++ b/lib/src/interfaces/Options.ts @@ -637,6 +637,8 @@ export interface OptionsTopBar { leftButtonColor?: Color; rightButtonColor?: Color; + leftButtonBackgroundColor?: Color; + rightButtonBackgroundColor?: Color; leftButtonDisabledColor?: Color; rightButtonDisabledColor?: Color; /** diff --git a/playground/ios/NavigationTests/RNNButtonsPresenterTest.m b/playground/ios/NavigationTests/RNNButtonsPresenterTest.m index 54b981561f7..c26edb25937 100644 --- a/playground/ios/NavigationTests/RNNButtonsPresenterTest.m +++ b/playground/ios/NavigationTests/RNNButtonsPresenterTest.m @@ -59,7 +59,7 @@ - (void)testApplyLeftButtonColor_shouldApplyTintColor { RNNButtonOptions *button = [self buttonWithDict:@{@"id" : @"buttonId"}]; button.icon = [Image withValue:UIImage.new]; [_uut applyLeftButtons:@[ button ] defaultColor:nil defaultDisabledColor:nil animated:NO]; - [_uut applyLeftButtonsColor:UIColor.redColor]; + [_uut applyLeftButtonsColor:[Color withValue:UIColor.redColor]]; XCTAssertEqual(_viewController.navigationItem.leftBarButtonItems.firstObject.tintColor, UIColor.redColor); } @@ -67,7 +67,7 @@ - (void)testApplyLeftButtonColor_shouldApplyTintColor { - (void)testApplyLeftButtonColor_shouldApplyTextAttributesColor { RNNButtonOptions *button = [self buttonWithDict:@{@"id" : @"buttonId", @"text" : @"title"}]; [_uut applyLeftButtons:@[ button ] defaultColor:nil defaultDisabledColor:nil animated:NO]; - [_uut applyLeftButtonsColor:UIColor.redColor]; + [_uut applyLeftButtonsColor:[Color withValue:UIColor.redColor]]; XCTAssertEqual([[_viewController.navigationItem.leftBarButtonItems.firstObject titleTextAttributesForState:UIControlStateNormal] valueForKey:NSForegroundColorAttributeName], @@ -82,7 +82,7 @@ - (void)testApplyRightButtonColor_shouldApplyTintColor { RNNButtonOptions *button = [self buttonWithDict:@{@"id" : @"buttonId"}]; button.icon = [Image withValue:UIImage.new]; [_uut applyRightButtons:@[ button ] defaultColor:nil defaultDisabledColor:nil animated:NO]; - [_uut applyRightButtonsColor:UIColor.redColor]; + [_uut applyRightButtonsColor:[Color withValue:UIColor.redColor]]; XCTAssertEqual(_viewController.navigationItem.rightBarButtonItems.firstObject.tintColor, UIColor.redColor); } @@ -90,7 +90,7 @@ - (void)testApplyRightButtonColor_shouldApplyTintColor { - (void)testApplyRightButtonColor_shouldApplyTextAttributesColor { RNNButtonOptions *button = [self buttonWithDict:@{@"id" : @"buttonId", @"text" : @"title"}]; [_uut applyRightButtons:@[ button ] defaultColor:nil defaultDisabledColor:nil animated:NO]; - [_uut applyRightButtonsColor:UIColor.redColor]; + [_uut applyRightButtonsColor:[Color withValue:UIColor.redColor]]; XCTAssertEqual([[_viewController.navigationItem.rightBarButtonItems.firstObject titleTextAttributesForState:UIControlStateNormal] valueForKey:NSForegroundColorAttributeName],