HalfASheet
HalfASheet copied to clipboard
Background color doesn't disappear when view is dismissed.
Hi, I just found your package and it looks like just what I need to solve the problem of presenting some sheets that just don't have enough content to look good as full views on iPad. However, I have a couple issues, and I'm not sure if I'm using it wrong of if it's an issue with HalfASheet
.
The first is that when I press the Close button, the background color overlay persists and isn't dismissed.
However, the reason I am not sure if this is a "me" problem is because I'm sort of jury-rigging things to make it work with an enum selection:
enum SidebarMenuOption: String, Identifiable, CaseIterable {
var id: String { self.rawValue }
case importFiles = "Import Files"
case settings = "Settings"
var icon: String {
switch self {
case .importFiles: return "plus"
case .settings: return "gearshape"
}
}
@ViewBuilder
var listLabel: some View {
HStack {
Image(systemName: self.icon)
Text(self.rawValue)
}
}
@ViewBuilder
var destination: some View {
switch self {
case .importFiles: ImportSheet()
case .settings: SettingsView()
}
}
}
struct SidebarMenu: View {
@State private var selection : SidebarMenuOption?
private var importIsShown: Binding<Bool> {
switch selection {
case .importFiles: return .constant(true)
default: return .constant(false)
}
}
private var settingsMenuIsShown: Binding<Bool> {
switch selection {
case .settings: return .constant(true)
default: return .constant(false)
}
}
var body: some View {
List(SidebarMenuOption.allCases) { option in
Button(action: {
selection = option
}, label: {
option.listLabel
})
}
.listStyle(SidebarListStyle())
.halfASheet(isPresented: importIsShown,
title: "Import Files") {
selection?.destination
}
.onDisappear(perform: {
selection = nil
})
.halfASheet(isPresented: settingsMenuIsShown,
title: "Settings") {
selection?.destination
}
.onDisappear(perform: {
selection = nil
})
}
}
The other issue I'm having is that the height
view modifier doesn't appear to work when using halfASheet
as a view modifier instead of a view? (Which I saw on reread, you mention in your README.)
As you can tell from the screenshots, my view is small enough that the sheet is still larger than I need.I could go into the code of my fork of the package and edit it directly there, but I'd rather be able to keep things flexible by altering the height in the view where it's used.
Ideally, I'd love the sheet to be able to dynamically size depending on the size of the content, but I'm struggling to figure out how to accomplish that, as I'm just learning SwiftUI and it's my first time having to work with GeometryReader
.
My thought was to add a third option to the HalfASheetHeight enum, something along the lines of this (which of course isn't working.)
public enum HalfASheetHeight {
case fixed(CGFloat)
case proportional(CGFloat)
case dynamic(Content)
func value(with geometry: GeometryProxy) -> CGFloat {
switch self {
case .fixed(let height):
return height
case .proportional(let proportion):
return geometry.size.height * proportion
case .dynamic(let content):
// somehow get the size of the content and return that?
}
}
}
Thank you for this great package!
I too had the problem with the background after dismissing the modal. Would love to use and support this library, thanks for contributing it 👍