Skip to content

Commit cd5431b

Browse files
Merge branch 'master' into fix/android-top-bar-buttons-disappear
2 parents 16d3b9d + efee2bd commit cd5431b

File tree

4 files changed

+79
-11
lines changed

4 files changed

+79
-11
lines changed

lib/ios/RNNBottomTabsController.m

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ @implementation RNNBottomTabsController {
1313
NSUInteger _previousTabIndex;
1414
BottomTabsBaseAttacher *_bottomTabsAttacher;
1515
BOOL _tabBarNeedsRestore;
16+
RNNNavigationOptions *_options;
17+
BOOL _didFinishSetup;
1618
}
1719

1820
- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
@@ -28,14 +30,24 @@ - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
2830
_bottomTabsAttacher = bottomTabsAttacher;
2931
_bottomTabPresenter = bottomTabPresenter;
3032
_dotIndicatorPresenter = dotIndicatorPresenter;
33+
_options = options;
34+
_didFinishSetup = NO;
35+
36+
IntNumber *currentTabIndex = options.bottomTabs.currentTabIndex;
37+
if ([currentTabIndex hasValue]) {
38+
NSUInteger currentTabIndexValue = [currentTabIndex get];
39+
_previousTabIndex = currentTabIndexValue;
40+
_currentTabIndex = currentTabIndexValue;
41+
}
3142

3243
self = [super initWithLayoutInfo:layoutInfo
33-
creator:creator
34-
options:options
35-
defaultOptions:defaultOptions
36-
presenter:presenter
37-
eventEmitter:eventEmitter
38-
childViewControllers:childViewControllers];
44+
creator:creator
45+
options:options
46+
defaultOptions:defaultOptions
47+
presenter:presenter
48+
eventEmitter:eventEmitter
49+
childViewControllers:childViewControllers];
50+
3951
if (@available(iOS 13.0, *)) {
4052
self.tabBar.standardAppearance = [UITabBarAppearance new];
4153
}
@@ -52,6 +64,7 @@ - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
5264
action:@selector(handleLongPressGesture:)];
5365
[self.tabBar addGestureRecognizer:self.longPressRecognizer];
5466

67+
_didFinishSetup = YES;
5568
return self;
5669
}
5770

@@ -124,8 +137,15 @@ - (void)setSelectedIndexByComponentID:(NSString *)componentID {
124137
}
125138

126139
- (void)setSelectedIndex:(NSUInteger)selectedIndex {
127-
_currentTabIndex = selectedIndex;
128-
[super setSelectedIndex:selectedIndex];
140+
IntNumber *currentTabIndex = _options.bottomTabs.currentTabIndex;
141+
if ([currentTabIndex hasValue] && !_didFinishSetup) {
142+
NSUInteger currentTabIndexValue = [currentTabIndex get];
143+
_currentTabIndex = currentTabIndexValue;
144+
} else {
145+
_currentTabIndex = selectedIndex;
146+
}
147+
148+
[super setSelectedIndex:_currentTabIndex];
129149
}
130150

131151
- (UIViewController *)selectedViewController {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-navigation",
3-
"version": "7.40.2-pretester",
3+
"version": "7.40.3",
44
"description": "React Native Navigation - truly native navigation for iOS and Android",
55
"license": "MIT",
66
"nativePackage": true,
@@ -77,7 +77,7 @@
7777
"@react-native/metro-config": "^0.73.2",
7878
"@react-native/babel-preset": "^0.73.18",
7979
"@react-native/typescript-config": "^0.73.1",
80-
"@react-native-community/blur": "^3.6.0",
80+
"@react-native-community/blur": "^4.4.1",
8181
"@react-native-community/datetimepicker": "^3.4.7",
8282
"@react-native-community/eslint-config": "2.0.0",
8383
"@react-native-community/netinfo": "^5.9.4",

playground/ios/NavigationTests/RNNCommandsHandlerTest.m

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,12 +515,60 @@ - (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTab {
515515
commandId:@""
516516
completion:^(NSString *componentId){
517517
}];
518+
518519
XCTAssertTrue(_vc1.isViewLoaded);
519520
XCTAssertFalse(_vc2.isViewLoaded);
521+
520522
[tabBarController setSelectedIndex:1];
521523
XCTAssertTrue(_vc2.isViewLoaded);
522524
}
523525

526+
- (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTabWithCustomIndex {
527+
[self.uut setReadyToReceiveCommands:true];
528+
RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions];
529+
options.bottomTabs.tabsAttachMode =
530+
[[BottomTabsAttachMode alloc] initWithValue:@"onSwitchToTab"];
531+
options.animations.setRoot.waitForRender = [[Bool alloc] initWithBOOL:YES];
532+
options.bottomTabs.currentTabIndex = [IntNumber withValue:@1];
533+
534+
BottomTabsBaseAttacher *attacher =
535+
[[[BottomTabsAttachModeFactory alloc] initWithDefaultOptions:nil] fromOptions:options];
536+
537+
RNNBottomTabsController *tabBarController =
538+
[[RNNBottomTabsController alloc] initWithLayoutInfo:nil
539+
creator:nil
540+
options:options
541+
defaultOptions:[RNNNavigationOptions emptyOptions]
542+
presenter:[RNNBasePresenter new]
543+
bottomTabPresenter:nil
544+
dotIndicatorPresenter:nil
545+
eventEmitter:_eventEmmiter
546+
childViewControllers:@[ _vc1, _vc2, _vc3 ]
547+
bottomTabsAttacher:attacher];
548+
549+
[tabBarController viewWillAppear:YES];
550+
OCMStub([self.controllerFactory createLayout:[OCMArg any]]).andReturn(tabBarController);
551+
552+
[self.uut setRoot:@{}
553+
commandId:@""
554+
completion:^(NSString *componentId){
555+
}];
556+
557+
XCTAssertFalse(_vc1.isViewLoaded);
558+
XCTAssertTrue(_vc2.isViewLoaded);
559+
XCTAssertFalse(_vc3.isViewLoaded);
560+
561+
[tabBarController setSelectedIndex:0];
562+
XCTAssertTrue(_vc1.isViewLoaded);
563+
XCTAssertTrue(_vc2.isViewLoaded);
564+
XCTAssertFalse(_vc3.isViewLoaded);
565+
566+
[tabBarController setSelectedIndex:2];
567+
XCTAssertTrue(_vc1.isViewLoaded);
568+
XCTAssertTrue(_vc2.isViewLoaded);
569+
XCTAssertTrue(_vc3.isViewLoaded);
570+
}
571+
524572
- (void)testSetRoot_withBottomTabsAttachModeAfterInitialTab {
525573
[self.uut setReadyToReceiveCommands:true];
526574
RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions];

website/versioned_docs/version-7.37.0/docs/stack-buttons.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ topBar: {
5353

5454
## Updating props of custom buttons
5555

56-
To update props of a mounted compoennt used as a button, you'll first need to assign it a unique id, then call the `Navigation.updateProps()` command with the id.
56+
To update props of a mounted component used as a button, you'll first need to assign it a unique id, then call the `Navigation.updateProps()` command with the id.
5757

5858
Calling the updateProps command will trigger React's component lifecycle methods related to [props update](https://reactjs.org/docs/react-component.html#updating)
5959

0 commit comments

Comments
 (0)