forked from callstack/react-native-bottom-tabs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewTabView.swift
More file actions
55 lines (49 loc) · 1.6 KB
/
NewTabView.swift
File metadata and controls
55 lines (49 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import SwiftUI
@available(iOS 18, macOS 15, visionOS 2, tvOS 18, *)
struct NewTabView: AnyTabView {
@ObservedObject var props: TabViewProps
var onLayout: (CGSize) -> Void
var onSelect: (String) -> Void
var updateTabBarAppearance: () -> Void
@ViewBuilder
var body: some View {
TabView(selection: $props.selectedPage) {
ForEach(props.children) { child in
if let index = props.children.firstIndex(of: child),
let tabData = props.items[safe: index] {
let isFocused = props.selectedPage == tabData.key
if !tabData.hidden || isFocused {
let icon = props.icons[index]
let context = TabAppearContext(
index: index,
tabData: tabData,
props: props,
updateTabBarAppearance: updateTabBarAppearance,
onSelect: onSelect
)
Tab(value: tabData.key, role: tabData.role?.convert()) {
RepresentableView(view: child.view)
.ignoresSafeArea(.container, edges: .all)
.tabAppear(using: context)
} label: {
TabItem(
title: tabData.title,
icon: icon,
sfSymbol: tabData.sfSymbol,
labeled: props.labeled
)
}
#if !os(tvOS)
.badge(tabData.badge.flatMap { !$0.isEmpty ? Text($0) : nil })
#endif
.accessibilityIdentifier(tabData.testID ?? "")
}
}
}
}
.measureView { size in
onLayout(size)
}
.hideTabBar(props.tabBarHidden)
}
}