ios – SwiftUI – Disabling default collection of TabView


I’m studying TabView and have a requirement the place my primary/content material view will show map and may have TabView on the backside. At any time when any of the tab’s on TabView is tapped, a customized modal sheet (with slider deal with to regulate sizes… extra like backside sheet) might be opened. At any time when I slide the modal down utterly or shut the modal sheet, the chosen tab on tabview ought to get de-selected i.e. no tabs on the TabView must 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 might 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 might be displayed.
                Textual content("Residence tab's view")
                    .tabItem {
                        Label("Residence", systemImage: "home")
                    }
                    .tag(0)
                    .body(peak: 100.0)
                Textual content("Search tab's view")
                    .tabItem {
                        Label("Search", systemImage: "magnifyingglass")
                    }
                    .tag(1)
                    .body(peak: 100.0)
            }
        }.onAppear {
            UITabBar.look().backgroundColor = .lightGray
        }
    }
}

To maintain the code brief and easy, I’m utilizing Textual content() ingredient in my BottomTabView struct for now, however it will likely be changed with CustomModalSheet which when closed, so de-select the chosen tab on tab view and no tabs must be chosen by default.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles