Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SF Symbols support to bottom tab and top bar's back button #7271

Merged
merged 6 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions lib/ios/RNNBackButtonOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@interface RNNBackButtonOptions : RNNOptions

@property(nonatomic, strong) Image *icon;
@property(nonatomic, strong) Text *sfSymbol;
@property(nonatomic, strong) Text *title;
@property(nonatomic, strong) Text *fontFamily;
@property(nonatomic, strong) Number *fontSize;
Expand Down
5 changes: 4 additions & 1 deletion lib/ios/RNNBackButtonOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ - (instancetype)initWithDict:(NSDictionary *)dict {

self.identifier = [TextParser parse:dict key:@"identifier"];
self.icon = [ImageParser parse:dict key:@"icon"];
self.sfSymbol = [TextParser parse:dict key:@"sfSymbol"];
self.title = [TextParser parse:dict key:@"title"];
self.transition = [TextParser parse:dict key:@"transition"];
self.color = [ColorParser parse:dict key:@"color"];
Expand Down Expand Up @@ -49,12 +50,14 @@ - (void)mergeOptions:(RNNBackButtonOptions *)options {
self.displayMode = options.displayMode;
if (options.popStackOnPress.hasValue)
self.popStackOnPress = options.popStackOnPress;
if (options.sfSymbol.hasValue)
self.sfSymbol = options.sfSymbol;
}

- (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.enableMenu.hasValue || self.displayMode.hasValue || self.sfSymbol.hasValue;
}

@end
2 changes: 2 additions & 0 deletions lib/ios/RNNBottomTabOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
@property(nonatomic, strong) Number *fontSize;
@property(nonatomic, strong) Bool *visible;
@property(nonatomic, strong) Bool *selectTabOnPress;
@property(nonatomic, strong) Text *sfSymbol;
@property(nonatomic, strong) Text *sfSelectedSymbol;

- (BOOL)hasValue;

Expand Down
8 changes: 7 additions & 1 deletion lib/ios/RNNBottomTabOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ - (instancetype)initWithDict:(NSDictionary *)dict {
self.fontSize = [NumberParser parse:dict key:@"fontSize"];
self.visible = [BoolParser parse:dict key:@"visible"];
self.selectTabOnPress = [BoolParser parse:dict key:@"selectTabOnPress"];
self.sfSymbol = [TextParser parse:dict key:@"sfSymbol"];
self.sfSelectedSymbol = [TextParser parse:dict key:@"sfSelectedSymbol"];

return self;
}
Expand Down Expand Up @@ -70,6 +72,10 @@ - (void)mergeOptions:(RNNBottomTabOptions *)options {
self.visible = options.visible;
if (options.selectTabOnPress.hasValue)
self.selectTabOnPress = options.selectTabOnPress;
if (options.sfSymbol.hasValue)
self.sfSymbol = options.sfSymbol;
if (options.sfSelectedSymbol.hasValue)
self.sfSelectedSymbol = options.sfSelectedSymbol;
}

- (BOOL)hasValue {
Expand All @@ -78,7 +84,7 @@ - (BOOL)hasValue {
self.testID.hasValue || self.icon.hasValue || self.selectedIcon.hasValue ||
self.iconColor.hasValue || self.selectedIconColor.hasValue ||
self.selectedTextColor.hasValue || self.iconInsets.hasValue || self.textColor.hasValue ||
self.visible.hasValue || self.selectTabOnPress.hasValue;
self.visible.hasValue || self.selectTabOnPress.hasValue || self.sfSymbol.hasValue || self.sfSelectedSymbol.hasValue;
}

@end
10 changes: 10 additions & 0 deletions lib/ios/RNNTabBarItemCreator.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ + (UITabBarItem *)createTabBarItem:(RNNBottomTabOptions *)bottomTabOptions
UIColor *iconColor = [bottomTabOptions.iconColor withDefault:nil];
UIColor *selectedIconColor = [bottomTabOptions.selectedIconColor withDefault:iconColor];

if (@available(iOS 13.0, *)) {
if (bottomTabOptions.sfSymbol.hasValue) {
icon = [UIImage systemImageNamed: [bottomTabOptions.sfSymbol withDefault:nil]];
}

if (bottomTabOptions.sfSelectedSymbol.hasValue) {
selectedIcon = [UIImage systemImageNamed: [bottomTabOptions.sfSelectedSymbol withDefault:nil]];
}
}

tabItem.image = [self getIconImage:icon withTint:iconColor];
tabItem.selectedImage = [self getSelectedIconImage:selectedIcon
selectedIconColor:selectedIconColor];
Expand Down
16 changes: 13 additions & 3 deletions lib/ios/TopBarPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ - (UINavigationItemBackButtonDisplayMode)getBackButtonDisplayMode:(NSString *)di

- (void)setBackButtonOptions:(RNNBackButtonOptions *)backButtonOptions {
UIImage *icon = [backButtonOptions.icon withDefault:nil];
UIImage *sfSymbol = [UIImage systemImageNamed:[backButtonOptions.sfSymbol withDefault:nil]];
svbutko marked this conversation as resolved.
Show resolved Hide resolved
UIColor *color = [backButtonOptions.color withDefault:nil];
NSString *title = [backButtonOptions.title withDefault:nil];
BOOL showTitle = [backButtonOptions.showTitle withDefault:YES];
Expand All @@ -160,9 +161,18 @@ - (void)setBackButtonOptions:(RNNBackButtonOptions *)backButtonOptions {
UIBarButtonItem *backItem = [[RNNUIBarBackButtonItem alloc] initWithOptions:backButtonOptions];
UINavigationItem *previousNavigationItem = previousViewControllerInStack.navigationItem;

icon = color ? [[icon withTintColor:color]
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
: icon;

if (@available(iOS 13.0, *)) {
if (backButtonOptions.sfSymbol.hasValue) {
icon = color ? [sfSymbol imageWithTintColor:color renderingMode:UIImageRenderingModeAlwaysOriginal]
: [sfSymbol imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
} else {
icon = color ? [[icon withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] : icon;
}
} else {
icon = color ? [[icon withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] : icon;
}

[self setBackIndicatorImage:icon withColor:color];

title = title ? title : (previousNavigationItem.title ? previousNavigationItem.title : @"");
Expand Down
15 changes: 15 additions & 0 deletions lib/src/interfaces/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ export interface OptionsTopBarBackButton {
* Image to show as the back button
*/
icon?: ImageResource;
/**
* SF Symbol to show as the back button
* #### (iOS 13+ specific)
*/
sfSymbol?: string;
/**
* Weither the back button is visible or not
* @default true
Expand Down Expand Up @@ -1010,6 +1015,16 @@ export interface OptionsBottomTab {
* #### (Android specific)
*/
popToRoot?: boolean;
/**
* Set the SF symbol as icon (will be used primarily)
* #### (iOS 13+ specific)
*/
sfSymbol?: string;
/**
* Set the SF symbol as selected icon (will be used primarily)
* #### (iOS 13+ specific)
*/
sfSelectedSymbol?: string;
}

export interface SideMenuSide {
Expand Down
8 changes: 8 additions & 0 deletions website/docs/api/options-backButton.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ Change the default back button icon.
| ------------------------------------------ | -------- | -------- |
| [ImageResource](options-imageResource.mdx) | No | Both |

### `sfSymbol`

SF Symbol to show as the back button

| Type | Required | Platform |
| ------ | -------- | -------- |
| string | No | iOS 13+ |

### `showTitle`

Show or hide the text displayed next to the back button.
Expand Down
17 changes: 17 additions & 0 deletions website/docs/api/options-bottomTab.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,23 @@ Overrides the text that's read by the screen reader when the user interacts with
| ----- | -------- | -------- |
| color | No | Both |

### `sfSymbol`

Set the SF symbol as icon (will be used primarily).

| Type | Required | Platform |
| ------ | -------- | -------- |
| string | No | iOS 13+ |


### `sfSelectedSymbol`

Set the SF symbol as selected icon (will be used primarily)

| Type | Required | Platform |
| ------ | -------- | -------- |
| string | No | iOS 13+ |

## DotIndicator

##### color?: color
Expand Down