Skip to content

Commit

Permalink
Fix bottomTabs.currentTabIndex, Closes wix#5012 (wix#5013)
Browse files Browse the repository at this point in the history
* Fix bottomTabs.currentTabIndex, Closes wix#5012

* Set currentTabIndex on init
  • Loading branch information
yogevbd authored and vshkl committed Feb 5, 2020
1 parent 07707c5 commit faf51f0
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 20 deletions.
2 changes: 0 additions & 2 deletions lib/ios/RNNBasePresenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);

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

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

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

- (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions;
Expand Down
4 changes: 0 additions & 4 deletions lib/ios/RNNBasePresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ - (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {

}

- (void)applyOptionsOnSetViewControllers:(RNNNavigationOptions *)options {

}

- (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
UIViewController* viewController = self.bindedViewController;

Expand Down
5 changes: 0 additions & 5 deletions lib/ios/RNNTabBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ @implementation RNNTabBarController {
NSUInteger _currentTabIndex;
}

- (void)setViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers {
[super setViewControllers:viewControllers];
[self.presenter applyOptionsOnSetViewControllers:self.resolveOptions];
}

- (id<UITabBarControllerDelegate>)delegate {
return self;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ios/RNNTabBarPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@implementation RNNTabBarPresenter

- (void)applyOptionsOnSetViewControllers:(RNNNavigationOptions *)options {
- (void)applyOptionsOnInit:(RNNNavigationOptions *)options {
UITabBarController* tabBarController = self.bindedViewController;
[tabBarController rnn_setCurrentTabIndex:[options.bottomTabs.currentTabIndex getWithDefaultValue:0]];
}
Expand Down
10 changes: 10 additions & 0 deletions lib/ios/ReactNativeNavigationTests/RNNTabBarControllerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,14 @@ - (void)testSetSelectedIndexByComponentID_ShouldSetSelectedIndexWithCorrectIndex
XCTAssertTrue(uut.selectedIndex == 1);
}

- (void)testSetSelectedIndex_ShouldSetSelectedIndexWithCurrentTabIndex {
RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
options.bottomTabs.currentTabIndex = [[IntNumber alloc] initWithValue:@(1)];

RNNRootViewController* vc = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:nil options:nil defaultOptions:nil];
RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil creator:nil options:options defaultOptions:nil presenter:[RNNTabBarPresenter new] eventEmitter:nil childViewControllers:@[[UIViewController new], vc]];

XCTAssertTrue(uut.selectedIndex == 1);
}

@end
8 changes: 0 additions & 8 deletions lib/ios/ReactNativeNavigationTests/RNNTabBarPresenterTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,5 @@ - (void)testApplyOptions_shouldApplyOptions {
[self.bindedViewController verify];
}

- (void)testApplyOptions_shouldApplyOptionsOnSetViewControllers {
RNNNavigationOptions* initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
initialOptions.bottomTabs.currentTabIndex = [[IntNumber alloc] initWithValue:@(1)];
[[self.bindedViewController expect] rnn_setCurrentTabIndex:1];

[self.uut applyOptionsOnSetViewControllers:initialOptions];
[self.bindedViewController verify];
}

@end

0 comments on commit faf51f0

Please sign in to comment.