Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static BackButton parse(Context context, JSONObject json) {
result.disableIconTint = BoolParser.parse(json, "disableIconTint");
result.color = ThemeColour.parse(context, json.optJSONObject( "color"));
result.disabledColor = ThemeColour.parse(context, json.optJSONObject( "disabledColor"));
result.iconBackground = IconBackgroundOptions.parse(context, json.optJSONObject("iconBackground"));
result.testId = TextParser.parse(json, "testID");
result.popStackOnPress = BoolParser.parse(json, "popStackOnPress");

Expand Down Expand Up @@ -54,6 +55,7 @@ public void mergeWith(BackButton other) {
if (other.disabledColor.hasValue()) disabledColor = other.disabledColor;
if (other.disableIconTint.hasValue()) disableIconTint = other.disableIconTint;
if (other.enabled.hasValue()) enabled = other.enabled;
if (other.iconBackground.hasValue()) iconBackground = other.iconBackground;
if (other.testId.hasValue()) testId = other.testId;
if (other.popStackOnPress.hasValue()) popStackOnPress = other.popStackOnPress;
}
Expand All @@ -67,6 +69,7 @@ void mergeWithDefault(final BackButton defaultOptions) {
if (!disabledColor.hasValue()) disabledColor = defaultOptions.disabledColor;
if (!disableIconTint.hasValue()) disableIconTint = defaultOptions.disableIconTint;
if (!enabled.hasValue()) enabled = defaultOptions.enabled;
if (!iconBackground.hasValue()) iconBackground = defaultOptions.iconBackground;
if (!testId.hasValue()) testId = defaultOptions.testId;
if (!popStackOnPress.hasValue()) popStackOnPress = defaultOptions.popStackOnPress;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ open class ButtonPresenter(private val context: Context, private val button: But
fun applyNavigationIcon(toolbar: Toolbar, onPress: (ButtonOptions) -> Unit) {
iconResolver.resolve(button) { icon: Drawable ->
setIconColor(icon)
val iconWithBackground = applyIconBackgroundDrawable(icon)
toolbar.setNavigationOnClickListener { onPress(button) }
toolbar.navigationIcon = null
toolbar.navigationIcon = icon
toolbar.navigationIcon = iconWithBackground
setLeftButtonTestId(toolbar)
if (button.accessibilityLabel.hasValue()) toolbar.navigationContentDescription = button.accessibilityLabel.get()
}
Expand Down
2 changes: 2 additions & 0 deletions ios/RNNBackButtonOptions.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "RNNOptions.h"
#import "RNNIconBackgroundOptions.h"

@interface RNNBackButtonOptions : RNNOptions

Expand All @@ -16,6 +17,7 @@
@property(nonatomic, strong) Text *displayMode;
@property(nonatomic, strong) Text *identifier;
@property(nonatomic, strong) Bool *popStackOnPress;
@property(nonatomic, strong) RNNIconBackgroundOptions *iconBackground;

- (BOOL)hasValue;

Expand Down
5 changes: 4 additions & 1 deletion ios/RNNBackButtonOptions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ - (instancetype)initWithDict:(NSDictionary *)dict {
self.enableMenu = [BoolParser parse:dict key:@"enableMenu"];
self.displayMode = [TextParser parse:dict key:@"displayMode"];
self.popStackOnPress = [BoolParser parse:dict key:@"popStackOnPress"];
self.iconBackground = [[RNNIconBackgroundOptions alloc] initWithDict:dict[@"iconBackground"] enabled:nil];

return self;
}

- (void)mergeOptions:(RNNBackButtonOptions *)options {
[self.iconBackground mergeOptions:options.iconBackground];
if (options.identifier.hasValue)
self.identifier = options.identifier;
if (options.icon.hasValue)
Expand Down Expand Up @@ -57,7 +59,8 @@ - (void)mergeOptions:(RNNBackButtonOptions *)options {
- (BOOL)hasValue {
return self.icon.hasValue || self.showTitle.hasValue || self.color.hasValue ||
self.fontFamily.hasValue || self.fontSize.hasValue || self.title.hasValue ||
self.enableMenu.hasValue || self.displayMode.hasValue || self.sfSymbol.hasValue;
self.enableMenu.hasValue || self.displayMode.hasValue || self.sfSymbol.hasValue ||
self.iconBackground.hasValue;
}

@end
16 changes: 16 additions & 0 deletions ios/TopBarPresenter.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "TopBarPresenter.h"
#import "RNNFontAttributesCreator.h"
#import "RNNUIBarBackButtonItem.h"
#import "RNNIconDrawer.h"
#import "UIColor+RNNUtils.h"
#import "UIImage+utils.h"
#import "UINavigationController+RNNOptions.h"
Expand Down Expand Up @@ -179,6 +180,21 @@ - (void)setBackButtonOptions:(RNNBackButtonOptions *)backButtonOptions {
: icon;
}

// Apply iconBackground if present
if (backButtonOptions.iconBackground.hasValue && icon) {
UIColor *backgroundColor = [backButtonOptions.iconBackground.color withDefault:UIColor.clearColor];
CGFloat cornerRadius = [backButtonOptions.iconBackground.cornerRadius withDefault:@(0)].floatValue;
CGFloat width = [backButtonOptions.iconBackground.width withDefault:@(icon.size.width)].floatValue;
CGFloat height = [backButtonOptions.iconBackground.height withDefault:@(icon.size.height)].floatValue;

RNNIconDrawer *iconDrawer = [[RNNIconDrawer alloc] init];
icon = [iconDrawer draw:icon
imageColor:color
backgroundColor:backgroundColor
size:CGSizeMake(width, height)
cornerRadius:cornerRadius];
}

[self setBackIndicatorImage:icon withColor:color];

title = title ? title : (previousNavigationItem.title ? previousNavigationItem.title : @"");
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ export interface OptionsTopBarBackButton {
* values, in that case the closest one is chosen.
*/
fontWeight?: FontWeight;
/**
* Set icon background style
*/
iconBackground?: IconBackgroundOptions;
/**
* Set testID for reference in E2E tests
*/
Expand Down