Skip to content

Commit

Permalink
Fix top bar layout frame (#5008)
Browse files Browse the repository at this point in the history
* Fix top bar layout frame, Closes #5003

* Set layout child view controllers on initialization

* Remove duplicate initWithLayoutInfo: function
  • Loading branch information
yogevbd authored Apr 21, 2019
1 parent e9ca247 commit be00c4c
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 92 deletions.
7 changes: 0 additions & 7 deletions lib/ios/RNNBasePresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@
#import "UIViewController+LayoutProtocol.h"

@interface RNNBasePresenter ()
@property (nonatomic, strong) RNNReactComponentRegistry* componentRegistry;
@end


@implementation RNNBasePresenter

- (instancetype)initWithComponentRegistry:(RNNReactComponentRegistry *)componentRegistry {
self = [super init];
self.componentRegistry = componentRegistry;
return self;
}

- (void)bindViewController:(UIViewController<RNNLayoutProtocol> *)bindedViewController {
self.bindedComponentId = bindedViewController.layoutInfo.componentId;
_bindedViewController = bindedViewController;
Expand Down
14 changes: 5 additions & 9 deletions lib/ios/RNNControllerFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ - (UIViewController *)createStack:(RNNLayoutNode*)node {

NSArray *childViewControllers = [self extractChildrenViewControllersFromNode:node];

RNNNavigationController* stack = [[RNNNavigationController alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:presenter eventEmitter:_eventEmitter];
[stack setViewControllers:childViewControllers];
RNNNavigationController* stack = [[RNNNavigationController alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:presenter eventEmitter:_eventEmitter childViewControllers:childViewControllers];

return stack;
}
Expand All @@ -154,8 +153,7 @@ -(UIViewController *)createTabs:(RNNLayoutNode*)node {

NSArray *childViewControllers = [self extractChildrenViewControllersFromNode:node];

RNNTabBarController* tabsController = [[RNNTabBarController alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:presenter eventEmitter:_eventEmitter];
[tabsController setViewControllers:childViewControllers];
RNNTabBarController* tabsController = [[RNNTabBarController alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:presenter eventEmitter:_eventEmitter childViewControllers:childViewControllers];

return tabsController;
}
Expand All @@ -167,8 +165,7 @@ - (UIViewController *)createTopTabs:(RNNLayoutNode*)node {

NSArray *childViewControllers = [self extractChildrenViewControllersFromNode:node];

RNNTopTabsViewController* topTabsController = [[RNNTopTabsViewController alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:presenter eventEmitter:_eventEmitter];
[topTabsController setViewControllers:childViewControllers];
RNNTopTabsViewController* topTabsController = [[RNNTopTabsViewController alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:presenter eventEmitter:_eventEmitter childViewControllers:childViewControllers];

return topTabsController;
}
Expand All @@ -191,7 +188,7 @@ - (UIViewController *)createSideMenuChild:(RNNLayoutNode*)node type:(RNNSideMenu
RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] initWithNode:node];
RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:node.data[@"options"]];;

RNNSideMenuChildVC *sideMenuChild = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:layoutInfo childViewControllers:@[childVc] options:options defaultOptions:_defaultOptions presenter:[[RNNViewControllerPresenter alloc] init] type:type];
RNNSideMenuChildVC *sideMenuChild = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:[[RNNViewControllerPresenter alloc] init] eventEmitter:_eventEmitter childViewController:childVc type:type];

return sideMenuChild;
}
Expand All @@ -203,8 +200,7 @@ - (UIViewController *)createSplitView:(RNNLayoutNode*)node {

NSArray *childViewControllers = [self extractChildrenViewControllersFromNode:node];

RNNSplitViewController* splitViewController = [[RNNSplitViewController alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:presenter eventEmitter:_eventEmitter];
[splitViewController bindChildViewControllers:childViewControllers];
RNNSplitViewController* splitViewController = [[RNNSplitViewController alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:presenter eventEmitter:_eventEmitter childViewControllers:childViewControllers];

return splitViewController;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/ios/RNNLayoutProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
options:(RNNNavigationOptions *)options
defaultOptions:(RNNNavigationOptions *)defaultOptions
presenter:(RNNBasePresenter *)presenter
eventEmitter:(RNNEventEmitter *)eventEmitter;
eventEmitter:(RNNEventEmitter *)eventEmitter
childViewControllers:(NSArray *)childViewControllers;

- (void)renderTreeAndWait:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock;

Expand Down
2 changes: 1 addition & 1 deletion lib/ios/RNNRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ @implementation RNNRootViewController
@synthesize previewCallback;

- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo rootViewCreator:(id<RNNRootViewCreator>)creator eventEmitter:(RNNEventEmitter *)eventEmitter presenter:(RNNViewControllerPresenter *)presenter options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions {
self = [super initWithLayoutInfo:layoutInfo creator:creator options:options defaultOptions:defaultOptions presenter:presenter eventEmitter:eventEmitter];
self = [super initWithLayoutInfo:layoutInfo creator:creator options:options defaultOptions:defaultOptions presenter:presenter eventEmitter:eventEmitter childViewControllers:nil];

self.animator = [[RNNAnimator alloc] initWithTransitionOptions:self.resolveOptions.customTransition];

Expand Down
4 changes: 2 additions & 2 deletions lib/ios/RNNSideMenuChildVC.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ typedef NS_ENUM(NSInteger, RNNSideMenuChildType) {

@interface RNNSideMenuChildVC : UIViewController <RNNLayoutProtocol>

- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo creator:(id<RNNRootViewCreator>)creator options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNBasePresenter *)presenter eventEmitter:(RNNEventEmitter *)eventEmitter childViewController:(UIViewController *)childViewController type:(RNNSideMenuChildType)type;

@property (readonly) RNNSideMenuChildType type;
@property (readonly) UIViewController<RNNLayoutProtocol> *child;


- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo childViewControllers:(NSArray *)childViewControllers options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNViewControllerPresenter *)presenter type:(RNNSideMenuChildType)type;

- (void)setWidth:(CGFloat)width;

@end
29 changes: 6 additions & 23 deletions lib/ios/RNNSideMenuChildVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,20 @@ @interface RNNSideMenuChildVC ()

@implementation RNNSideMenuChildVC

- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo childViewControllers:(NSArray *)childViewControllers options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNViewControllerPresenter *)presenter type:(RNNSideMenuChildType)type {
self = [self initWithLayoutInfo:layoutInfo childViewControllers:childViewControllers options:options defaultOptions:defaultOptions presenter:presenter];

self.type = type;

return self;
}

- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo childViewControllers:(NSArray *)childViewControllers options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNViewControllerPresenter *)presenter {
self = [super init];

self.child = childViewControllers[0];

self.presenter = presenter;
[self.presenter bindViewController:self];

self.defaultOptions = defaultOptions;
self.options = options;
self.layoutInfo = layoutInfo;

[self bindChildViewController:self.child];

- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo creator:(id<RNNRootViewCreator>)creator options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNBasePresenter *)presenter eventEmitter:(RNNEventEmitter *)eventEmitter childViewController:(UIViewController *)childViewController type:(RNNSideMenuChildType)type {
self = [super initWithLayoutInfo:layoutInfo creator:creator options:options defaultOptions:defaultOptions presenter:presenter eventEmitter:eventEmitter childViewControllers:nil];
self.type = type;
self.child = childViewController;
return self;
}

- (void)renderTreeAndWait:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
[self.getCurrentChild renderTreeAndWait:wait perform:readyBlock];
}

- (void)bindChildViewController:(UIViewController<RNNLayoutProtocol>*)child {
self.child = child;
- (void)setChild:(UIViewController<RNNLayoutProtocol> *)child {
_child = child;
[self addChildViewController:self.child];
[self.child.view setFrame:self.view.bounds];
[self.view addSubview:self.child.view];
Expand Down
15 changes: 0 additions & 15 deletions lib/ios/RNNTopTabsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ @interface RNNTopTabsViewController () {

@implementation RNNTopTabsViewController

- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo childViewControllers:(NSArray *)childViewControllers options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNViewControllerPresenter *)presenter {
self = [self init];

self.presenter = presenter;
[self.presenter bindViewController:self];

self.defaultOptions = defaultOptions;
self.options = options;
self.layoutInfo = layoutInfo;

[self setViewControllers:childViewControllers];

return self;
}

- (instancetype)init {
self = [super init];

Expand Down
1 change: 1 addition & 0 deletions lib/ios/RNNViewControllerPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ - (void)setCustomNavigationTitleView:(RNNNavigationOptions *)options perform:(RN
BOOL isCenter = [alignment isEqualToString:@"center"];
__weak RNNReactView *weakTitleView = _customTitleView;
CGRect frame = viewController.navigationController.navigationBar.bounds;
[_customTitleView setFrame:frame];
[_customTitleView setRootViewDidChangeIntrinsicSize:^(CGSize intrinsicContentSize) {
if (isCenter) {
[weakTitleView setFrame:CGRectMake(0, 0, intrinsicContentSize.width, intrinsicContentSize.height)];
Expand Down
3 changes: 1 addition & 2 deletions lib/ios/ReactNativeNavigationTests/RNNCommandsHandlerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ -(void)testDynamicStylesMergeWithStaticStyles {
RNNViewControllerPresenter* presenter = [[RNNViewControllerPresenter alloc] init];
RNNRootViewController* vc = [[RNNRootViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:creator eventEmitter:nil presenter:presenter options:initialOptions defaultOptions:nil];

RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:creator options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init] eventEmitter:nil];
[nav setViewControllers:@[vc]];
RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:creator options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init] eventEmitter:nil childViewControllers:@[vc]];

[vc viewWillAppear:false];
XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@ - (void)setUp {
_vc2Mock = [OCMockObject partialMockForObject:_vc2];
_vc3 = [UIViewController new];
_options = [OCMockObject partialMockForObject:[[RNNNavigationOptions alloc] initEmptyOptions]];
self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:_options defaultOptions:nil presenter:[OCMockObject partialMockForObject:[[RNNNavigationControllerPresenter alloc] init]] eventEmitter:nil];
[self.uut setViewControllers:@[_vc1, _vc2]];
self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:_options defaultOptions:nil presenter:[OCMockObject partialMockForObject:[[RNNNavigationControllerPresenter alloc] init]] eventEmitter:nil childViewControllers:@[_vc1, _vc2]];
}

- (void)testInitWithLayoutInfo_shouldBindPresenter {
XCTAssertNotNil(self.uut.presenter);
}

- (void)testInitWithLayoutInfo_shouldSetMultipleViewControllers {
self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:[[RNNViewControllerPresenter alloc] init] eventEmitter:nil];
[self.uut setViewControllers:@[_vc1, _vc2]];
self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:[[RNNViewControllerPresenter alloc] init] eventEmitter:nil childViewControllers:@[_vc1, _vc2]];
XCTAssertTrue(self.uut.viewControllers.count == 2);
}

Expand Down Expand Up @@ -155,8 +153,7 @@ - (void)testOverrideOptionsShouldOverrideOptionsState {
}

- (RNNNavigationController *)createNavigationControllerWithOptions:(RNNNavigationOptions *)options {
RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:options defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init] eventEmitter:nil];
[nav setViewControllers:@[_vc1]];
RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:options defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init] eventEmitter:nil childViewControllers:@[_vc1]];
return nav;
}

