Skip to content

Commit

Permalink
home: use new NavigationSplitView on iOS 16/macOS 13
Browse files Browse the repository at this point in the history
This also resolves the bug where the bottom toolbar does not appear.

Fixes #4325
  • Loading branch information
osy committed Sep 3, 2022
1 parent 30ae70a commit 1728953
Showing 1 changed file with 48 additions and 24 deletions.
72 changes: 48 additions & 24 deletions Platform/Shared/VMNavigationListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,55 @@ struct VMNavigationListView: View {
@EnvironmentObject private var data: UTMData

var body: some View {
NavigationView {
List {
ForEach(data.virtualMachines) { vm in
if let wrappedVM = vm as? UTMWrappedVirtualMachine {
UTMUnavailableVMView(wrappedVM: wrappedVM)
} else {
NavigationLink(
destination: VMDetailsView(vm: vm),
tag: vm,
selection: $data.selectedVM,
label: { VMCardView(vm: vm) })
.modifier(VMContextMenuModifier(vm: vm))
}
}.onMove(perform: move)
.onDelete(perform: delete)

if data.pendingVMs.count > 0 {
Section(header: Text("Pending")) {
ForEach(data.pendingVMs, id: \.name) { vm in
UTMPendingVMView(vm: vm)
}.onDelete(perform: cancel)
}.transition(.opacity)
if #available(iOS 16, macOS 13, *) {
NavigationSplitView {
List(selection: $data.selectedVM) {
listBody
}.modifier(VMListModifier())
} detail: {
if let vm = data.selectedVM {
VMDetailsView(vm: vm)
} else {
VMPlaceholderView()
}
}.modifier(VMListModifier())
VMPlaceholderView()
}
} else {
NavigationView {
List {
listBody
}.modifier(VMListModifier())
VMPlaceholderView()
}
}
}

@ViewBuilder private var listBody: some View {
ForEach(data.virtualMachines) { vm in
if let wrappedVM = vm as? UTMWrappedVirtualMachine {
UTMUnavailableVMView(wrappedVM: wrappedVM)
} else {
if #available(iOS 16, macOS 13, *) {
VMCardView(vm: vm)
.modifier(VMContextMenuModifier(vm: vm))
.tag(vm)
} else {
NavigationLink(
destination: VMDetailsView(vm: vm),
tag: vm,
selection: $data.selectedVM,
label: { VMCardView(vm: vm) })
.modifier(VMContextMenuModifier(vm: vm))
}
}
}.onMove(perform: move)
.onDelete(perform: delete)

if data.pendingVMs.count > 0 {
Section(header: Text("Pending")) {
ForEach(data.pendingVMs, id: \.name) { vm in
UTMPendingVMView(vm: vm)
}.onDelete(perform: cancel)
}.transition(.opacity)
}
}

Expand Down

0 comments on commit 1728953

Please sign in to comment.