After upgrading from Xcode 12.4 to 13.2 my app's TabView background is clear whenever it appears over my Mapbox map for the first time but the buttons appear and work as normal.
When the TabView appears over my other SwiftUI views it looks and behaves as normal
If I tap on the buttons and navigate to another view the TabView's background goes back to normal and works perfectly the rest of the time EVEN WHEN NAVIGATING BACK TO THE MAPBOX MAP, it just won't appear as normal for the first time it appears over the Mapbox map...???
To try and fix this I have removed all code from my project that modifies the TabView utilized by UIKits UITabBar to make sure there wasn't some code changing its behavior.
Before upgrading Xcode this was never a problem but it seems that for some reason the new Xcode is having a problem with Mapbox or UIKit???
See photos below, TabView appears blank the first time is appears over the map but if I navigate away THEN back to the map it will appear as normal and work fine the rest of the time...?
^ Background is blank first time over map
^Navigate away then return to map and background is normal??
MAIN VIEW
struct MainView: View {
@EnvironmentObject var session: SessionStore
@State private var selectedTab = 1
var body: some View {
TabView(selection: $selectedTab) {
NewsFeed()
.onTapGesture { self.selectedTab = 0 }
.tabItem { Image(systemName: "lineweight").font(.title) }
.tag(0)
MapScreen(
mapVM: MapViewModel(currentUserPublisher: session.$currentUser),
popupVM: PopupViewModel(currentUserPublisher: session.$currentUser)
)
.onTapGesture { self.selectedTab = 1 }
.tabItem { Image(systemName: "lineweight") }
.tag(1)
ProfileView()
.onTapGesture { self.selectedTab = 2 }
.tabItem { Image(systemName: "lineweight").font(.title) }
.tag(2)
}
}
}
MAPBOX MAP VIEW
import SwiftUI
import Mapbox
struct MapScreen: View {
@EnvironmentObject var session: SessionStore
@StateObject var mapVM: MapViewModel
@StateObject var popupVM: PopupViewModel
@State private var showSheet = false
var body: some View {
NavigationView {
ZStack(alignment: .bottom) {
MapboxMapView(mapVM : mapVM, popupVM: popupVM)
PopupAnchorView(modalManager: popupVM)
}
.navigationBarHidden(true)
.navigationViewStyle(StackNavigationViewStyle())
.onAppear {
if popupVM.data == nil {
self.popupVM.newModal(position: .closed) {
PopupFull(popupVM: popupVM)
}
}
}
}
}
}
iOS 15 changed the default look of the TabBar when there is nothing underneath it to scroll.
What worked for me (to change it back to the iOS 14 default) is modifying the TabBar in an onAppear
statement:
TabView {
...
}
.onAppear {
let tabBarAppearance = UITabBarAppearance()
tabBarAppearance.configureWithDefaultBackground()
UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
}