Skip to content

Commit ccf1b89

Browse files
committed
fix(iOS): fix glitch when switching tabs first time
1 parent 16ec5b4 commit ccf1b89

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct TabViewImpl: View {
7070
#else
7171
tabBar = tabController.tabBar
7272
updateTabBarAppearance(props: props, tabBar: tabController.tabBar)
73+
updateTabBarImages(props: props, tabBar: tabController.tabBar)
7374
if !props.tabBarHidden {
7475
onTabBarMeasured(
7576
Int(tabController.tabBar.frame.size.height)
@@ -113,6 +114,12 @@ struct TabViewImpl: View {
113114
}
114115

115116
#if !os(macOS)
117+
private func updateTabBarImages(props: TabViewProps, tabBar: UITabBar?) {
118+
guard let tabBar, let items = tabBar.items else { return }
119+
configureTabBarItemImages(items: items, props: props)
120+
configureTabBarItemImagesAfterLayout(tabBar: tabBar, props: props)
121+
}
122+
116123
private func updateTabBarAppearance(props: TabViewProps, tabBar: UITabBar?) {
117124
guard let tabBar else { return }
118125

@@ -149,8 +156,6 @@ struct TabViewImpl: View {
149156
item.setTitleTextAttributes(fontAttributes, for: .normal)
150157
item.setTitleTextAttributes(selectedAttributes(props: props), for: .selected)
151158
}
152-
configureTabBarItemImages(items: items, props: props)
153-
configureTabBarItemImagesAfterLayout(tabBar: tabBar, props: props)
154159
}
155160

156161
private func configureStandardAppearance(tabBar: UITabBar, props: TabViewProps) {
@@ -204,10 +209,6 @@ struct TabViewImpl: View {
204209
if #available(iOS 15.0, *) {
205210
tabBar.scrollEdgeAppearance = appearance.copy()
206211
}
207-
if let items = tabBar.items {
208-
configureTabBarItemImages(items: items, props: props)
209-
configureTabBarItemImagesAfterLayout(tabBar: tabBar, props: props)
210-
}
211212
}
212213

213214
private func configureTabBarItemImages(items: [UITabBarItem], props: TabViewProps) {
@@ -381,24 +382,29 @@ extension View {
381382
}
382383
.onChange(of: props.inactiveTintColor) { _ in
383384
updateTabBarAppearance(props: props, tabBar: tabBar)
385+
updateTabBarImages(props: props, tabBar: tabBar)
384386
}
385387
.onChange(of: props.activeTintColor) { _ in
386388
updateTabBarAppearance(props: props, tabBar: tabBar)
389+
updateTabBarImages(props: props, tabBar: tabBar)
387390
}
388391
.onChange(of: props.selectedActiveTintColor) { newValue in
389392
tabBar?.tintColor = newValue
390393
}
391394
.onChange(of: props.iconsRevision) { _ in
392-
updateTabBarAppearance(props: props, tabBar: tabBar)
395+
updateTabBarImages(props: props, tabBar: tabBar)
393396
}
394397
.onChange(of: props.fontSize) { _ in
395398
updateTabBarAppearance(props: props, tabBar: tabBar)
399+
updateTabBarImages(props: props, tabBar: tabBar)
396400
}
397401
.onChange(of: props.fontFamily) { _ in
398402
updateTabBarAppearance(props: props, tabBar: tabBar)
403+
updateTabBarImages(props: props, tabBar: tabBar)
399404
}
400405
.onChange(of: props.fontWeight) { _ in
401406
updateTabBarAppearance(props: props, tabBar: tabBar)
407+
updateTabBarImages(props: props, tabBar: tabBar)
402408
}
403409
.onChange(of: props.tabBarHidden) { newValue in
404410
tabBar?.isHidden = newValue

0 commit comments

Comments
 (0)