Expand Down
15 changes: 5 additions & 10 deletions lib/ios/ReactNativeNavigationTests/RNNRootViewControllerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,7 @@ -(void)testOrientationTabsController_all {
-(void)testRightButtonsWithTitle_withoutStyle {
self.options.topBar.rightButtons = @[@{@"id": @"testId", @"text": @"test"}];
self.uut = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNViewControllerPresenter new] options:self.options defaultOptions:nil];
RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil];
[nav setViewControllers:@[self.uut]];
RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[self.uut]];

RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
NSString* expectedButtonId = @"testId";
Expand All @@ -431,8 +430,7 @@ -(void)testRightButtonsWithTitle_withStyle {

self.options.topBar.rightButtons = @[@{@"id": @"testId", @"text": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
self.uut = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNViewControllerPresenter new] options:self.options defaultOptions:nil];
RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil];
[nav setViewControllers:@[self.uut]];
RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[self.uut]];

RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
NSString* expectedButtonId = @"testId";
Expand All @@ -448,8 +446,7 @@ -(void)testRightButtonsWithTitle_withStyle {
-(void)testLeftButtonsWithTitle_withoutStyle {
self.options.topBar.leftButtons = @[@{@"id": @"testId", @"text": @"test"}];
self.uut = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNViewControllerPresenter new] options:self.options defaultOptions:nil];
RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil];
[nav setViewControllers:@[self.uut]];
RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[self.uut]];

RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
NSString* expectedButtonId = @"testId";
Expand All @@ -464,8 +461,7 @@ -(void)testLeftButtonsWithTitle_withStyle {

self.options.topBar.leftButtons = @[@{@"id": @"testId", @"text": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
self.uut = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNViewControllerPresenter new] options:self.options defaultOptions:nil];
RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil];
[nav setViewControllers:@[self.uut]];
RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[self.uut]];

RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
NSString* expectedButtonId = @"testId";
Expand Down Expand Up @@ -569,8 +565,7 @@ - (void)testOverrideOptions {


- (RNNNavigationController *)createNavigationController {
RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init] eventEmitter:nil];
[nav setViewControllers:@[self.uut]];
RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init] eventEmitter:nil childViewControllers:@[self.uut]];

return nav;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ @implementation RNNSideMenuControllerTest

- (void)setUp {
[super setUp];
_leftVC = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil childViewControllers:@[[RNNRootViewController new]] options:nil defaultOptions:nil presenter:nil type:RNNSideMenuChildTypeLeft];
_rightVC = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil childViewControllers:@[[RNNRootViewController new]] options:nil defaultOptions:nil presenter:nil type:RNNSideMenuChildTypeRight];
_centerVC = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil childViewControllers:@[[RNNRootViewController new]] options:nil defaultOptions:nil presenter:nil type:RNNSideMenuChildTypeCenter];
_leftVC = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewController:[RNNRootViewController new] type:RNNSideMenuChildTypeLeft];
_rightVC = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewController:[RNNRootViewController new] type:RNNSideMenuChildTypeRight];
_centerVC =[[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewController:[RNNRootViewController new] type:RNNSideMenuChildTypeCenter];
self.uut = [[RNNSideMenuController alloc] initWithLayoutInfo:nil creator:nil childViewControllers:@[_leftVC, _centerVC, _rightVC] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:nil eventEmitter:nil];
}

Expand Down
Loading

0 comments on commit be00c4c

Please sign in to comment.