iaktas
1
hi community,
i am simply trying to pass data from one view to another, but somehow it won't work :-( what am I doing wrong?
i want HomeList to pass the variable parentSection to MenuList:
struct HomeList: View {
var menus = menuData
@State var showContent = false
var parentSection: String
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
VStack {
HStack {
Text("à la carte")
.font(.largeTitle)
.fontWeight(.heavy)
Spacer()
}
.padding(.leading, 40)
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 30.0) {
ForEach(menus) { item in
Button(action: { self.showContent.toggle() }) {
GeometryReader { geometry in
MenuSectionView(name: item.name,
image: item.image,
sectionColor: item.sectionColor)
.rotation3DEffect(Angle(degrees: Double(geometry.frame(in: .global).minX - 30) / -40), axis: (x: 0, y: 10.0, z: 0))
.sheet(isPresented: self.$showContent) { MenuList(parentSection: item.name) }
}
.frame(width: 246, height: 360)
}
}
}
.padding(.leading, 30)
.padding(.trailing, 30)
.padding(.top, 30)
.padding(.bottom, 70)
Spacer()
}
}
.padding(.top, 60)
}
}
}
struct MenuList: View {
var parentSection: String
var body: some View {
NavigationView {
List {
ForEach(menuData.filter({$0.name == parentSection})) { section in
//Section(header: Text(section.name)) {
ForEach(section.items) { item in
MenuItemRow(item: item)
}
//}
}
}
.navigationBarTitle(parentSection)
}
}
}
jonprescott
(Jonathan Prescott)
2
This should really be asked over on the Apple SwiftUI developer forum, but, you need to publish parentString in HomeList (assuming HomeList is the source of truth), and observe it in MenuList. Best to look at the SwiftUI documentation at the other modeling paradigms besides @State.