im having an issue with a custom tab bar in swiftui. It works fine if you go through the views using the tabbar, but im having a weird issue, in searchview() i have a button to open a navigation stack using a fullscreencover. once i dismiss the views from full screen cover, a toolbar is appearing on top of my custom tabbar, moving the views around 20 px on top of the tabbar. Any ideas how to solve this?
import SwiftUI
struct NewTabView: View {
let user: User
@StateObject private var programsViewModel = ProgramViewModel()
@StateObject private var workoutsViewModel = WorkoutViewModel()
@State var currentTab: HomeTab = .home
@State private var isShowingFullScreenCover = false
init(user: User) {
self.user = user
UITabBar.appearance().isHidden = true
}
var body: some View {
VStack(spacing: 0) {
TabView(selection: $currentTab) {
MainView(workoutsViewModel: workoutsViewModel, user: user)
.applyBG()
.tag(HomeTab.home)
SearchView()
.applyBG()
.tag(HomeTab.workouts)
ProgramLoaderView(user: user, programsViewModel: programsViewModel)
.applyBG()
.tag(HomeTab.program)
LikedView()
.applyBG()
.tag(HomeTab.liked)
ActivityView()
.applyBG()
.tag(HomeTab.you)
}
CustomTab(currentTab: $currentTab)
.background(.black.opacity(0.9))
}
}
}
struct CustomTab: View {
@Binding var currentTab: HomeTab
var body: some View {
GeometryReader { proxy in
HStack(spacing: 0) {
ForEach(HomeTab.allCases, id: .rawValue) { tab in
Button {
withAnimation(.easeInOut(duration: 0.2)) {
currentTab = tab
}
} label: {
VStack {
Image(systemName: tab.symbol)
.renderingMode(.template)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 25, height: 25)
.frame(maxWidth: .infinity)
.foregroundStyle(currentTab == tab ? .white : .gray)
Circle()
.fill(.red.opacity(0.8))
.frame(width: 10, height: 10)
.opacity(currentTab == tab ? 1 : 0)
}
}
}
}
.frame(maxWidth: .infinity)
}
.frame(height: 30)
.padding(.bottom, 10)
.padding([.top])
}
}
extension View {
func applyBG() -> some View {
self
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}