11import SwiftUI
22
3- struct SidebarItem : Identifiable , Equatable {
3+ private struct SidebarItem : Identifiable , Equatable {
44 var id : Int { tag }
55 var tag : Int
66 var title : String
77 var subtitle : String ? = nil
88 var image : String ? = nil
99}
1010
11- struct SidebarItemPreferenceKey : PreferenceKey {
11+ private struct SidebarItemPreferenceKey : PreferenceKey {
1212 static var defaultValue : [ SidebarItem ] = [ ]
1313 static func reduce( value: inout [ SidebarItem ] , nextValue: ( ) -> [ SidebarItem ] ) {
1414 value. append ( contentsOf: nextValue ( ) )
1515 }
1616}
1717
18- struct SidebarTabTagKey : EnvironmentKey {
18+ private struct SidebarTabTagKey : EnvironmentKey {
1919 static var defaultValue : Int = 0
2020}
2121
22- extension EnvironmentValues {
22+ private extension EnvironmentValues {
2323 var sidebarTabTag : Int {
2424 get { self [ SidebarTabTagKey . self] }
2525 set { self [ SidebarTabTagKey . self] = newValue }
2626 }
2727}
2828
29- struct SidebarTabViewWrapper < Content: View > : View {
29+ private struct SidebarTabViewWrapper < Content: View > : View {
3030 @Environment ( \. sidebarTabTag) var sidebarTabTag
3131 var tag : Int
3232 var title : String
@@ -35,12 +35,17 @@ struct SidebarTabViewWrapper<Content: View>: View {
3535 var content : ( ) -> Content
3636
3737 var body : some View {
38- content ( )
39- . opacity ( tag != sidebarTabTag ? 0 : 1 )
40- . preference (
41- key: SidebarItemPreferenceKey . self,
42- value: [ . init( tag: tag, title: title, subtitle: subtitle, image: image) ]
43- )
38+ Group {
39+ if tag == sidebarTabTag {
40+ content ( )
41+ } else {
42+ Color . clear
43+ }
44+ }
45+ . preference (
46+ key: SidebarItemPreferenceKey . self,
47+ value: [ . init( tag: tag, title: title, subtitle: subtitle, image: image) ]
48+ )
4449 }
4550}
4651
@@ -62,7 +67,7 @@ extension View {
6267}
6368
6469struct SidebarTabView < Content: View > : View {
65- @State var sidebarItems = [ SidebarItem] ( )
70+ @State private var sidebarItems = [ SidebarItem] ( )
6671 @Binding var tag : Int
6772 @ViewBuilder var views : ( ) -> Content
6873 var body : some View {
@@ -87,7 +92,7 @@ struct SidebarTabView<Content: View>: View {
8792 Text ( subtitle)
8893 . lineSpacing ( 0 )
8994 . font ( . caption)
90- . foregroundStyle ( . tertiary )
95+ . foregroundStyle ( . secondary )
9196 . opacity ( 0.5 )
9297 . multilineTextAlignment ( . leading)
9398 }
@@ -101,8 +106,9 @@ struct SidebarTabView<Content: View>: View {
101106 in: RoundedRectangle ( cornerRadius: 4 )
102107 )
103108 . padding ( . horizontal, 8 )
109+ . contentShape ( Rectangle ( ) )
104110 }
105- . buttonStyle ( . borderless )
111+ . buttonStyle ( . plain )
106112 }
107113 }
108114 . frame ( width: 200 )
0 commit comments