Skip to content

Commit 690d08e

Browse files
committed
chore: cleanup
1 parent 101c9d3 commit 690d08e

2 files changed

Lines changed: 33 additions & 20 deletions

File tree

apps/example/src/Examples/TintColors.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Article } from '../Screens/Article';
44
import { Albums } from '../Screens/Albums';
55
import { Contacts } from '../Screens/Contacts';
66
import { Chat } from '../Screens/Chat';
7+
import { Platform } from 'react-native';
78

89
const renderScene = SceneMap({
910
article: Article,
@@ -12,6 +13,8 @@ const renderScene = SceneMap({
1213
chat: Chat,
1314
});
1415

16+
const isAndroid = Platform.OS === 'android';
17+
1518
export default function TintColorsExample() {
1619
const [index, setIndex] = useState(0);
1720
const [routes] = useState([
@@ -31,7 +34,9 @@ export default function TintColorsExample() {
3134
},
3235
{
3336
key: 'contacts',
34-
focusedIcon: require('../../assets/icons/person_dark.png'),
37+
focusedIcon: isAndroid
38+
? require('../../assets/icons/person_dark.png')
39+
: { sfSymbol: 'person.fill' },
3540
title: 'Contacts',
3641
activeTintColor: 'blue',
3742
},

packages/react-native-bottom-tabs/ios/TabViewImpl.swift

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,16 @@ struct TabViewImpl: View {
115115

116116
#if !os(macOS)
117117
private func updateTabBarImages(props: TabViewProps, tabBar: UITabBar?) {
118-
guard let tabBar, let items = tabBar.items else { return }
118+
guard shouldApplyLiquidGlassTintWorkaround(),
119+
let tabBar,
120+
let items = tabBar.items else { return }
121+
119122
configureTabBarItemImages(items: items, props: props)
120-
configureTabBarItemImagesAfterLayout(tabBar: tabBar, props: props)
123+
124+
DispatchQueue.main.async { [weak tabBar] in
125+
guard let tabBar, let items = tabBar.items else { return }
126+
configureTabBarItemImages(items: items, props: props)
127+
}
121128
}
122129

123130
private func updateTabBarAppearance(props: TabViewProps, tabBar: UITabBar?) {
@@ -219,13 +226,12 @@ struct TabViewImpl: View {
219226
let tabActiveColor = tabData.activeTintColor ?? props.activeTintColor
220227
let assetIcon = props.icons[itemIndex]
221228
let icon = assetIcon ?? makeSFSymbolImage(named: tabData.sfSymbol)
229+
let shouldRenderLabelIntoImage = props.labeled && tabData.role != .search && icon != nil
222230

223-
if shouldRenderTabBarLabelsIntoImages(),
224-
props.labeled,
225-
tabData.role != .search,
226-
let icon {
231+
item.accessibilityLabel = tabData.title
232+
233+
if shouldRenderLabelIntoImage, let icon {
227234
item.title = ""
228-
item.accessibilityLabel = tabData.title
229235
item.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: 100)
230236
item.image = makeTabBarItemImage(
231237
icon: icon,
@@ -242,6 +248,9 @@ struct TabViewImpl: View {
242248
continue
243249
}
244250

251+
item.title = props.labeled ? tabData.title : nil
252+
item.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: 0)
253+
245254
if let icon {
246255
item.image = props.inactiveTintColor.map {
247256
icon.withTintColor($0, renderingMode: .alwaysOriginal)
@@ -269,15 +278,6 @@ struct TabViewImpl: View {
269278
return UIImage(systemName: sfSymbol)
270279
}
271280

272-
private func configureTabBarItemImagesAfterLayout(tabBar: UITabBar, props: TabViewProps) {
273-
guard shouldRenderTabBarLabelsIntoImages() else { return }
274-
275-
DispatchQueue.main.async { [weak tabBar] in
276-
guard let tabBar, let items = tabBar.items else { return }
277-
configureTabBarItemImages(items: items, props: props)
278-
}
279-
}
280-
281281
private func selectedAttributes(props: TabViewProps) -> [NSAttributedString.Key: Any] {
282282
TabBarFontSize.createFontAttributes(
283283
size: props.fontSize.map(CGFloat.init) ?? TabBarFontSize.defaultSize,
@@ -287,9 +287,14 @@ struct TabViewImpl: View {
287287
)
288288
}
289289

290-
private func shouldRenderTabBarLabelsIntoImages() -> Bool {
291-
let version = ProcessInfo.processInfo.operatingSystemVersion
292-
return version.majorVersion >= 26
290+
private func shouldApplyLiquidGlassTintWorkaround() -> Bool {
291+
#if os(iOS)
292+
if #available(iOS 26.0, *) {
293+
return true
294+
}
295+
#endif
296+
297+
return false
293298
}
294299

295300
private func makeTabBarItemImage(
@@ -427,6 +432,9 @@ extension View {
427432
.onChange(of: props.iconsRevision) { _ in
428433
updateTabBarImages(props: props, tabBar: tabBar)
429434
}
435+
.onChange(of: props.labeled) { _ in
436+
updateTabBarImages(props: props, tabBar: tabBar)
437+
}
430438
.onChange(of: props.fontSize) { _ in
431439
updateTabBarAppearance(props: props, tabBar: tabBar)
432440
updateTabBarImages(props: props, tabBar: tabBar)

0 commit comments

Comments
 (0)