@@ -15,6 +15,7 @@ class TabViewProps: ObservableObject {
15
15
@Published var ignoresTopSafeArea : Bool ?
16
16
@Published var disablePageAnimations : Bool = false
17
17
@Published var scrollEdgeAppearance : String ?
18
+ @Published var barTintColor : UIColor ?
18
19
@Published var translucent : Bool = true
19
20
}
20
21
@@ -63,7 +64,6 @@ struct TabViewImpl: View {
63
64
}
64
65
}
65
66
. getSidebarAdaptable ( enabled: props. sidebarAdaptable ?? false )
66
- . tabBarTranslucent ( props. translucent)
67
67
. onChange ( of: props. selectedPage ?? " " ) { newValue in
68
68
if ( props. disablePageAnimations) {
69
69
UIView . setAnimationsEnabled ( false )
@@ -73,16 +73,22 @@ struct TabViewImpl: View {
73
73
}
74
74
onSelect ( newValue)
75
75
}
76
+ . onAppear ( ) {
77
+ updateTabBarAppearance ( props: props)
78
+ }
79
+ . onChange ( of: props. barTintColor) { newValue in
80
+ updateTabBarAppearance ( props: props)
81
+ }
76
82
. onChange ( of: props. scrollEdgeAppearance) { newValue in
77
- if #available( iOS 15 . 0 , * ) {
78
- UITabBar . appearance ( ) . scrollEdgeAppearance = configureAppearance ( for: newValue ?? " " )
79
- }
83
+ updateTabBarAppearance ( props: props)
84
+ }
85
+ . onChange ( of: props. translucent) { newValue in
86
+ updateTabBarAppearance ( props: props)
80
87
}
81
88
}
82
89
}
83
90
84
- private func configureAppearance( for appearanceType: String ) -> UITabBarAppearance {
85
- let appearance = UITabBarAppearance ( )
91
+ private func configureAppearance( for appearanceType: String , appearance: UITabBarAppearance ) -> UITabBarAppearance {
86
92
87
93
switch appearanceType {
88
94
case " opaque " :
@@ -96,6 +102,27 @@ private func configureAppearance(for appearanceType: String) -> UITabBarAppearan
96
102
return appearance
97
103
}
98
104
105
+ private func updateTabBarAppearance( props: TabViewProps ) {
106
+ if #available( iOS 15 . 0 , * ) {
107
+ let appearance = UITabBarAppearance ( )
108
+
109
+ UITabBar . appearance ( ) . scrollEdgeAppearance = configureAppearance ( for: props. scrollEdgeAppearance ?? " " , appearance: appearance)
110
+
111
+ if props. translucent == false {
112
+ appearance. configureWithOpaqueBackground ( )
113
+ }
114
+
115
+ if props. barTintColor != nil {
116
+ appearance. backgroundColor = props. barTintColor
117
+ }
118
+
119
+ UITabBar . appearance ( ) . standardAppearance = appearance
120
+ } else {
121
+ UITabBar . appearance ( ) . barTintColor = props. barTintColor
122
+ UITabBar . appearance ( ) . isTranslucent = props. translucent
123
+ }
124
+ }
125
+
99
126
struct TabItem : View {
100
127
var title : String ?
101
128
var icon : UIImage ?
@@ -159,15 +186,4 @@ extension View {
159
186
. frame ( idealWidth: frame. width, idealHeight: frame. height)
160
187
}
161
188
}
162
-
163
- @ViewBuilder
164
- func tabBarTranslucent( _ translucent: Bool ) -> some View {
165
- self
166
- . onAppear {
167
- UITabBar . appearance ( ) . isTranslucent = translucent
168
- }
169
- . onChange ( of: translucent) { newValue in
170
- UITabBar . appearance ( ) . isTranslucent = newValue
171
- }
172
- }
173
189
}
0 commit comments