I’m studying TabView and have a requirement the place my essential/content material view will show map and could have TabView on the backside. Every time any of the tab’s on TabView is tapped, a customized modal sheet (with slider deal with to regulate sizes… extra like backside sheet) can be opened. Every time I slide the modal down fully or shut the modal sheet, the chosen tab on tabview ought to get de-selected i.e. no tabs on the TabView needs to be chosen by default.
Is that this achievable with SwiftUI TabView? I’m noticing first tab is all the time chosen by default. Or will I’ve to create a customized tab view to realize this?
Code:
import SwiftUI
import Basis
struct ContentView: View {
var physique: some View {
VStack {
SimpleDataView()
BottomTabView()
}
}
}
struct SimpleDataView: View {
var physique: some View {
VStack {
Textual content("Map can be displayed over right here").background(Shade.grey).body(maxWidth: .infinity, maxHeight: .infinity)
Spacer()
}
.background(Shade.grey)
.ignoresSafeArea()
}
}
struct BottomTabView: View {
@State var choice: Int = -4
var physique: some View {
TabView(choice: $choice) {
Group {
/// Customized modal view with slider deal with/backside sheet can be displayed.
Textual content("House tab's view")
.tabItem {
Label("House", systemImage: "home")
}
.tag(0)
.body(top: 100.0)
Textual content("Search tab's view")
.tabItem {
Label("Search", systemImage: "magnifyingglass")
}
.tag(1)
.body(top: 100.0)
}
}.onAppear {
UITabBar.look().backgroundColor = .lightGray
}
}
}
To maintain the code brief and easy, I’m utilizing Textual content() aspect in my BottomTabView struct for now, however it is going to be changed with CustomModalSheet which when closed, so de-select the chosen tab on tab view and no tabs needs to be chosen by default.