From f0087be7163d344c3d6724592d01646a821ac9fa Mon Sep 17 00:00:00 2001 From: Eli Perkins Date: Wed, 29 Nov 2017 11:33:33 -0500 Subject: [PATCH 1/3] Refactor resetTo view controller creation into function This will allow for multiple view controllers to call the same function to create their instance. --- ios/RCCNavigationController.m | 58 +++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/ios/RCCNavigationController.m b/ios/RCCNavigationController.m index 116c6505a26..0fc35234f86 100755 --- a/ios/RCCNavigationController.m +++ b/ios/RCCNavigationController.m @@ -257,31 +257,20 @@ - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actio { NSString *component = actionParams[@"component"]; if (!component) return; - + NSMutableDictionary *passProps = [actionParams[@"passProps"] mutableCopy]; passProps[@"commandType"] = @"resetTo"; NSDictionary *navigatorStyle = actionParams[@"style"]; - - RCCViewController *viewController = [[RCCViewController alloc] initWithComponent:component passProps:passProps navigatorStyle:navigatorStyle globalProps:nil bridge:bridge]; - viewController.controllerId = passProps[@"screenInstanceID"]; - - viewController.navigationItem.hidesBackButton = YES; - - [self processTitleView:viewController - props:actionParams - style:navigatorStyle]; NSArray *leftButtons = actionParams[@"leftButtons"]; - if (leftButtons) - { - [self setButtons:leftButtons viewController:viewController side:@"left" animated:NO]; - } - NSArray *rightButtons = actionParams[@"rightButtons"]; - if (rightButtons) - { - [self setButtons:rightButtons viewController:viewController side:@"right" animated:NO]; - } - + + UIViewController *viewController = [self viewControllerWithComponent:component + props:[passProps copy] + style:navigatorStyle + leftButtons:leftButtons + rightButtons:rightButtons + bridge:bridge]; + BOOL animated = actionParams[@"animated"] ? [actionParams[@"animated"] boolValue] : YES; NSString *animationType = actionParams[@"animationType"]; @@ -360,6 +349,35 @@ - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actio } } +- (UIViewController *)viewControllerWithComponent:(NSString *)component + props:(NSDictionary *)props + style:(NSDictionary *)style + leftButtons:(NSArray *)leftButtons + rightButtons:(NSArray *)rightButtons + bridge:(RCTBridge *)bridge +{ + RCCViewController *viewController = [[RCCViewController alloc] initWithComponent:component passProps:props navigatorStyle:style globalProps:nil bridge:bridge]; + viewController.controllerId = props[@"screenInstanceID"]; + + viewController.navigationItem.hidesBackButton = YES; + + [self processTitleView:viewController + props:props + style:style]; + + if (leftButtons) + { + [self setButtons:leftButtons viewController:viewController side:@"left" animated:NO]; + } + + if (rightButtons) + { + [self setButtons:rightButtons viewController:viewController side:@"right" animated:NO]; + } + + return viewController; +} + -(void)onButtonPress:(UIBarButtonItem*)barButtonItem { NSString *callbackId = objc_getAssociatedObject(barButtonItem, &CALLBACK_ASSOCIATED_KEY); From 70e6b79fe75ac6b17915e26e2547b4cffa02fd5e Mon Sep 17 00:00:00 2001 From: Eli Perkins Date: Wed, 29 Nov 2017 11:48:50 -0500 Subject: [PATCH 2/3] Configure resetTo to take multiple components to set view controllers for This allows for a navigation stack to be recreated with multiple view controllers rather than just one. --- ios/RCCNavigationController.m | 58 ++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/ios/RCCNavigationController.m b/ios/RCCNavigationController.m index 0fc35234f86..4af4116d1ac 100755 --- a/ios/RCCNavigationController.m +++ b/ios/RCCNavigationController.m @@ -255,21 +255,49 @@ - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actio // resetTo if ([performAction isEqualToString:@"resetTo"]) { - NSString *component = actionParams[@"component"]; - if (!component) return; + NSArray *viewControllers; - NSMutableDictionary *passProps = [actionParams[@"passProps"] mutableCopy]; - passProps[@"commandType"] = @"resetTo"; - NSDictionary *navigatorStyle = actionParams[@"style"]; - NSArray *leftButtons = actionParams[@"leftButtons"]; - NSArray *rightButtons = actionParams[@"rightButtons"]; + NSString *component = actionParams[@"component"]; + NSArray *componentConfigs = actionParams[@"components"]; + if (component) { + NSMutableDictionary *passProps = [actionParams[@"passProps"] mutableCopy]; + passProps[@"commandType"] = @"resetTo"; + NSDictionary *style = actionParams[@"style"]; + NSArray *leftButtons = actionParams[@"leftButtons"]; + NSArray *rightButtons = actionParams[@"rightButtons"]; + + UIViewController *viewController = [self viewControllerWithComponent:component + props:[passProps copy] + style:style + leftButtons:leftButtons + rightButtons:rightButtons + bridge:bridge]; + + viewControllers = @[viewController]; + } else if (componentConfigs) { + NSMutableArray *mutableViewControllers = [NSMutableArray arrayWithCapacity:[componentConfigs count]]; + [componentConfigs enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull config, NSUInteger idx, BOOL * _Nonnull stop) { + NSString *component = config[@"component"]; + + NSMutableDictionary *props = [config[@"passProps"] mutableCopy]; + props[@"commandType"] = @"resetTo"; + NSDictionary *style = config[@"style"]; + NSArray *leftButtons = config[@"leftButtons"]; + NSArray *rightButtons = config[@"rightButtons"]; + + UIViewController *viewController = [self viewControllerWithComponent:component + props:[props copy] + style:style + leftButtons:leftButtons + rightButtons:rightButtons + bridge:bridge]; + + [mutableViewControllers addObject:viewController]; + }]; + viewControllers = [mutableViewControllers copy]; + } - UIViewController *viewController = [self viewControllerWithComponent:component - props:[passProps copy] - style:navigatorStyle - leftButtons:leftButtons - rightButtons:rightButtons - bridge:bridge]; + if (!viewControllers) return; BOOL animated = actionParams[@"animated"] ? [actionParams[@"animated"] boolValue] : YES; @@ -281,11 +309,11 @@ - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actio transition.type = kCATransitionFade; [self.view.layer addAnimation:transition forKey:kCATransition]; - [self setViewControllers:@[viewController] animated:NO]; + [self setViewControllers:viewControllers animated:NO]; } else { - [self setViewControllers:@[viewController] animated:animated]; + [self setViewControllers:viewControllers animated:animated]; } return; } From 26bab3339f9be30b4271046ca0ae455760ede28c Mon Sep 17 00:00:00 2001 From: Eli Perkins Date: Wed, 29 Nov 2017 11:55:56 -0500 Subject: [PATCH 3/3] Breakup view controller initializer into multiple lines for legibility --- ios/RCCNavigationController.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ios/RCCNavigationController.m b/ios/RCCNavigationController.m index 4af4116d1ac..8c15f7a145b 100755 --- a/ios/RCCNavigationController.m +++ b/ios/RCCNavigationController.m @@ -384,7 +384,11 @@ - (UIViewController *)viewControllerWithComponent:(NSString *)component rightButtons:(NSArray *)rightButtons bridge:(RCTBridge *)bridge { - RCCViewController *viewController = [[RCCViewController alloc] initWithComponent:component passProps:props navigatorStyle:style globalProps:nil bridge:bridge]; + RCCViewController *viewController = [[RCCViewController alloc] initWithComponent:component + passProps:props + navigatorStyle:style + globalProps:nil + bridge:bridge]; viewController.controllerId = props[@"screenInstanceID"]; viewController.navigationItem.hidesBackButton = YES;