MainContent not displayed if there are less than 3 bottom sheet positions #73
-
Hello, I think I've found an issue regarding the BottomSheetPositions. In my project, I copied the Book Detail View example and ran it. No issue. But as soon as I removed a case in PicturesIn the first picture, Sample CodeThis is mostly the Book Detail View example taken straight from the README. import SwiftUI
import BottomSheet
//The custom BottomSheetPosition enum with absolute values.
enum BookBottomSheetPosition: CGFloat, CaseIterable {
case middle = 300
// TODO: 🐛🐛🐛🐛🐛 Comment bottom to reproduce the bug 🐛🐛🐛🐛🐛
case bottom = 299.999
case hidden = 0
}
struct ContentView: View {
@State var bottomSheetPosition: BookBottomSheetPosition = .middle
let backgroundColors: [Color] = [Color(red: 0.2, green: 0.85, blue: 0.7), Color(red: 0.13, green: 0.55, blue: 0.45)]
let readMoreColors: [Color] = [Color(red: 0.70, green: 0.22, blue: 0.22), Color(red: 1, green: 0.32, blue: 0.32)]
let bookmarkColors: [Color] = [Color(red: 0.28, green: 0.28, blue: 0.53), Color(red: 0.44, green: 0.44, blue: 0.83)]
var body: some View {
//A green gradient as a background that ignores the safe area.
LinearGradient(gradient: Gradient(colors: self.backgroundColors), startPoint: .topLeading, endPoint: .bottomTrailing)
.edgesIgnoringSafeArea(.all)
.bottomSheet(bottomSheetPosition: self.$bottomSheetPosition, options: [.noDragIndicator, .allowContentDrag, .showCloseButton(), .swipeToDismiss, .tapToDismiss, .absolutePositionValue], headerContent: {
//The name of the book as the heading and the author as the subtitle with a divider.
VStack(alignment: .leading) {
Text("Wuthering Heights")
.font(.title).bold()
Text("by Emily Brontë")
.font(.subheadline).foregroundColor(.secondary)
Divider()
.padding(.trailing, -30)
}
}) {
//A short introduction to the book, with a "Read More" button and a "Bookmark" button.
VStack(spacing: 0) {
Text("This tumultuous tale of life in a bleak farmhouse on the Yorkshire moors is a popular set text for GCSE and A-level English study, but away from the demands of the classroom it’s easier to enjoy its drama and intensity. Populated largely by characters whose inability to control their own emotions...")
.fixedSize(horizontal: false, vertical: true)
HStack {
Button(action: {}, label: {
Text("Read More")
.padding(.horizontal)
})
.buttonStyle(BookButton(colors: self.readMoreColors)).clipShape(Capsule())
Spacer()
Button(action: {}, label: {
Image(systemName: "bookmark")
})
.buttonStyle(BookButton(colors: self.bookmarkColors)).clipShape(Circle())
}
.padding(.top)
Spacer(minLength: 0)
}
.padding([.horizontal, .top])
}
}
}
//The gradient ButtonStyle.
struct BookButton: ButtonStyle {
let colors: [Color]
func makeBody(configuration: Configuration) -> some View {
configuration.label
.font(.headline)
.foregroundColor(.white)
.padding()
.background(LinearGradient(gradient: Gradient(colors: self.colors), startPoint: .topLeading, endPoint: .bottomTrailing))
}
} ExpectationSince the lib use an enum to describe the positions, it seems reasonable that we can declare as many positions as we want, including less than 3. If, for some reason, it weren't possible it should at least print an error or even trigger a WorkaroundIn the meantime, I plan to declare a fictional third position very close to my extended position so that the user won't see the difference but the issue will be mitigated. Configuration
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
As mentioned in your other issue, this is also expected. Always the lowest value in your |
Beta Was this translation helpful? Give feedback.
As mentioned in your other issue, this is also expected. Always the lowest value in your
BottomSheetPosition
(but grater than 0) gets the .bottom position behavior. The name of the variable doesn’t matter (I can’t test for names and there is no need for it). So when commenting.bottom
out,.middle
gets the .bottom position behavior. If you don’t was this, please use the.noBottomPosition
option as described in the documentation.