I have a setup with tab views within a navigation view. I have been testing for some time with light mode showing that all views work properly when switched between portrait and landscape modes. When I switch to dark mode, all the tabs work fine upon change in orientation. When changing orientation in any of the three views in the settings tab, control always falls out to the settings tab.
Why should the behavior be different between light and dark modes when changing the orientation? Am I missing something or is this a bug in Apple software?
This is a working example. Xcode 13.4.1
enum Tabs: String {
case home
case history
case settings
}
// App startup: display tab view
struct ContentView: View {
@State private var selectedTab: Tabs = .home
var body: some View {
NavigationView {
TabView (selection: $selectedTab) {
EntryView()
.tabItem {
Label("Home", systemImage: "house.circle.fill")
}.tag(Tabs.home)
HistoryView()
.tabItem {
Label("History", systemImage: "clock.fill")
}.tag(Tabs.history)
SettingsView()
.tabItem {
Label("Settings", systemImage: "gear")
}.tag(Tabs.settings)
}
}.navigationViewStyle(StackNavigationViewStyle())
}
}
struct EntryView: View {
var body: some View {
VStack {
Text("This is Entry View")
}
}
}
struct HistoryView: View {
var body: some View {
VStack {
Text("This is History View")
}
}
}
// display settings menu
struct SettingsView: View {
var body: some View {
VStack (alignment: .leading) {
Form {
NavigationLink(destination: BaseView()) {Text("View A")}
NavigationLink(destination: ManCurView()) {Text("View B")}
NavigationLink(destination: ManCatView()) {Text("View C")}
}
}
}
}
struct BaseView: View {
var body: some View {
VStack {
Text("This is View A")
}
}
}
struct ManCurView: View {
var body: some View {
VStack {
Text("This is View B")
}
}
}
struct ManCatView: View {
var body: some View {
VStack {
Text("This is View C")
}
}
}
Entry in portrait mode: light mode https://i.stack.imgur.com/qj0fZ.png
Same view but rotated orientation to landscape: stays in view https://i.stack.imgur.com/U9rhg.png
Entry in portrait: Dark mode https://i.stack.imgur.com/my9PG.png
Same view but rotated orientation to landscape: exits view and returns to menu https://i.stack.imgur.com/qPXef.png