Post marked as solved
Post marked as solved with 1 replies, 331 views
I have a program that uses 3 different windows, each in their own window group. In a button I can use openWindow() to call another window and it works perfectly. I watched the video at the link below and now am trying to convert my program to use a navigation stack instead of buttons. I got things to work using the code listed at the link with a few changes but am unable to get the navigation destination to use openWindow. I attempted to create a view builder but could not get it to work. After some additional research I am starting to think that the navigation destination expects to use the same window as the root view not a separate window/view and therefore, navigation destination wants just a view. But I am unsure. If someone could provide some guidance it would be appreciated.
https://developer.apple.com/videos/play/wwdc2022/10054/
struct ContentView: View {
@Environment (\.openWindow) private var openWindow
@StateObject private var dataModel = DataModel()
var body: some View {
VStack(alignment: .center) {
NavigationStack() {
List(Sections.allCases) { section in
Section(section.localizedName) {
ForEach(dataModel.stocks(in: section)) { stock in
NavigationLink(stock.listingName, value: stock)
.font(Font.custom("Arial", size: 16))
}
} // end section
} // end list
.scrollContentBackground(.hidden)
.background(Color.mint)
.navigationTitle("Stocks")
.navigationDestination(for: StockData.self) { stock in
Text("\(stock.listingName) - \(stock.name)")
// GenericTableView(content: openWindow(id: "table", value: stock.name))
// Cannot convert value of type '()' to expected argument type '() -> ContentView'
}
} // end navigation stack
} // end v stack
}
}
struct GenericTableView<Content:View>: View {
let content: Content
init(@ViewBuilder content: () -> Content) {
self.content = content()
}
var body: some View {
content
}
}