I have serious problem. My Xcode version is 13, iOS version is 15.
import SwiftUI
struct ContentView: View {
@State var isGo: Bool = false
var body: some View {
ZStack {
Button(action: {
self.isGo = true
}, label: {
Text("Go EmptyView")
})
EmptyView()
.background(Color.green)
.frame(width: 100, height: 100)
.sheet(isPresented: $isGo, onDismiss: nil, content: {
PopupView()
})
}
}
}
struct PopupView: View {
var body: some View {
Rectangle()
.fill(Color.green)
}
}
Above code is not working. But, Previous Xcode version or Previous iOS version is that code is working. Is that iOS bug? Is there anything solution?
CodePudding user response:
You're very close, not sure why nobody has offered help. Your code does work but in theory isn't correct, you needed to move the where you called .sheet
to outside your ZStack
and it works. But here's a better approach without all the useless code.
struct ContentView: View {
@State var showemptyview: Bool = false
var body: some View {
Button("Go EmptyView") {
showemptyview.toggle()
}
.sheet(isPresented: $showemptyview) {
EmptyView()
.background(Color.green)
}
}
}
CodePudding user response:
Finally in a last version you can use several sheets directly for main view and it works. You don't need to create separate EmptyView() with sheet
YourMainView()
.sheet(item: $viewModel) { item in
// some logic here
}
.sheet(isPresented: $onther_viewModel.showView, content: {
SomeAnotherView(viewModel: viewModel.getVM())
})
.sheet(isPresented: $onther_viewModel2.showView, content: {
SomeView(viewModel: viewModel.getVM())
})