When I use multiple bottomsheets, is there a way to make the code look cleaner
Closed this issue · 1 comments
telami commented
.bottomSheet(bottomSheetPosition: $durationPosition, switchablePositions: [.dynamic]) {
Picker("Time", selection: $durationTime) {
ForEach(1 ..< 60, id: \.self) { min in
Text(min == 1 ? "1 min" : "\(min) mins")
}
}
.pickerStyle(.wheel)
}
.enableTapToDismiss()
.enableSwipeToDismiss()
.showCloseButton()
.enableBackgroundBlur()
.bottomSheet(bottomSheetPosition: $highTideTimesPosition, switchablePositions: [.dynamic]) {
Picker("times", selection: $durationTime) {
ForEach(1 ... 20, id: \.self) { item in
Text("\(item) 次")
}
}
.pickerStyle(.wheel)
}
.enableTapToDismiss()
.enableSwipeToDismiss()
.showCloseButton()
.enableBackgroundBlur()
I tried to use a Modifier, but it didn't work,What should I do?
import BottomSheet
import SwiftUI
struct BottomSheetModifier<V>: ViewModifier where V: View {
@State var position: BottomSheetPosition
let innerView: V
func body(content: Content) -> some View {
content
.bottomSheet(bottomSheetPosition: $position, switchablePositions: [.dynamic]) {
innerView
}
.enableTapToDismiss()
.enableSwipeToDismiss()
.showCloseButton()
.enableBackgroundBlur()
.enableFloatingIPadSheet()
.backgroundBlurMaterial(.systemDark)
}
}
Here's how I use it
Vstack {
}
.modifier(BottomSheetModifier(position: createPosition, innerView:
DatePicker("time", selection: $.createTime)
.labelsHidden()
.datePickerStyle(.wheel)
))