Skip to content

Commit

Permalink
Improve application trigger list
Browse files Browse the repository at this point in the history
- Make the application trigger list scrollable with a max height
  • Loading branch information
zenangst committed Dec 6, 2023
1 parent 2561ece commit 2b2365c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
62 changes: 34 additions & 28 deletions App/Sources/UI/Views/WorkflowApplicationTriggerView.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Apps
import Inject
import SwiftUI

struct WorkflowApplicationTriggerView: View {
Expand All @@ -7,6 +8,7 @@ struct WorkflowApplicationTriggerView: View {
case updateApplicationTriggerContext(DetailViewModel.ApplicationTrigger)
}

@ObserveInjection var inject
@EnvironmentObject private var applicationStore: ApplicationStore
@ObservedObject private var selectionManager: SelectionManager<DetailViewModel.ApplicationTrigger>
@State private var data: [DetailViewModel.ApplicationTrigger]
Expand Down Expand Up @@ -57,39 +59,43 @@ struct WorkflowApplicationTriggerView: View {
RoundedRectangle(cornerRadius: 8)
.fill(Color(.textBackgroundColor).opacity(0.65))
)
.viewDebugger()

LazyVStack(spacing: 4) {
ForEach($data.lazy, id: \.id) { element in
WorkflowApplicationTriggerItemView(element, data: $data,
selectionManager: selectionManager,
onAction: onAction)
.contentShape(Rectangle())
.focusable(focus, as: .detail(.applicationTrigger(element.id))) {
selectionManager.handleOnTap(data, element: element.wrappedValue)
}
}
.onCommand(#selector(NSResponder.insertTab(_:)), perform: {
onTab()
})
.onCommand(#selector(NSResponder.selectAll(_:)), perform: {
selectionManager.selections = Set(data.map(\.id))
})
.onMoveCommand(perform: { direction in
if let elementID = selectionManager.handle(direction, data, proxy: nil) {
focus.wrappedValue = .detail(.applicationTrigger(elementID))
}
})
.onDeleteCommand {
let offsets = data.deleteOffsets(for: selectionManager.selections)
withAnimation {
data.remove(atOffsets: IndexSet(offsets))
if !data.isEmpty {
ScrollView {
LazyVStack(spacing: 4) {
ForEach($data.lazy, id: \.id) { element in
WorkflowApplicationTriggerItemView(element, data: $data,
selectionManager: selectionManager,
onAction: onAction)
.contentShape(Rectangle())
.focusable(focus, as: .detail(.applicationTrigger(element.id))) {
selectionManager.handleOnTap(data, element: element.wrappedValue)
}
}
.onCommand(#selector(NSResponder.insertTab(_:)), perform: {
onTab()
})
.onCommand(#selector(NSResponder.selectAll(_:)), perform: {
selectionManager.selections = Set(data.map(\.id))
})
.onMoveCommand(perform: { direction in
if let elementID = selectionManager.handle(direction, data, proxy: nil) {
focus.wrappedValue = .detail(.applicationTrigger(elementID))
}
})
.onDeleteCommand {
let offsets = data.deleteOffsets(for: selectionManager.selections)
withAnimation {
data.remove(atOffsets: IndexSet(offsets))
}
}
}
.focused(focus, equals: .detail(.applicationTriggers))
}
.frame(minHeight: 52, maxHeight: min(CGFloat(data.count * 52), 300) )
}
.focused(focus, equals: .detail(.applicationTriggers))
}
.padding(.horizontal, 8)
.enableInjection()
}
}

Expand Down
2 changes: 1 addition & 1 deletion App/Sources/UI/Views/WorkflowCommandEmptyListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct WorkflowCommandEmptyListView: View {
}
return false
}
.frame(maxWidth: .infinity)
.frame(maxWidth: .infinity, minHeight: 250, maxHeight: .infinity)
.matchedGeometryEffect(id: "command-list", in: namespace)
}
}
Expand Down

0 comments on commit 2b2365c

Please sign in to comment.