This didn't work.
I put showSheetView into a shared object, SheetInfo, and called it in both CardsView and AddView as sheetInfo. I changed every declaration of $showSheetView to $sheetInfo.showSheetView. Still didn't work. Is there something I missed? Here's the code:
SheetInfo:
class SheetInfo: ObservableObject {
@Published var showSheetView = false
}
CardsView:
struct CardsView: View {
@StateObject var cardsInfo = CardsInfo()
@StateObject var sheetInfo = SheetInfo() // <-
@State private var editMode = EditMode.inactive
var body: some View {
(...)
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
self.sheetInfo.showSheetView.toggle()
}) {
Image(systemName: "plus")
}.sheet(isPresented: $sheetInfo.showSheetView) {
AddView(cardsInfo: cardsInfo, sheetInfo: sheetInfo, isShowing: $sheetInfo.showSheetView)
}
}
(...)
}
AddView:
struct AddView: View {
@ObservedObject var cardsInfo: CardsInfo
@ObservedObject var sheetInfo: SheetInfo
@Binding var isShowing: Bool
var body: some View {
(...)
Button(action: {
cardsInfo.add()
isShowing = false
}) {
Text("Create")
.bold()
}
(...)
}