Skip to content

Commit 5de6709

Browse files
committed
feat: create NewTabView implementation
1 parent 4e6764d commit 5de6709

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import SwiftUI
2+
3+
@available(iOS 18, macOS 15, visionOS 2, tvOS 18, *)
4+
struct NewTabView: View {
5+
@ObservedObject var props: TabViewProps
6+
@AppStorage("sidebarCustomizations") var tabViewCustomization: TabViewCustomization
7+
8+
#if os(macOS)
9+
var tabBar: NSTabView?
10+
#else
11+
var tabBar: UITabBar?
12+
#endif
13+
14+
var onLayout: (_ size: CGSize) -> Void
15+
var onSelect: (_ key: String) -> Void
16+
var updateTabBarAppearance: (_ props: TabViewProps, _ tabBar: UITabBar?) -> Void
17+
18+
@ViewBuilder
19+
var body: some View {
20+
TabView(selection: $props.selectedPage) {
21+
ForEach(props.children.indices, id: \.self) { index in
22+
if let tabData = props.items[safe: index] {
23+
let isFocused = props.selectedPage == tabData.key
24+
25+
if !tabData.hidden || isFocused {
26+
let icon = props.icons[index]
27+
let role: TabRole? = nil
28+
29+
let platformChild = props.children[safe: index] ?? PlatformView()
30+
let child = RepresentableView(view: platformChild)
31+
32+
Tab(value: tabData.key, role: role) {
33+
child
34+
.ignoresSafeArea(.container, edges: .all)
35+
.onAppear {
36+
#if !os(macOS)
37+
updateTabBarAppearance(props, tabBar)
38+
#endif
39+
#if os(iOS)
40+
if index >= 4 {
41+
if props.selectedPage != tabData.key {
42+
onSelect(tabData.key)
43+
}
44+
}
45+
#endif
46+
}
47+
} label: {
48+
TabItem(
49+
title: tabData.title,
50+
icon: icon,
51+
sfSymbol: tabData.sfSymbol,
52+
labeled: props.labeled
53+
)
54+
}
55+
//.badge(tabData.badge)
56+
.customizationID(tabData.key)
57+
.customizationBehavior(.disabled, for: .sidebar, .tabBar)
58+
.accessibilityIdentifier(tabData.testID ?? "")
59+
}
60+
}
61+
}
62+
}
63+
.measureView { size in
64+
onLayout(size)
65+
}
66+
.tabViewCustomization($tabViewCustomization)
67+
.hideTabBar(props.tabBarHidden)
68+
}
69+
}

0 commit comments

Comments
 (0)