I have a view with an overlaying half sheet (for lack of better terms), which covers the bottom half of the screen. It’s implemented like this:
.sheet(isPresented: $showSender, content: {
SenderView()
.presentationDetents([.medium])
}
If I set showSender
to true upon launching, it looks just fine. However, I want the sheet to pop up upon selecting a photo. I’m using a PhotosPicker
and setting showSender
to true when the photo selected changes:
PhotosPicker("Send Pictures", selection: $photoPicked, matching: .images)
.onChange(of: photoPicked) { value in
self.showSender = true
}
However, bizarrely, in this case the sheet covers the whole screen. Any ideas what’s going on? Here’s a minimal repro. Thanks.
import SwiftUI
import PhotosUI
struct SenderView: View {
var body: some View {
Text("Sender View")
}
}
struct ContentView: View {
@State var showSender = false
@State var photoPicked: PhotosPickerItem? = nil
var body: some View {
VStack {
PhotosPicker("Send Pictures", selection: $photoPicked, matching: .images)
.onChange(of: photoPicked) { value in
self.showSender = true
}
}
.padding()
.sheet(isPresented: $showSender, content: {
SenderView()
.presentationDetents([.medium])
})
}
}
#Preview {
ContentView()
}