Skip to content

Commit c231ff0

Browse files
authored
refactor(Tabs, iOS): extract RNSTabBarControllerDelegate into a formal protocol (#3876)
## Description Turns the informal `RNSTabBarControllerDelegate` category on `RNSTabsHostComponentView` into a proper `@protocol` defined in `RNSTabBarController.h`. This is a step toward fully decoupling `RNSTabBarController` from `RNSTabsHostComponentView` — a separate delegate property will follow once appearance configuration is also decoupled. ## Changes - Defined `@protocol RNSTabBarControllerDelegate <NSObject>` in `RNSTabBarController.h` with the 4 existing callback methods - Made `RNSTabsHostComponentView` conform to the new protocol - Removed the `RNSTabsHostComponentView (RNSTabBarControllerDelegate)` category from the header - Broke circular import chain (`RNSTabBarController.h` → `RNSTabBarAppearanceCoordinator.h` → `RNSTabsHostComponentView.h`) by downgrading the appearance coordinator's import to a forward declaration ## Test plan Build FabricExample iOS app — this is a purely structural refactor with no behavioral changes. ## Checklist - [ ] Included code example that can be used to test this change. - [ ] For visual changes, included screenshots / GIFs / recordings documenting the change. - [ ] For API changes, updated relevant public types. - [ ] Ensured that CI passes
1 parent eab4361 commit c231ff0

5 files changed

Lines changed: 31 additions & 25 deletions

File tree

ios/tabs/RNSTabBarAppearanceCoordinator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#pragma once
22

33
#import <Foundation/Foundation.h>
4-
#import "RNSTabsHostComponentView.h"
54
#import "RNSTabsScreenViewController.h"
65

6+
@class RNSTabsHostComponentView;
7+
78
NS_ASSUME_NONNULL_BEGIN
89

910
@class RCTImageLoader;

ios/tabs/RNSTabBarAppearanceCoordinator.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#import "RNSConversions.h"
66
#import "RNSImageLoadingHelper.h"
77
#import "RNSTabBarController.h"
8+
#import "RNSTabsHostComponentView.h"
89
#import "RNSTabsScreenViewController.h"
910

1011
@implementation RNSTabBarAppearanceCoordinator

ios/tabs/host/RNSTabBarController.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@
1111

1212
NS_ASSUME_NONNULL_BEGIN
1313

14+
@class RNSTabsHostComponentView;
15+
@class RNSTabBarController;
16+
17+
@protocol RNSTabBarControllerDelegate <NSObject>
18+
19+
- (void)tabBarController:(nonnull RNSTabBarController *)tabBarController
20+
didUpdateStateTo:(nonnull RNSTabsNavigationState *)navState
21+
withContext:(nonnull RNSTabsNavigationStateUpdateContext *)context;
22+
23+
- (void)tabBarController:(nonnull RNSTabBarController *)tabBarController
24+
rejectedStateUpdateTo:(nonnull RNSTabsNavigationState *)rejectedNavState
25+
currentState:(nonnull RNSTabsNavigationState *)currentNavState
26+
withReason:(RNSTabsNavigationStateRejectionReason)reasonCode;
27+
28+
- (void)tabBarController:(nonnull RNSTabBarController *)tabBarController
29+
preventedSelectionOf:(nonnull NSString *)screenKey
30+
currentState:(nonnull RNSTabsNavigationState *)currentNavState;
31+
32+
- (void)tabBarController:(nonnull RNSTabBarController *)tabBarController
33+
didSelectMoreTabWithCurrentState:(nonnull RNSTabsNavigationState *)currentNavState;
34+
35+
@end
36+
1437
@protocol RNSReactTransactionObserving
1538

1639
- (void)reactMountingTransactionWillMount;

ios/tabs/host/RNSTabBarController.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#import "NSString+RNSUtility.h"
77
#import "RNSLog.h"
88
#import "RNSScreenWindowTraits.h"
9+
#import "RNSTabsHostComponentView.h"
910

1011
#define RNS_MORE_NAVIGATION_CONTROLLER_AVAILABLE !TARGET_OS_TV && !TARGET_OS_VISION
1112

ios/tabs/host/RNSTabsHostComponentView.h

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
#import <React/RCTInvalidating.h>
1313
#endif
1414

15+
#import "RNSTabBarController.h"
16+
1517
NS_ASSUME_NONNULL_BEGIN
1618

17-
@class RNSTabBarController;
1819
@class RCTImageLoader;
1920

2021
/**
@@ -26,7 +27,8 @@ NS_ASSUME_NONNULL_BEGIN
2627
* 3. two way communication channel with React (commands & events)
2728
*/
2829
@interface RNSTabsHostComponentView : RNSReactBaseView <
29-
RNSScreenContainerDelegate
30+
RNSScreenContainerDelegate,
31+
RNSTabBarControllerDelegate
3032
#if !RCT_NEW_ARCH_ENABLED
3133
,
3234
RCTInvalidating
@@ -99,26 +101,4 @@ NS_ASSUME_NONNULL_BEGIN
99101

100102
@end
101103

102-
#pragma mark - RNSTabBarControllerDelegate
103-
104-
@interface RNSTabsHostComponentView (RNSTabBarControllerDelegate)
105-
106-
- (void)tabBarController:(nonnull RNSTabBarController *)tabBarController
107-
didUpdateStateTo:(nonnull RNSTabsNavigationState *)navState
108-
withContext:(nonnull RNSTabsNavigationStateUpdateContext *)context;
109-
110-
- (void)tabBarController:(nonnull RNSTabBarController *)tabBarController
111-
rejectedStateUpdateTo:(nonnull RNSTabsNavigationState *)rejectedNavState
112-
currentState:(nonnull RNSTabsNavigationState *)currentNavState
113-
withReason:(RNSTabsNavigationStateRejectionReason)reasonCode;
114-
115-
- (void)tabBarController:(nonnull RNSTabBarController *)tabBarController
116-
preventedSelectionOf:(nonnull NSString *)screenKey
117-
currentState:(nonnull RNSTabsNavigationState *)currentNavState;
118-
119-
- (void)tabBarController:(nonnull RNSTabBarController *)tabBarController
120-
didSelectMoreTabWithCurrentState:(nonnull RNSTabsNavigationState *)currentNavState;
121-
122-
@end
123-
124104
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)