@@ -71,7 +71,7 @@ struct TabViewImpl: View {
7171 #else
7272 tabBar = tabController. tabBar
7373 updateTabBarAppearance ( props: props, tabBar: tabController. tabBar)
74- updateExperimentalBakedTintColors ( props: props, tabBar: tabController. tabBar)
74+ updateTabBarItemImages ( props: props, tabBar: tabController. tabBar)
7575 if !props. tabBarHidden {
7676 onTabBarMeasured (
7777 Int ( tabController. tabBar. frame. size. height)
@@ -115,17 +115,16 @@ struct TabViewImpl: View {
115115}
116116
117117#if !os(macOS)
118- private func updateExperimentalBakedTintColors( props: TabViewProps , tabBar: UITabBar ? ) {
119- guard shouldUseExperimentalBakedTintColors ( props: props) ,
120- let tabBar,
118+ private func updateTabBarItemImages( props: TabViewProps , tabBar: UITabBar ? ) {
119+ guard let tabBar,
121120 let items = tabBar. items
122121 else { return }
123122
124- configureExperimentalBakedTintColors ( items: items, props: props)
123+ configureTabBarItemImages ( items: items, props: props)
125124
126125 DispatchQueue . main. async { [ weak tabBar] in
127126 guard let tabBar, let items = tabBar. items else { return }
128- configureExperimentalBakedTintColors ( items: items, props: props)
127+ configureTabBarItemImages ( items: items, props: props)
129128 }
130129 }
131130
@@ -220,7 +219,7 @@ struct TabViewImpl: View {
220219 }
221220 }
222221
223- private func configureExperimentalBakedTintColors ( items: [ UITabBarItem ] , props: TabViewProps ) {
222+ private func configureTabBarItemImages ( items: [ UITabBarItem ] , props: TabViewProps ) {
224223 for (tabBarIndex, item) in items. enumerated ( ) {
225224 guard let tabData = props. filteredItems [ safe: tabBarIndex] ,
226225 let itemIndex = props. items. firstIndex ( where: { $0. key == tabData. key } )
@@ -232,12 +231,13 @@ struct TabViewImpl: View {
232231 let focusedIcon =
233232 props. focusedIcons [ itemIndex] ?? makeSFSymbolImage ( named: tabData. focusedSfSymbol) ?? icon
234233 let preservesOriginalIconColors = preservesOriginalIconColors ( tabData: tabData)
234+ let useBakedTintColors = shouldUseExperimentalBakedTintColors ( props: props)
235235 let shouldRenderLabelIntoImage =
236236 props. hasCustomTintColors && props. labeled && tabData. role != . search && icon != nil
237237
238238 item. accessibilityLabel = tabData. title
239239
240- if shouldRenderLabelIntoImage, let icon {
240+ if useBakedTintColors , shouldRenderLabelIntoImage, let icon {
241241 let selectedIcon = focusedIcon ?? icon
242242 item. title = " "
243243 item. titlePositionAdjustment = UIOffset ( horizontal: 0 , vertical: 100 )
@@ -263,19 +263,18 @@ struct TabViewImpl: View {
263263
264264 if let icon {
265265 let selectedIcon = focusedIcon ?? icon
266- if preservesOriginalIconColors {
267- item. image = icon. withRenderingMode ( . alwaysOriginal)
268- item. selectedImage = selectedIcon. withRenderingMode ( . alwaysOriginal)
269- } else {
270- item. image =
271- props. inactiveTintColor. map {
272- icon. withTintColor ( $0, renderingMode: . alwaysOriginal)
273- } ?? icon
274- item. selectedImage =
275- tabActiveColor. map {
276- selectedIcon. withTintColor ( $0, renderingMode: . alwaysOriginal)
277- } ?? selectedIcon
278- }
266+ item. image = renderTabBarIcon (
267+ icon,
268+ color: props. inactiveTintColor,
269+ preservesOriginalIconColors: preservesOriginalIconColors,
270+ forceTintColor: useBakedTintColors
271+ )
272+ item. selectedImage = renderTabBarIcon (
273+ selectedIcon,
274+ color: tabActiveColor,
275+ preservesOriginalIconColors: preservesOriginalIconColors,
276+ forceTintColor: useBakedTintColors
277+ )
279278 }
280279
281280 item. setTitleTextAttributes (
@@ -290,31 +289,25 @@ struct TabViewImpl: View {
290289 }
291290 }
292291
293- private func resetExperimentalBakedTintColors( props: TabViewProps , tabBar: UITabBar ? ) {
294- guard let tabBar,
295- let items = tabBar. items
296- else { return }
297-
298- for (tabBarIndex, item) in items. enumerated ( ) {
299- guard let tabData = props. filteredItems [ safe: tabBarIndex] ,
300- let itemIndex = props. items. firstIndex ( where: { $0. key == tabData. key } )
301- else { continue }
292+ private func preservesOriginalIconColors( tabData: TabInfo ) -> Bool {
293+ tabData. iconRenderingMode == " original "
294+ }
302295
303- let assetIcon = props. icons [ itemIndex]
304- let icon = assetIcon ?? makeSFSymbolImage ( named: tabData. sfSymbol)
305- let originalIcon = icon. map {
306- preservesOriginalIconColors ( tabData: tabData) ? $0. withRenderingMode ( . alwaysOriginal) : $0
307- }
296+ private func renderTabBarIcon(
297+ _ icon: UIImage ,
298+ color: UIColor ? ,
299+ preservesOriginalIconColors: Bool ,
300+ forceTintColor: Bool
301+ ) -> UIImage {
302+ if preservesOriginalIconColors {
303+ return icon. withRenderingMode ( . alwaysOriginal)
304+ }
308305
309- item. title = props. labeled ? tabData. title : nil
310- item. titlePositionAdjustment = UIOffset ( horizontal: 0 , vertical: 0 )
311- item. image = originalIcon
312- item. selectedImage = originalIcon
306+ guard forceTintColor, let color else {
307+ return icon
313308 }
314- }
315309
316- private func preservesOriginalIconColors( tabData: TabInfo ) -> Bool {
317- tabData. iconRenderingMode == " original "
310+ return icon. withTintColor ( color, renderingMode: . alwaysOriginal)
318311 }
319312
320313 private func makeSFSymbolImage( named sfSymbol: String ? ) -> UIImage ? {
@@ -476,40 +469,36 @@ extension View {
476469 }
477470 . onChange ( of: props. inactiveTintColor) { _ in
478471 updateTabBarAppearance ( props: props, tabBar: tabBar)
479- updateExperimentalBakedTintColors ( props: props, tabBar: tabBar)
472+ updateTabBarItemImages ( props: props, tabBar: tabBar)
480473 }
481474 . onChange ( of: props. activeTintColor) { _ in
482475 updateTabBarAppearance ( props: props, tabBar: tabBar)
483- updateExperimentalBakedTintColors ( props: props, tabBar: tabBar)
476+ updateTabBarItemImages ( props: props, tabBar: tabBar)
484477 }
485478 . onChange ( of: props. selectedActiveTintColor) { newValue in
486479 tabBar? . tintColor = newValue
487480 }
488481 . onChange ( of: props. iconsRevision) { _ in
489- updateExperimentalBakedTintColors ( props: props, tabBar: tabBar)
482+ updateTabBarItemImages ( props: props, tabBar: tabBar)
490483 }
491484 . onChange ( of: props. labeled) { _ in
492- updateExperimentalBakedTintColors ( props: props, tabBar: tabBar)
485+ updateTabBarItemImages ( props: props, tabBar: tabBar)
493486 }
494487 . onChange ( of: props. fontSize) { _ in
495488 updateTabBarAppearance ( props: props, tabBar: tabBar)
496- updateExperimentalBakedTintColors ( props: props, tabBar: tabBar)
489+ updateTabBarItemImages ( props: props, tabBar: tabBar)
497490 }
498491 . onChange ( of: props. fontFamily) { _ in
499492 updateTabBarAppearance ( props: props, tabBar: tabBar)
500- updateExperimentalBakedTintColors ( props: props, tabBar: tabBar)
493+ updateTabBarItemImages ( props: props, tabBar: tabBar)
501494 }
502495 . onChange ( of: props. fontWeight) { _ in
503496 updateTabBarAppearance ( props: props, tabBar: tabBar)
504- updateExperimentalBakedTintColors ( props: props, tabBar: tabBar)
497+ updateTabBarItemImages ( props: props, tabBar: tabBar)
505498 }
506- . onChange ( of: props. experimentalBakedTintColors) { newValue in
499+ . onChange ( of: props. experimentalBakedTintColors) { _ in
507500 updateTabBarAppearance ( props: props, tabBar: tabBar)
508- if newValue {
509- updateExperimentalBakedTintColors ( props: props, tabBar: tabBar)
510- } else {
511- resetExperimentalBakedTintColors ( props: props, tabBar: tabBar)
512- }
501+ updateTabBarItemImages ( props: props, tabBar: tabBar)
513502 }
514503 . onChange ( of: props. tabBarHidden) { newValue in
515504 tabBar? . isHidden = newValue
0 commit comments