iam new to swiftui and i got a requirement to create CustomTabBar and hide that CustomTabBar in other contentViews except its child views and I have created CustomTabBar and i want to hide this custom tab bar when i navigate to other views from CustomTabBar child views.
Here is my CustomTabBar
code:
struct CustomTabBar: View {
@StateObject private var viewModel = CustomTabBarViewModel()
var body: some View {
ZStack{
VStack(spacing: 0) {
ZStack {
tabContentView()
}.navigationBarHidden(true)
HStack {
TabView(image: "ic_Home", selectedTab: $viewModel.selectedView)
TabView(image: "ic_Notepad", selectedTab: $viewModel.selectedView)
TabView(image: "ic_Cart", selectedTab: $viewModel.selectedView)
TabView(image: "ic_Library", selectedTab: $viewModel.selectedView)
TabView(image: "ic_Profile", selectedTab: $viewModel.selectedView)
}
.frame(width: .infinity)
.padding(.horizontal, 10)
.padding(.bottom)
}
.padding(.vertical)
}.background(Color.lightOrangeColor)
.ignoresSafeArea()
}
@ViewBuilder
private func tabContentView() -\> some View {
switch viewModel.selectedView {
case "ic_Home":
HomeView(parentViewModel: viewModel)
case "ic_Notepad":
TestsSegmentView(selectedSegment: 0)
case "ic_Cart":
Color.green
case "ic_Library":
Color.red
case "ic_Profile":
Color.blueColour
default:
EmptyView()
}
}
}
struct TabView: View {
let image: String
@Binding var selectedTab: String
var body: some View {
GeometryReader { button in
Button {
withAnimation(.linear(duration: 0.3)) {
selectedTab = image
}
} label: {
VStack {
Image(image)
.renderingMode(.template)
.foregroundColor(selectedTab == image ? Color.blueColour : Color.grayTextColour)
}
}
.frame(maxWidth: .infinity, maxHeight: 50)
}.frame(height: 20)
}
}
please help me to How to hide this Custom. tabbar when i navigate to otherViews from Its Child Views in swiftu