Skip to content

Commit e308c90

Browse files
authored
fix: make sure everything works correctly on macOS (#443)
1 parent cf3b78e commit e308c90

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

.changeset/busy-seals-relax.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-native-bottom-tabs': patch
3+
---
4+
5+
fix: make sure everything works correctly on macOS

packages/react-native-bottom-tabs/ios/TabBarFontSize.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import React
2+
#if os(macOS)
3+
import AppKit
4+
#else
25
import UIKit
6+
#endif
37

48
enum TabBarFontSize {
59
/// Returns the default font size for tab bar item labels based on the current platform
610
#if os(tvOS)
711
static let defaultSize: CGFloat = 30.0
12+
#elseif os(macOS)
13+
static let defaultSize: CGFloat = 11.0
814
#else
915
static let defaultSize: CGFloat = {
1016
if UIDevice.current.userInterfaceIdiom == .pad {

packages/react-native-bottom-tabs/ios/TabViewImpl.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ struct TabViewImpl: View {
2020
onLayout: onLayout,
2121
onSelect: onSelect
2222
) {
23+
#if !os(macOS)
2324
updateTabBarAppearance(props: props, tabBar: tabBar)
25+
#endif
2426
}
2527
} else {
2628
LegacyTabView(
2729
props: props,
2830
onLayout: onLayout,
2931
onSelect: onSelect
3032
) {
33+
#if !os(macOS)
3134
updateTabBarAppearance(props: props, tabBar: tabBar)
35+
#endif
3236
}
3337
}
3438
}
@@ -57,8 +61,10 @@ struct TabViewImpl: View {
5761
}
5862
#endif
5963
.introspectTabView { tabController in
64+
#if !os(macOS)
6065
tabController.view.backgroundColor = .clear
6166
tabController.viewControllers?.forEach { $0.view.backgroundColor = .clear }
67+
#endif
6268
#if os(macOS)
6369
tabBar = tabController
6470
#else
@@ -276,7 +282,7 @@ extension View {
276282
@ViewBuilder
277283
func tabBarMinimizeBehavior(_ behavior: MinimizeBehavior?) -> some View {
278284
#if compiler(>=6.2)
279-
if #available(iOS 26.0, *) {
285+
if #available(iOS 26.0, macOS 26.0, *) {
280286
if let behavior {
281287
self.tabBarMinimizeBehavior(behavior.convert())
282288
} else {

packages/react-native-bottom-tabs/ios/TabViewProps.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ internal enum MinimizeBehavior: String {
77
case onScrollDown
88

99
#if compiler(>=6.2)
10-
@available(iOS 26.0, *)
10+
@available(iOS 26.0, macOS 26.0, *)
1111
func convert() -> TabBarMinimizeBehavior {
12+
#if os(macOS)
13+
return .automatic
14+
#else
1215
switch self {
1316
case .automatic:
1417
return .automatic
@@ -19,6 +22,7 @@ internal enum MinimizeBehavior: String {
1922
case .onScrollDown:
2023
return .onScrollDown
2124
}
25+
#endif
2226
}
2327
#endif
2428
}

packages/react-native-bottom-tabs/ios/TabViewProvider.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public final class TabInfo: NSObject {
165165
self.init()
166166
self.delegate = delegate
167167
}
168-
168+
169169
@objc public func setImageLoader(_ imageLoader: RCTImageLoader) {
170170
self.imageLoader = imageLoader
171171
loadIcons(icons)
@@ -204,7 +204,9 @@ public final class TabInfo: NSObject {
204204

205205
if let hostingController = self.hostingController, let parentViewController = reactViewController() {
206206
parentViewController.addChild(hostingController)
207+
#if !os(macOS)
207208
hostingController.view.backgroundColor = .clear
209+
#endif
208210
addSubview(hostingController.view)
209211
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
210212
hostingController.view.pinEdges(to: self)
@@ -215,7 +217,7 @@ public final class TabInfo: NSObject {
215217
}
216218

217219
@objc(insertChild:atIndex:)
218-
public func insertChild(_ child: UIView, at index: Int) {
220+
public func insertChild(_ child: PlatformView, at index: Int) {
219221
guard index >= 0 && index <= props.children.count else {
220222
return
221223
}
@@ -232,7 +234,7 @@ public final class TabInfo: NSObject {
232234

233235
private func loadIcons(_ icons: NSArray?) {
234236
guard let imageLoader else { return }
235-
237+
236238
// TODO: Diff the arrays and update only changed items.
237239
// Now if the user passes `unfocusedIcon` we update every item.
238240
if let imageSources = icons as? [RCTImageSource?] {
@@ -244,7 +246,7 @@ public final class TabInfo: NSObject {
244246
scale: imageSource.scale,
245247
clipped: true,
246248
resizeMode: RCTResizeMode.contain,
247-
progressBlock: { _,_ in },
249+
progressBlock: { _, _ in },
248250
partialLoad: { _ in },
249251
completionBlock: { error, image in
250252
if error != nil {
@@ -254,7 +256,7 @@ public final class TabInfo: NSObject {
254256
guard let image else { return }
255257
DispatchQueue.main.async { [weak self] in
256258
guard let self else { return }
257-
self.props.icons[index] = image.resizeImageTo(size: self.iconSize)
259+
props.icons[index] = image.resizeImageTo(size: iconSize)
258260
}
259261
})
260262
}

0 commit comments

Comments
 (0)