diff --git a/README.md b/README.md index ccdf9cb..3bca79a 100644 --- a/README.md +++ b/README.md @@ -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 } ``` diff --git a/ios/RCCManager.h b/ios/RCCManager.h index aa86496..c55cda2 100755 --- a/ios/RCCManager.h +++ b/ios/RCCManager.h @@ -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; diff --git a/ios/RCCManager.m b/ios/RCCManager.m index b95a7c6..fbf8915 100755 --- a/ios/RCCManager.m +++ b/ios/RCCManager.m @@ -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]; } diff --git a/ios/RCCManagerModule.m b/ios/RCCManagerModule.m index dc193b0..42c2268 100755 --- a/ios/RCCManagerModule.m +++ b/ios/RCCManagerModule.m @@ -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"] diff --git a/ios/RCCNavigationController.m b/ios/RCCNavigationController.m index d049ac5..4fa83af 100755 --- a/ios/RCCNavigationController.m +++ b/ios/RCCNavigationController.m @@ -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 diff --git a/ios/RCCTabBarController.h b/ios/RCCTabBarController.h index 569b50f..348920a 100755 --- a/ios/RCCTabBarController.h +++ b/ios/RCCTabBarController.h @@ -7,3 +7,9 @@ - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actionParams bridge:(RCTBridge *)bridge completion:(void (^)(void))completion; @end + +@interface RCCTabBarController (UITabBarDelegate) +- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item; + +@end + diff --git a/ios/RCCTabBarController.m b/ios/RCCTabBarController.m index c30e52c..53412b6 100755 --- a/ios/RCCTabBarController.m +++ b/ios/RCCTabBarController.m @@ -2,6 +2,8 @@ #import "RCCViewController.h" #import "RCTConvert.h" #import "RCCManager.h" +#import "RCTEventDispatcher.h" +#import "RCCNavigationController.h" @implementation RCCTabBarController @@ -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]]) @@ -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 + diff --git a/ios/RCCViewController.h b/ios/RCCViewController.h index 6b6c3ca..7f42e46 100755 --- a/ios/RCCViewController.h +++ b/ios/RCCViewController.h @@ -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; diff --git a/ios/RCCViewController.m b/ios/RCCViewController.m index 99252ee..7b292e5 100755 --- a/ios/RCCViewController.m +++ b/ios/RCCViewController.m @@ -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; } @@ -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