Add-Pedal sheet: scrollable list, fixed header with type filter, stable size
The sheet couldn't scroll — PedalPaletteView doesn't self-wrap in a ScrollView (the host must) and the sheet had none, so the list overflowed and drags just resized the detent. Rework: - Wrap the palette in a ScrollView; single fixed detent (fraction 0.82) so the sheet no longer resizes, and presentationContentInteraction(.scrolls) so drags scroll the list. - Fixed header with the "Add Pedal" title, the type-filter menu, and Done — PedalPaletteView gains an external filter binding + showsFilterMenu flag so the filter can be hoisted out of the scrolling content. - PedalCategory made public (+ Sendable) so the filter binding can cross the public palette init. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -83,9 +83,25 @@ public struct PedalPaletteView: View {
|
||||
private let onAdd: (String) -> Void
|
||||
private let onRouting: (RoutingAction) -> Void
|
||||
private let axis: Axis
|
||||
private let showsFilterMenu: Bool
|
||||
|
||||
/// Active type filter; `nil` shows all pedals.
|
||||
@State private var filter: PedalCategory?
|
||||
/// Active type filter when the palette owns it; `nil` shows all pedals. Ignored when an
|
||||
/// `externalFilter` binding is supplied (the host hoists the filter into its own header).
|
||||
@State private var internalFilter: PedalCategory?
|
||||
private let externalFilter: Binding<PedalCategory?>?
|
||||
|
||||
/// The live filter, from the host binding if provided, else the palette's own state.
|
||||
private var activeFilter: PedalCategory? {
|
||||
externalFilter?.wrappedValue ?? internalFilter
|
||||
}
|
||||
|
||||
private func setFilter(_ category: PedalCategory?) {
|
||||
if let externalFilter: Binding<PedalCategory?> = externalFilter {
|
||||
externalFilter.wrappedValue = category
|
||||
} else {
|
||||
internalFilter = category
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
@@ -95,15 +111,23 @@ public struct PedalPaletteView: View {
|
||||
/// - axis: `.vertical` (default) lays the catalog out as a full-width column for a sidebar;
|
||||
/// `.horizontal` lays it out as a fixed-width-card row for a horizontal scroller. The host
|
||||
/// wraps the view in a `ScrollView` of the matching axis.
|
||||
/// - filter: Optional external binding for the type filter, so a host (e.g. a sheet) can put
|
||||
/// the filter control in its own fixed header. When `nil` the palette manages its own filter.
|
||||
/// - showsFilterMenu: Whether to draw the built-in filter menu inline. Pass `false` when the
|
||||
/// host renders its own filter control. Defaults to `true`.
|
||||
/// - onAdd: Invoked with a pedal's `displayName` when its row is tapped (append to main chain).
|
||||
/// Rows are also `.draggable` carrying `"add:<displayName>"` for drop-onto-lane targeting.
|
||||
/// - onRouting: Invoked when a routing row is tapped. Defaults to a no-op.
|
||||
public init(
|
||||
axis: Axis = .vertical,
|
||||
filter: Binding<PedalCategory?>? = nil,
|
||||
showsFilterMenu: Bool = true,
|
||||
onAdd: @escaping (String) -> Void,
|
||||
onRouting: @escaping (RoutingAction) -> Void = { _ in }
|
||||
) {
|
||||
self.axis = axis
|
||||
self.externalFilter = filter
|
||||
self.showsFilterMenu = showsFilterMenu
|
||||
self.onAdd = onAdd
|
||||
self.onRouting = onRouting
|
||||
}
|
||||
@@ -120,7 +144,7 @@ public struct PedalPaletteView: View {
|
||||
|
||||
/// Pedal names after applying the active type filter.
|
||||
private var visiblePedalNames: [String] {
|
||||
guard let filter: PedalCategory = filter else { return orderedPedalNames }
|
||||
guard let filter: PedalCategory = activeFilter else { return orderedPedalNames }
|
||||
return orderedPedalNames.filter { PedalCategory.category(for: $0) == filter }
|
||||
}
|
||||
|
||||
@@ -151,7 +175,7 @@ public struct PedalPaletteView: View {
|
||||
HStack {
|
||||
sectionTitle("PEDALS")
|
||||
Spacer(minLength: 0)
|
||||
filterMenu
|
||||
if showsFilterMenu { filterMenu }
|
||||
}
|
||||
ForEach(visiblePedalNames, id: \.self) { name in
|
||||
pedalRow(name)
|
||||
@@ -215,18 +239,18 @@ public struct PedalPaletteView: View {
|
||||
/// "Filter by type" menu — defaults to **All** (no filtering).
|
||||
private var filterMenu: some View {
|
||||
Menu {
|
||||
Button("All Types") { filter = nil }
|
||||
Button("All Types") { setFilter(nil) }
|
||||
Divider()
|
||||
ForEach(PedalCategory.allCases) { category in
|
||||
Button(category.rawValue) { filter = category }
|
||||
Button(category.rawValue) { setFilter(category) }
|
||||
}
|
||||
} label: {
|
||||
HStack(spacing: 3) {
|
||||
Image(systemName: "line.3.horizontal.decrease.circle")
|
||||
Text(filter?.rawValue ?? "All").lineLimit(1)
|
||||
Text(activeFilter?.rawValue ?? "All").lineLimit(1)
|
||||
}
|
||||
.font(.system(size: PedalPaletteView.titleFontSize))
|
||||
.foregroundStyle((filter?.color ?? Color.white).opacity(0.9))
|
||||
.foregroundStyle((activeFilter?.color ?? Color.white).opacity(0.9))
|
||||
}
|
||||
#if os(macOS)
|
||||
.menuStyle(.borderlessButton)
|
||||
|
||||
Reference in New Issue
Block a user