Skip to content

added support for tabBarItem.titlePositionAdjustment #62

New issue

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

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

Already on GitHub? # to your account

Closed
wants to merge 9 commits into from
Closed
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,8 @@ All styles are optional, this is the format of the style object:
{
tabBarButtonColor: '#ffff00', // change the color of the tab icons and text (also unselected)
tabBarSelectedButtonColor: '#ff9900', // change the color of the selected tab icon and text (only selected)
tabBarBackgroundColor: '#551A8B' // change the background color of the tab bar
tabBarBackgroundColor: '#551A8B', // change the background color of the tab bar
tabBarTextAdjustment: { x: 0, y: 0 } // change the text x and y offset
}
```

Expand Down
2 changes: 1 addition & 1 deletion ios/RCCManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
+ (instancetype)sharedInstance;
+ (instancetype)sharedIntance;

-(void)initBridgeWithBundleURL:(NSURL *)bundleURL;
-(void)initBridgeWithBundleURL:(NSURL *)bundleURL launchOptions:(NSDictionary *)launchOptions;
-(RCTBridge*)getBridge;

-(void)registerController:(UIViewController*)controller componentId:(NSString*)componentId componentType:(NSString*)componentType;
Expand Down
4 changes: 2 additions & 2 deletions ios/RCCManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ -(id)getControllerWithId:(NSString*)componentId componentType:(NSString*)compone
return component;
}

-(void)initBridgeWithBundleURL:(NSURL *)bundleURL
-(void)initBridgeWithBundleURL:(NSURL *)bundleURL launchOptions:(NSDictionary *)launchOptions
{
if (self.sharedBridge) return;

self.bundleURL = bundleURL;
self.sharedBridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:nil];
self.sharedBridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];

[self showSplashScreen];
}
Expand Down
2 changes: 2 additions & 0 deletions ios/RCCManagerModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ -(void)dismissAllModalPresenters:(NSMutableArray*)allPresentedViewControllers re
error:[RCCManagerModule rccErrorWithCode:RCCManagerModuleCantCreateControllerErrorCode description:@"could not create controller"]];
return;
}

[controller setModalPresentationStyle:UIModalPresentationCustom];

[[RCCManagerModule lastModalPresenterViewController] presentViewController:controller
animated:![animationType isEqualToString:@"none"]
Expand Down
22 changes: 22 additions & 0 deletions ios/RCCNavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,26 @@ -(void)setTitleIamgeForVC:(UIViewController*)viewController titleImageData:(id)t
}
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return [self.topViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
if (self.topViewController) {
return [self.topViewController supportedInterfaceOrientations];
}

return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate
{
if (self.topViewController) {
return [self.topViewController shouldAutorotate];
}
return NO;
}

@end
6 changes: 6 additions & 0 deletions ios/RCCTabBarController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
- (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actionParams bridge:(RCTBridge *)bridge completion:(void (^)(void))completion;

@end

@interface RCCTabBarController (UITabBarDelegate) <UITabBarDelegate>
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item;

@end

45 changes: 45 additions & 0 deletions ios/RCCTabBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#import "RCCViewController.h"
#import "RCTConvert.h"
#import "RCCManager.h"
#import "RCTEventDispatcher.h"
#import "RCCNavigationController.h"

@implementation RCCTabBarController

Expand Down Expand Up @@ -106,6 +108,14 @@ - (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children
@{NSForegroundColorAttributeName : selectedButtonColor} forState:UIControlStateSelected];
}

// adject text position
NSDictionary *tabBarTextAdjustment = tabsStyle[@"tabBarTextAdjustment"];
if(tabBarTextAdjustment &&
[tabBarTextAdjustment objectForKey:@"x"] &&
[tabBarTextAdjustment objectForKey:@"y"]) {
viewController.tabBarItem.titlePositionAdjustment = UIOffsetMake([[tabBarTextAdjustment objectForKey:@"x"] integerValue], [[tabBarTextAdjustment objectForKey:@"y"] integerValue]);
}

// create badge
NSObject *badge = tabItemLayout[@"props"][@"badge"];
if (badge == nil || [badge isEqual:[NSNull null]])
Expand Down Expand Up @@ -216,4 +226,39 @@ - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actio
}
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
if (self.selectedViewController) {
return [self.selectedViewController supportedInterfaceOrientations];
}

return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate {
RCCNavigationController *navVC = (id)self.selectedViewController;
if ([navVC isKindOfClass:[RCCNavigationController class]]) {
return navVC.shouldAutorotate;
}
return NO;
}

@end

@implementation RCCTabBarController (UITabBarDelegate)

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {

[[[RCCManager sharedInstance] getBridge].eventDispatcher sendAppEventWithName:@"tabbarControllerEventID" body:@
{
@"type": @"TabBarButtonPress",
@"id": @(item.tag),
@"label": item.title,
}];
}

@end

1 change: 1 addition & 0 deletions ios/RCCViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@property (nonatomic) NSMutableDictionary *navigatorStyle;
@property (nonatomic) BOOL navBarHidden;
@property (nonatomic) BOOL shouldAutoRotate;

+ (UIViewController*)controllerWithLayout:(NSDictionary *)layout globalProps:(NSDictionary *)globalProps bridge:(RCTBridge *)bridge;

Expand Down
30 changes: 30 additions & 0 deletions ios/RCCViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,26 @@ - (instancetype)initWithComponent:(NSString *)component passProps:(NSDictionary

RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:bridge moduleName:component initialProperties:mergedProps];
if (!reactView) return nil;

// Set custom background color
id backgroundColor = navigatorStyle[@"backgroundColor"];
if (backgroundColor) {
if ([backgroundColor isEqual:@0]) {
[reactView setBackgroundColor:[UIColor clearColor]];
} else {
UIColor *bgColor = [RCTConvert UIColor:backgroundColor];
[reactView setBackgroundColor:bgColor];
}
}

self = [super init];
if (!self) return nil;

[self commonInit:reactView navigatorStyle:navigatorStyle props:passProps];

NSNumber *shouldAutoRotate = navigatorStyle[@"shouldAutoRotate"];
BOOL shouldAutoRotateBool = shouldAutoRotate ? [shouldAutoRotate boolValue] : NO;
self.shouldAutoRotate = shouldAutoRotateBool;

return self;
}
Expand Down Expand Up @@ -502,4 +517,19 @@ -(void)addExternalVCIfNecessary:(NSDictionary*)props
}
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationIsLandscape);
}

- (BOOL)shouldAutorotate
{
return self.shouldAutoRotate;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
}

@end