Skip to content

Commit

Permalink
Merge branch 'master' into fix/android-top-bar-buttons-disappear
Browse files Browse the repository at this point in the history
  • Loading branch information
NormanWangEndeavor authored Nov 4, 2024
2 parents 16d3b9d + efee2bd commit cd5431b
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 11 deletions.
36 changes: 28 additions & 8 deletions lib/ios/RNNBottomTabsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ @implementation RNNBottomTabsController {
NSUInteger _previousTabIndex;
BottomTabsBaseAttacher *_bottomTabsAttacher;
BOOL _tabBarNeedsRestore;
RNNNavigationOptions *_options;
BOOL _didFinishSetup;
}

- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
Expand All @@ -28,14 +30,24 @@ - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
_bottomTabsAttacher = bottomTabsAttacher;
_bottomTabPresenter = bottomTabPresenter;
_dotIndicatorPresenter = dotIndicatorPresenter;
_options = options;
_didFinishSetup = NO;

IntNumber *currentTabIndex = options.bottomTabs.currentTabIndex;
if ([currentTabIndex hasValue]) {
NSUInteger currentTabIndexValue = [currentTabIndex get];
_previousTabIndex = currentTabIndexValue;
_currentTabIndex = currentTabIndexValue;
}

self = [super initWithLayoutInfo:layoutInfo
creator:creator
options:options
defaultOptions:defaultOptions
presenter:presenter
eventEmitter:eventEmitter
childViewControllers:childViewControllers];
creator:creator
options:options
defaultOptions:defaultOptions
presenter:presenter
eventEmitter:eventEmitter
childViewControllers:childViewControllers];

if (@available(iOS 13.0, *)) {
self.tabBar.standardAppearance = [UITabBarAppearance new];
}
Expand All @@ -52,6 +64,7 @@ - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
action:@selector(handleLongPressGesture:)];
[self.tabBar addGestureRecognizer:self.longPressRecognizer];

_didFinishSetup = YES;
return self;
}

Expand Down Expand Up @@ -124,8 +137,15 @@ - (void)setSelectedIndexByComponentID:(NSString *)componentID {
}

- (void)setSelectedIndex:(NSUInteger)selectedIndex {
_currentTabIndex = selectedIndex;
[super setSelectedIndex:selectedIndex];
IntNumber *currentTabIndex = _options.bottomTabs.currentTabIndex;
if ([currentTabIndex hasValue] && !_didFinishSetup) {
NSUInteger currentTabIndexValue = [currentTabIndex get];
_currentTabIndex = currentTabIndexValue;
} else {
_currentTabIndex = selectedIndex;
}

[super setSelectedIndex:_currentTabIndex];
}

- (UIViewController *)selectedViewController {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-navigation",
"version": "7.40.2-pretester",
"version": "7.40.3",
"description": "React Native Navigation - truly native navigation for iOS and Android",
"license": "MIT",
"nativePackage": true,
Expand Down Expand Up @@ -77,7 +77,7 @@
"@react-native/metro-config": "^0.73.2",
"@react-native/babel-preset": "^0.73.18",
"@react-native/typescript-config": "^0.73.1",
"@react-native-community/blur": "^3.6.0",
"@react-native-community/blur": "^4.4.1",
"@react-native-community/datetimepicker": "^3.4.7",
"@react-native-community/eslint-config": "2.0.0",
"@react-native-community/netinfo": "^5.9.4",
Expand Down
48 changes: 48 additions & 0 deletions playground/ios/NavigationTests/RNNCommandsHandlerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -515,12 +515,60 @@ - (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTab {
commandId:@""
completion:^(NSString *componentId){
}];

XCTAssertTrue(_vc1.isViewLoaded);
XCTAssertFalse(_vc2.isViewLoaded);

[tabBarController setSelectedIndex:1];
XCTAssertTrue(_vc2.isViewLoaded);
}

- (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTabWithCustomIndex {
[self.uut setReadyToReceiveCommands:true];
RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions];
options.bottomTabs.tabsAttachMode =
[[BottomTabsAttachMode alloc] initWithValue:@"onSwitchToTab"];
options.animations.setRoot.waitForRender = [[Bool alloc] initWithBOOL:YES];
options.bottomTabs.currentTabIndex = [IntNumber withValue:@1];

BottomTabsBaseAttacher *attacher =
[[[BottomTabsAttachModeFactory alloc] initWithDefaultOptions:nil] fromOptions:options];

RNNBottomTabsController *tabBarController =
[[RNNBottomTabsController alloc] initWithLayoutInfo:nil
creator:nil
options:options
defaultOptions:[RNNNavigationOptions emptyOptions]
presenter:[RNNBasePresenter new]
bottomTabPresenter:nil
dotIndicatorPresenter:nil
eventEmitter:_eventEmmiter
childViewControllers:@[ _vc1, _vc2, _vc3 ]
bottomTabsAttacher:attacher];

[tabBarController viewWillAppear:YES];
OCMStub([self.controllerFactory createLayout:[OCMArg any]]).andReturn(tabBarController);

[self.uut setRoot:@{}
commandId:@""
completion:^(NSString *componentId){
}];

XCTAssertFalse(_vc1.isViewLoaded);
XCTAssertTrue(_vc2.isViewLoaded);
XCTAssertFalse(_vc3.isViewLoaded);

[tabBarController setSelectedIndex:0];
XCTAssertTrue(_vc1.isViewLoaded);
XCTAssertTrue(_vc2.isViewLoaded);
XCTAssertFalse(_vc3.isViewLoaded);

[tabBarController setSelectedIndex:2];
XCTAssertTrue(_vc1.isViewLoaded);
XCTAssertTrue(_vc2.isViewLoaded);
XCTAssertTrue(_vc3.isViewLoaded);
}

- (void)testSetRoot_withBottomTabsAttachModeAfterInitialTab {
[self.uut setReadyToReceiveCommands:true];
RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ topBar: {

## Updating props of custom buttons

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.
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.

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

Expand Down

0 comments on commit cd5431b

Please sign in to comment.