File tree Expand file tree Collapse file tree 1 file changed +64
-0
lines changed
packages/react-native-bottom-tabs/ios/TabView Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+ import SwiftUI
2+
3+ struct LegacyTabView : View {
4+ @ObservedObject var props : TabViewProps
5+
6+ #if os(macOS)
7+ var tabBar : NSTabView ?
8+ #else
9+ var tabBar : UITabBar ?
10+ #endif
11+
12+ var onLayout : ( _ size: CGSize ) -> Void
13+ var onSelect : ( _ key: String ) -> Void
14+ var updateTabBarAppearance : ( _ props: TabViewProps , _ tabBar: UITabBar ? ) -> Void
15+
16+ @ViewBuilder
17+ var body : some View {
18+ TabView ( selection: $props. selectedPage) {
19+ ForEach ( props. children. indices, id: \. self) { index in
20+ renderTabItem ( at: index)
21+ }
22+ . measureView { size in
23+ onLayout ( size)
24+ }
25+ }
26+ . hideTabBar ( props. tabBarHidden)
27+ }
28+
29+ @ViewBuilder
30+ private func renderTabItem( at index: Int ) -> some View {
31+ if let tabData = props. items [ safe: index] {
32+ let isFocused = props. selectedPage == tabData. key
33+
34+ if !tabData. hidden || isFocused {
35+ let icon = props. icons [ index]
36+ let child = props. children [ safe: index] ?? PlatformView ( )
37+
38+ RepresentableView ( view: child)
39+ . ignoresSafeArea ( . container, edges: . all)
40+ . tabItem {
41+ TabItem (
42+ title: tabData. title,
43+ icon: icon,
44+ sfSymbol: tabData. sfSymbol,
45+ labeled: props. labeled
46+ )
47+ . accessibilityIdentifier ( tabData. testID ?? " " )
48+ . tag ( tabData. key)
49+ . tabBadge ( tabData. badge)
50+ . onAppear {
51+ #if !os(macOS)
52+ updateTabBarAppearance ( props, tabBar)
53+ #endif
54+ #if os(iOS)
55+ if index >= 4 , !isFocused {
56+ onSelect ( tabData. key)
57+ }
58+ #endif
59+ }
60+ }
61+ }
62+ }
63+ }
64+ }
You can’t perform that action at this time.
0 commit comments