iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐷
SwiftUI Now Supports Multiple Sheets in iOS 14.5
Starting from iOS 14.5, it is now possible to apply multiple sheet or fullScreenCover modifiers to a single View in SwiftUI.
You can now apply multiple sheet(isPresented:onDismiss:content:) and fullScreenCover(item:onDismiss:content:) modifiers in the same view hierarchy.
I actually wrote the following code to verify this.
Environment
- Xcode 12.5
struct ContentView: View {
@State var showSheet1 = false
@State var showSheet2 = false
var body: some View {
VStack(spacing: 16) {
Button("sheet1を表示") {
showSheet1.toggle()
}
Button("sheet2を表示") {
showSheet2.toggle()
}
}
.sheet(isPresented: $showSheet1, onDismiss: nil, content: {
VStack {
Text(UIDevice.current.systemVersion)
Text("sheet1")
}
})
.sheet(isPresented: $showSheet2, onDismiss: nil, content: {
VStack {
Text(UIDevice.current.systemVersion)
Text("sheet2")
}
})
}
}
The left is the 14.4 simulator, and the right is 14.5.
The behavior changing depending on the OS version is somewhat subtle. Cases where "it works normally in 14.5 or later but behaves strangely in 14.4 or earlier" might arise. It feels like it might still be better to avoid writing multiple sheets for now.
Discussion