Thanks for pointing out this thread - it is the same setup. I could use the sidebarAdaptable style to consolidate the two views, but I'd like to preserve the custom view in the List in the sidebar if possible. I don't think you can do this with TabSections.
Post
Replies
Boosts
Views
Activity
There is a walkthrough in the WWDC22 session Complications and widgets reloaded which suggests duplicating your existing Widget target, modifying the base SDK and embedding it in the watch app to achieve this using the same code.
Thanks for your reply - I've submitted FB12171134. Here's a minimal code example to reproduce (I appreciate the Stack here doesn't achieve anything, but the behaviour is the same):
class Row: Identifiable, Hashable {
let id: UUID
let title: String
init(title: String) {
self.id = UUID()
self.title = title
}
static func == (lhs: Row, rhs: Row) -> Bool {
return lhs.id == rhs.id
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
struct ContentView: View {
let rows = [Row(title: "Row 1"), Row(title: "Row 2"), Row(title: "Row 3")]
@State var selectedRow: Row?
var body: some View {
NavigationSplitView {
List(selection: $selectedRow) {
ForEach(rows) { row in
NavigationLink(value: row) {
Text(row.title)
}
}
}
.navigationTitle("Root List")
} detail: {
if let selectedRow = selectedRow {
RowView(row: selectedRow)
}
}
}
}
import SwiftUI
struct RowView: View {
let row: Row
var body: some View {
NavigationStack {
VStack {
Text("Detail View")
}
.navigationTitle(row.title)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
// Empty
} label: {
Label("Add", systemImage: "plus")
}
}
}
}
}
}
Thanks! A separate table has worked nicely.