How to set up TabView for portrait iPhone and Sidebar for everything else

I am a newbie making a SwiftUI app and I want to have a TabView for when an iPhone is portrait and a sidebar view for when its landscape. The problem is that when you rotate the device, it always shows you a blank screen. When you rotate it back, it brings you back to the first item in the tab. I want my app to stay on the same view regardless of orientation or changes in orientation.

struct MainMenuView: View {
    #if os(iOS)
        @Environment(\.horizontalSizeClass) private var horizontalSizeClass
    #endif
    var body: some View {
        #if os(macOS)
            MainMenuSidebarView()
        #else
            if horizontalSizeClass == .compact {
                MainMenuTabBarView()
            } else {
                MainMenuSidebarView()
            }
        #endif
    }
}

Thanks and have a great day!



from Recent Questions - Stack Overflow https://ift.tt/3gi9wNS
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Today Walkin 14th-Sept

Object oriented programming concepts (OOPs)