@@ -56,50 +56,20 @@ struct TabViewImpl: View {
5656 var body : some View {
5757 TabView ( selection: $props. selectedPage) {
5858 ForEach ( props. children. indices, id: \. self) { index in
59- let child = props. children [ safe: index] ?? UIView ( )
60- let tabData = props. items [ safe: index]
61- let icon = props. icons [ index]
62-
63- RepresentableView ( view: child)
64- . ignoresTopSafeArea (
65- props. ignoresTopSafeArea ?? false ,
66- frame: child. frame
67- )
68- . tabItem {
69- TabItem (
70- title: tabData? . title,
71- icon: icon,
72- sfSymbol: tabData? . sfSymbol,
73- labeled: props. labeled
74- )
75- }
76- . tag ( tabData? . key)
77- . tabBadge ( tabData? . badge)
78- #if os(iOS)
79- . onAppear {
80- // SwiftUI doesn't change `selection` when clicked on items from the "More" list.
81- // More tab is visible only if we have more than 5 items.
82- // This is a workaround that fixes the "More" feature.
83- if index < 4 {
84- return
85- }
86- if let key = tabData? . key, props. selectedPage != key {
87- onSelect ( key)
88- }
89- }
90- #endif
59+ renderTabItem ( at: index)
9160 }
92-
9361 }
9462 . onTabItemEvent ( { index, isLongPress in
95- if let key = props. items [ safe: index] ? . key {
96- if isLongPress {
97- onLongPress ( key)
98- emitHapticFeedback ( longPress: true )
99- } else {
100- onSelect ( key)
101- emitHapticFeedback ( )
102- }
63+ guard let key = props. items. filter ( {
64+ !$0. hidden || $0. key == props. selectedPage
65+ } ) [ safe: index] ? . key else { return }
66+
67+ if isLongPress {
68+ onLongPress ( key)
69+ emitHapticFeedback ( longPress: true )
70+ } else {
71+ onSelect ( key)
72+ emitHapticFeedback ( )
10373 }
10474 } )
10575 . tintColor ( props. selectedActiveTintColor)
@@ -115,6 +85,42 @@ struct TabViewImpl: View {
11585 }
11686 }
11787
88+ @ViewBuilder
89+ private func renderTabItem( at index: Int ) -> some View {
90+ let tabData = props. items [ safe: index]
91+ let isHidden = tabData? . hidden ?? false
92+ let isFocused = props. selectedPage == tabData? . key
93+
94+ if !isHidden || isFocused {
95+ let child = props. children [ safe: index] ?? UIView ( )
96+ let icon = props. icons [ index]
97+
98+ RepresentableView ( view: child)
99+ . ignoresTopSafeArea (
100+ props. ignoresTopSafeArea ?? false ,
101+ frame: child. frame
102+ )
103+ . tabItem {
104+ TabItem (
105+ title: tabData? . title,
106+ icon: icon,
107+ sfSymbol: tabData? . sfSymbol,
108+ labeled: props. labeled
109+ )
110+ }
111+ . tag ( tabData? . key)
112+ . tabBadge ( tabData? . badge)
113+ #if os(iOS)
114+ . onAppear {
115+ guard index >= 4 ,
116+ let key = tabData? . key,
117+ props. selectedPage != key else { return }
118+ onSelect ( key)
119+ }
120+ #endif
121+ }
122+ }
123+
118124 func emitHapticFeedback( longPress: Bool = false ) {
119125#if os(iOS)
120126 if !props. hapticFeedbackEnabled {
0 commit comments