Skip to content

Commit e6d79df

Browse files
committed
refactor to a BottomAccessoryProvider
1 parent 28af2bc commit e6d79df

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import SwiftUI
2+
3+
@objc public class BottomAccessoryProvider: PlatformView {
4+
private weak var delegate: BottomAccessoryProviderDelegate?
5+
6+
@objc public convenience init(delegate: BottomAccessoryProviderDelegate) {
7+
self.init()
8+
self.delegate = delegate
9+
}
10+
11+
@available(iOS 26.0, *)
12+
public func emitPlacementChanged(_ placement: TabViewBottomAccessoryPlacement?) {
13+
var placementValue = "none"
14+
if placement == .inline {
15+
placementValue = "inline"
16+
} else if placement == .expanded {
17+
placementValue = "expanded"
18+
}
19+
self.delegate?.onPlacementChanged(placement: placementValue)
20+
}
21+
}
22+
23+
@objc public protocol BottomAccessoryProviderDelegate {
24+
func onPlacementChanged(placement: String)
25+
}

packages/react-native-bottom-tabs/ios/RCTBottomAccessoryComponentView.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ NS_ASSUME_NONNULL_BEGIN
1010

1111
@interface RCTBottomAccessoryComponentView: RCTViewComponentView
1212

13-
- (void)emitOnPlacementChanged:(NSString *)placement;
14-
1513
@end
1614

1715
NS_ASSUME_NONNULL_END

packages/react-native-bottom-tabs/ios/RCTBottomAccessoryComponentView.mm

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
using namespace facebook::react;
1818

19+
@interface RCTBottomAccessoryComponentView () <BottomAccessoryProviderDelegate> {
20+
}
21+
@end
22+
1923
@implementation RCTBottomAccessoryComponentView
2024

2125
+ (ComponentDescriptorProvider)componentDescriptorProvider
@@ -27,6 +31,9 @@ - (instancetype)initWithFrame:(CGRect)frame
2731
{
2832
if (self = [super initWithFrame:frame]) {
2933
static const auto defaultProps = std::make_shared<const BottomAccessoryViewProps>();
34+
if (@available(iOS 26.0, *)) {
35+
self.contentView = [[BottomAccessoryProvider alloc] initWithDelegate:self];
36+
}
3037
}
3138

3239
return self;
@@ -49,7 +56,10 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
4956
[super updateProps:props oldProps:oldProps];
5057
}
5158

52-
- (void)emitOnPlacementChanged:(NSString *)placement {
59+
// MARK: BottomAccessoryProviderDelegate
60+
61+
- (void)onPlacementChangedWithPlacement:(NSString *)placement
62+
{
5363
auto eventEmitter = std::static_pointer_cast<const BottomAccessoryViewEventEmitter>(_eventEmitter);
5464
if (eventEmitter) {
5565
eventEmitter->onPlacementChanged(BottomAccessoryViewEventEmitter::OnPlacementChanged {

packages/react-native-bottom-tabs/ios/TabView/NewTabView.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,8 @@ struct BottomAccessoryRepresentableView: PlatformViewRepresentable {
119119
}
120120

121121
private func emitPlacementChanged(for uiView: PlatformView) {
122-
let selectorString = "emitOnPlacementChanged:"
123-
let selector = NSSelectorFromString(selectorString)
124-
if uiView.responds(to: selector) {
125-
var placementValue = "none"
126-
if tabViewBottomAccessoryPlacement == .inline {
127-
placementValue = "inline"
128-
} else if (tabViewBottomAccessoryPlacement == .expanded) {
129-
placementValue = "expanded"
130-
}
131-
uiView.perform(selector, with: placementValue)
122+
if let contentView = uiView.value(forKey: "contentView") as? BottomAccessoryProvider {
123+
contentView.emitPlacementChanged(tabViewBottomAccessoryPlacement)
132124
}
133125
}
134126
}

0 commit comments

Comments
 (0)