Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/busy-seals-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-native-bottom-tabs': patch
---

fix: make sure everything works correctly on macOS
6 changes: 6 additions & 0 deletions packages/react-native-bottom-tabs/ios/TabBarFontSize.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import React
#if os(macOS)
import AppKit
#else
import UIKit
#endif

enum TabBarFontSize {
/// Returns the default font size for tab bar item labels based on the current platform
#if os(tvOS)
static let defaultSize: CGFloat = 30.0
#elseif os(macOS)
static let defaultSize: CGFloat = 11.0
#else
static let defaultSize: CGFloat = {
if UIDevice.current.userInterfaceIdiom == .pad {
Expand Down Expand Up @@ -35,7 +41,7 @@
attributes[.font] = RCTFont.update(
nil,
withFamily: family,
size: NSNumber(value: size),

Check warning on line 44 in packages/react-native-bottom-tabs/ios/TabBarFontSize.swift

View workflow job for this annotation

GitHub Actions / swift-lint

Legacy Objective-C Reference Type Violation: Prefer Swift value types to bridged Objective-C reference types (legacy_objc_type)
weight: weight,
style: nil,
variant: nil,
Expand Down
8 changes: 7 additions & 1 deletion packages/react-native-bottom-tabs/ios/TabViewImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ struct TabViewImpl: View {
onLayout: onLayout,
onSelect: onSelect
) {
#if !os(macOS)
updateTabBarAppearance(props: props, tabBar: tabBar)
#endif
}
} else {
LegacyTabView(
props: props,
onLayout: onLayout,
onSelect: onSelect
) {
#if !os(macOS)
updateTabBarAppearance(props: props, tabBar: tabBar)
#endif
}
}
}
Expand Down Expand Up @@ -57,8 +61,10 @@ struct TabViewImpl: View {
}
#endif
.introspectTabView { tabController in
#if !os(macOS)
tabController.view.backgroundColor = .clear
tabController.viewControllers?.forEach { $0.view.backgroundColor = .clear }
#endif
#if os(macOS)
tabBar = tabController
#else
Expand Down Expand Up @@ -276,7 +282,7 @@ extension View {
@ViewBuilder
func tabBarMinimizeBehavior(_ behavior: MinimizeBehavior?) -> some View {
#if compiler(>=6.2)
if #available(iOS 26.0, *) {
if #available(iOS 26.0, macOS 26.0, *) {
if let behavior {
self.tabBarMinimizeBehavior(behavior.convert())
} else {
Expand Down
6 changes: 5 additions & 1 deletion packages/react-native-bottom-tabs/ios/TabViewProps.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ internal enum MinimizeBehavior: String {
case onScrollDown

#if compiler(>=6.2)
@available(iOS 26.0, *)
@available(iOS 26.0, macOS 26.0, *)
func convert() -> TabBarMinimizeBehavior {
#if os(macOS)
return .automatic
#else
switch self {
case .automatic:
return .automatic
Expand All @@ -19,6 +22,7 @@ internal enum MinimizeBehavior: String {
case .onScrollDown:
return .onScrollDown
}
#endif
}
#endif
}
Expand Down
12 changes: 7 additions & 5 deletions packages/react-native-bottom-tabs/ios/TabViewProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
}

@objc public protocol TabViewProviderDelegate {
func onPageSelected(key: String, reactTag: NSNumber?)

Check warning on line 42 in packages/react-native-bottom-tabs/ios/TabViewProvider.swift

View workflow job for this annotation

GitHub Actions / swift-lint

Legacy Objective-C Reference Type Violation: Prefer Swift value types to bridged Objective-C reference types (legacy_objc_type)
func onLongPress(key: String, reactTag: NSNumber?)

Check warning on line 43 in packages/react-native-bottom-tabs/ios/TabViewProvider.swift

View workflow job for this annotation

GitHub Actions / swift-lint

Legacy Objective-C Reference Type Violation: Prefer Swift value types to bridged Objective-C reference types (legacy_objc_type)
func onTabBarMeasured(height: Int, reactTag: NSNumber?)

Check warning on line 44 in packages/react-native-bottom-tabs/ios/TabViewProvider.swift

View workflow job for this annotation

GitHub Actions / swift-lint

Legacy Objective-C Reference Type Violation: Prefer Swift value types to bridged Objective-C reference types (legacy_objc_type)
func onLayout(size: CGSize, reactTag: NSNumber?)
}

Expand Down Expand Up @@ -165,7 +165,7 @@
self.init()
self.delegate = delegate
}

@objc public func setImageLoader(_ imageLoader: RCTImageLoader) {
self.imageLoader = imageLoader
loadIcons(icons)
Expand Down Expand Up @@ -204,7 +204,9 @@

if let hostingController = self.hostingController, let parentViewController = reactViewController() {
parentViewController.addChild(hostingController)
#if !os(macOS)
hostingController.view.backgroundColor = .clear
#endif
addSubview(hostingController.view)
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
hostingController.view.pinEdges(to: self)
Expand All @@ -215,7 +217,7 @@
}

@objc(insertChild:atIndex:)
public func insertChild(_ child: UIView, at index: Int) {
public func insertChild(_ child: PlatformView, at index: Int) {
guard index >= 0 && index <= props.children.count else {
return
}
Expand All @@ -232,7 +234,7 @@

private func loadIcons(_ icons: NSArray?) {
guard let imageLoader else { return }

// TODO: Diff the arrays and update only changed items.
// Now if the user passes `unfocusedIcon` we update every item.
if let imageSources = icons as? [RCTImageSource?] {
Expand All @@ -244,7 +246,7 @@
scale: imageSource.scale,
clipped: true,
resizeMode: RCTResizeMode.contain,
progressBlock: { _,_ in },
progressBlock: { _, _ in },
partialLoad: { _ in },
completionBlock: { error, image in
if error != nil {
Expand All @@ -254,7 +256,7 @@
guard let image else { return }
DispatchQueue.main.async { [weak self] in
guard let self else { return }
self.props.icons[index] = image.resizeImageTo(size: self.iconSize)
props.icons[index] = image.resizeImageTo(size: iconSize)
}
})
}
Expand Down
Loading