@@ -15,6 +15,7 @@ class TabViewProps: ObservableObject {
1515 @Published var ignoresTopSafeArea : Bool ?
1616 @Published var disablePageAnimations : Bool = false
1717 @Published var scrollEdgeAppearance : String ?
18+ @Published var barTintColor : UIColor ?
1819 @Published var translucent : Bool = true
1920}
2021
@@ -63,7 +64,6 @@ struct TabViewImpl: View {
6364 }
6465 }
6566 . getSidebarAdaptable ( enabled: props. sidebarAdaptable ?? false )
66- . tabBarTranslucent ( props. translucent)
6767 . onChange ( of: props. selectedPage ?? " " ) { newValue in
6868 if ( props. disablePageAnimations) {
6969 UIView . setAnimationsEnabled ( false )
@@ -73,16 +73,22 @@ struct TabViewImpl: View {
7373 }
7474 onSelect ( newValue)
7575 }
76+ . onAppear ( ) {
77+ updateTabBarAppearance ( props: props)
78+ }
79+ . onChange ( of: props. barTintColor) { newValue in
80+ updateTabBarAppearance ( props: props)
81+ }
7682 . 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)
8087 }
8188 }
8289}
8390
84- private func configureAppearance( for appearanceType: String ) -> UITabBarAppearance {
85- let appearance = UITabBarAppearance ( )
91+ private func configureAppearance( for appearanceType: String , appearance: UITabBarAppearance ) -> UITabBarAppearance {
8692
8793 switch appearanceType {
8894 case " opaque " :
@@ -96,6 +102,27 @@ private func configureAppearance(for appearanceType: String) -> UITabBarAppearan
96102 return appearance
97103}
98104
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+
99126struct TabItem : View {
100127 var title : String ?
101128 var icon : UIImage ?
@@ -159,15 +186,4 @@ extension View {
159186 . frame ( idealWidth: frame. width, idealHeight: frame. height)
160187 }
161188 }
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- }
173189}
0 commit comments