I have a sheet thats being presented in SwiftUI and the first time it's opened it automatically dismisses itself half a second later. Reopening it from then on works properly. Has anyone else experienced this and perhaps come up with a solution?
Stack Overflow post: https://stackoverflow.com/questions/62722308/swiftui-sheet-automatically-dismisses-itself
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView:
NavigationView{
List{
ForEach(0..<10){ value in
Text("Hello, World \(value)")
}
}
NavigationLink(destination: Test()) {
Text("Details")
}
}
)
self.window = window
window.makeKeyAndVisible()
}
}
}
struct Test : View{
@State var show = false
var body : some View{
Text("Details")
.sheet(isPresented: $show, content: {
Color.blue
})
.toolbar{
ToolbarItem(placement: .navigationBarTrailing) {
Button("Show Sheet"){
show.toggle()
}
}
}
}
}
8
1
8.1k