Skip to content

Commit

Permalink
Fix More tab appearance on iOS (#7378)
Browse files Browse the repository at this point in the history
  • Loading branch information
yogevbd authored Dec 1, 2021
1 parent eae5831 commit a188307
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 70 deletions.
3 changes: 0 additions & 3 deletions lib/ios/BottomTabPresenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

- (void)applyOptions:(RNNNavigationOptions *)options child:(UIViewController *)child;

- (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options
child:(UIViewController *)child;

- (void)createTabBarItem:(UIViewController *)child
bottomTabOptions:(RNNBottomTabOptions *)bottomTabOptions;

Expand Down
8 changes: 0 additions & 8 deletions lib/ios/BottomTabPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ - (instancetype)initWithDefaultOptions:(RNNNavigationOptions *)defaultOptions
- (void)applyOptions:(RNNNavigationOptions *)options child:(UIViewController *)child {
RNNNavigationOptions *withDefault = [options withDefault:self.defaultOptions];

[child setTabBarItemBadge:[withDefault.bottomTab.badge withDefault:[NSNull null]]];
[child setTabBarItemBadgeColor:[withDefault.bottomTab.badgeColor withDefault:nil]];
}

- (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options
child:(UIViewController *)child {
RNNNavigationOptions *withDefault = [options withDefault:self.defaultOptions];

[self createTabBarItem:child bottomTabOptions:withDefault.bottomTab];
[child setTabBarItemBadge:[withDefault.bottomTab.badge withDefault:[NSNull null]]];
[child setTabBarItemBadgeColor:[withDefault.bottomTab.badgeColor withDefault:nil]];
Expand Down
4 changes: 0 additions & 4 deletions lib/ios/RNNBasePresenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);

- (void)applyOptions:(RNNNavigationOptions *)options;

- (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options;

- (void)mergeOptions:(RNNNavigationOptions *)options
resolvedOptions:(RNNNavigationOptions *)resolvedOptions;

Expand All @@ -42,8 +40,6 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);

- (UINavigationItem *)currentNavigationItem;

- (void)willMoveToParentViewController:(UIViewController *)parent;

- (UIStatusBarStyle)getStatusBarStyle;

- (UIInterfaceOrientationMask)getOrientation;
Expand Down
12 changes: 0 additions & 12 deletions lib/ios/RNNBasePresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ - (void)componentDidAppear {
- (void)componentDidDisappear {
}

- (void)willMoveToParentViewController:(UIViewController *)parent {
if (parent) {
RNNNavigationOptions *resolvedOptions = [self.boundViewController resolveOptions];
[self applyOptionsOnWillMoveToParentViewController:resolvedOptions];
[self.boundViewController onChildAddToParent:self.boundViewController
options:resolvedOptions];
}
}

- (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
UIViewController *viewController = self.boundViewController;
RNNNavigationOptions *withDefault = [initialOptions withDefault:[self defaultOptions]];
Expand All @@ -66,9 +57,6 @@ - (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
- (void)applyOptionsOnViewDidLayoutSubviews:(RNNNavigationOptions *)options {
}

- (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
}

- (void)applyOptions:(RNNNavigationOptions *)options {
}

Expand Down
16 changes: 8 additions & 8 deletions lib/ios/RNNBottomTabsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
}
#endif

[self createTabBarItems:childViewControllers];

self.longPressRecognizer =
[[UILongPressGestureRecognizer alloc] initWithTarget:self
action:@selector(handleLongPressGesture:)];
Expand All @@ -54,16 +56,18 @@ - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
return self;
}

- (void)createTabBarItems:(NSArray<UIViewController *> *)childViewControllers {
for (UIViewController *child in childViewControllers) {
[_bottomTabPresenter applyOptions:child.resolveOptions child:child];
}
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_viewWillAppearOnce = YES;
[self loadChildren:self.pendingChildViewControllers];
}

- (void)onChildAddToParent:(UIViewController *)child options:(RNNNavigationOptions *)options {
[_bottomTabPresenter applyOptionsOnWillMoveToParentViewController:options child:child];
}

- (void)mergeChildOptions:(RNNNavigationOptions *)options child:(UIViewController *)child {
[super mergeChildOptions:options child:child];
UIViewController *childViewController = [self findViewController:child];
Expand Down Expand Up @@ -189,10 +193,6 @@ - (BOOL)tabBarController:(UITabBarController *)tabBarController

#pragma mark - UIViewController overrides

- (void)willMoveToParentViewController:(UIViewController *)parent {
[self.presenter willMoveToParentViewController:parent];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
return [self.presenter getStatusBarStyle];
}
Expand Down
4 changes: 0 additions & 4 deletions lib/ios/RNNComponentPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ - (void)componentDidDisappear {
[_buttonsPresenter componentDidDisappear];
}

- (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
[super applyOptionsOnWillMoveToParentViewController:options];
}

- (void)applyOptions:(RNNNavigationOptions *)options {
[super applyOptions:options];

Expand Down
4 changes: 0 additions & 4 deletions lib/ios/RNNComponentViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,6 @@ - (UIPreviewAction *)convertAction:(NSDictionary *)action {

#pragma mark - UIViewController overrides

- (void)willMoveToParentViewController:(UIViewController *)parent {
[self.presenter willMoveToParentViewController:parent];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
return [self.presenter getStatusBarStyle];
}
Expand Down
4 changes: 0 additions & 4 deletions lib/ios/RNNExternalViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ - (void)viewDidDisappear:(BOOL)animated {

#pragma mark - UIViewController overrides

- (void)willMoveToParentViewController:(UIViewController *)parent {
[self.presenter willMoveToParentViewController:parent];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
return [self.presenter getStatusBarStyle];
}
Expand Down
4 changes: 0 additions & 4 deletions lib/ios/RNNSideMenuChildVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ - (UIViewController *)getCurrentChild {

#pragma mark - UIViewController overrides

- (void)willMoveToParentViewController:(UIViewController *)parent {
[self.presenter willMoveToParentViewController:parent];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
return [self.presenter getStatusBarStyle];
}
Expand Down
4 changes: 0 additions & 4 deletions lib/ios/RNNSideMenuController.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@ - (RNNNavigationOptions *)resolveOptions {

#pragma mark - UIViewController overrides

- (void)willMoveToParentViewController:(UIViewController *)parent {
[self.presenter willMoveToParentViewController:parent];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
return [self.presenter getStatusBarStyle];
}
Expand Down
4 changes: 0 additions & 4 deletions lib/ios/RNNSplitViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ - (UIViewController *)getCurrentChild {

#pragma mark - UIViewController overrides

- (void)willMoveToParentViewController:(UIViewController *)parent {
[self.presenter willMoveToParentViewController:parent];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
return [self.presenter getStatusBarStyle];
}
Expand Down
4 changes: 0 additions & 4 deletions lib/ios/RNNStackController.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ - (UIViewController *)childViewControllerForStatusBarStyle {

#pragma mark - UIViewController overrides

- (void)willMoveToParentViewController:(UIViewController *)parent {
[self.presenter willMoveToParentViewController:parent];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
return [self.presenter getStatusBarStyle];
}
Expand Down
45 changes: 38 additions & 7 deletions playground/ios/NavigationTests/BottomTabsControllerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ - (void)testInitWithLayoutInfo_shouldCreateWithDefaultStyles {
XCTAssertEqual(uut.modalTransitionStyle, UIModalTransitionStyleCoverVertical);
}

- (void)testWillMoveToParent_shouldNotInvokePresenterApplyOptionsOnWillMoveToNilParent {
[[self.mockTabBarPresenter reject]
applyOptionsOnWillMoveToParentViewController:[self.uut options]];
[self.uut willMoveToParentViewController:nil];
[self.mockTabBarPresenter verify];
}

- (void)testOnChildAppear_shouldInvokePresenterApplyOptionsWithResolvedOptions {
[[self.mockTabBarPresenter expect] applyOptions:[OCMArg any]];
[self.uut onChildWillAppear];
Expand Down Expand Up @@ -325,4 +318,42 @@ - (void)testShouldSelectViewController_emitEvent {
[self.mockEventEmitter verify];
}

- (void)testInit_shouldCreateTabBarItems {
id dotIndicator = [OCMockObject
partialMockForObject:[[RNNDotIndicatorPresenter alloc] initWithDefaultOptions:nil]];
RNNNavigationOptions *vc1Options = [RNNNavigationOptions emptyOptions];
vc1Options.bottomTab.text = [Text withValue:@"VC 1"];
RNNComponentViewController *vc1 = [RNNComponentViewController createWithComponentId:@"VC 1"
initialOptions:vc1Options];

RNNNavigationOptions *vc2Options = [RNNNavigationOptions emptyOptions];
vc2Options.bottomTab.text = [Text withValue:@"VC 2"];
RNNComponentViewController *vc2 = [RNNComponentViewController createWithComponentId:@"VC 2"
initialOptions:vc2Options];
RNNStackController *stack =
[[RNNStackController alloc] initWithLayoutInfo:nil
creator:nil
options:RNNNavigationOptions.new
defaultOptions:nil
presenter:nil
eventEmitter:nil
childViewControllers:@[ vc2 ]];

__unused RNNBottomTabsController *uut = [[RNNBottomTabsController alloc]
initWithLayoutInfo:nil
creator:nil
options:nil
defaultOptions:nil
presenter:nil
bottomTabPresenter:[BottomTabPresenterCreator
createWithDefaultOptions:RNNNavigationOptions.emptyOptions]
dotIndicatorPresenter:dotIndicator
eventEmitter:nil
childViewControllers:@[ vc1, stack ]
bottomTabsAttacher:nil];

XCTAssert([vc1.tabBarItem.title isEqualToString:@"VC 1"]);
XCTAssert([stack.tabBarItem.title isEqualToString:@"VC 2"]);
}

@end

0 comments on commit a188307

Please sign in to comment.