macOS: stabilize context menu card layout
This commit is contained in:
@@ -6,7 +6,10 @@ struct ContextMenuCardView: View {
|
|||||||
private let rows: [SessionRow]
|
private let rows: [SessionRow]
|
||||||
private let statusText: String?
|
private let statusText: String?
|
||||||
private let isLoading: Bool
|
private let isLoading: Bool
|
||||||
private let padding: CGFloat = 10
|
private let paddingTop: CGFloat = 6
|
||||||
|
private let paddingBottom: CGFloat = 6
|
||||||
|
private let paddingTrailing: CGFloat = 16
|
||||||
|
private let paddingLeading: CGFloat = 22
|
||||||
private let barHeight: CGFloat = 3
|
private let barHeight: CGFloat = 3
|
||||||
|
|
||||||
init(
|
init(
|
||||||
@@ -20,7 +23,7 @@ struct ContextMenuCardView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(alignment: .leading, spacing: 8) {
|
VStack(alignment: .leading, spacing: 6) {
|
||||||
HStack(alignment: .firstTextBaseline) {
|
HStack(alignment: .firstTextBaseline) {
|
||||||
Text("Context")
|
Text("Context")
|
||||||
.font(.caption.weight(.semibold))
|
.font(.caption.weight(.semibold))
|
||||||
@@ -53,7 +56,10 @@ struct ContextMenuCardView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(self.padding)
|
.padding(.top, self.paddingTop)
|
||||||
|
.padding(.bottom, self.paddingBottom)
|
||||||
|
.padding(.leading, self.paddingLeading)
|
||||||
|
.padding(.trailing, self.paddingTrailing)
|
||||||
.frame(minWidth: 300, maxWidth: .infinity, alignment: .leading)
|
.frame(minWidth: 300, maxWidth: .infinity, alignment: .leading)
|
||||||
.transaction { txn in txn.animation = nil }
|
.transaction { txn in txn.animation = nil }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,17 +70,22 @@ final class MenuContextCardInjector: NSObject, NSMenuDelegate {
|
|||||||
self.adoptMenuWidthIfAvailable(for: menu, hosting: hosting)
|
self.adoptMenuWidthIfAvailable(for: menu, hosting: hosting)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.loadTask = Task { [weak hosting] in
|
if initialIsLoading {
|
||||||
await self.refreshCache(force: initialIsLoading)
|
self.loadTask = Task { [weak hosting] in
|
||||||
guard let hosting else { return }
|
await self.refreshCache(force: true)
|
||||||
let view = self.cachedView()
|
guard let hosting else { return }
|
||||||
await MainActor.run {
|
let view = self.cachedView()
|
||||||
hosting.rootView = view
|
await MainActor.run {
|
||||||
hosting.invalidateIntrinsicContentSize()
|
hosting.rootView = view
|
||||||
self.adoptMenuWidthIfAvailable(for: menu, hosting: hosting)
|
hosting.invalidateIntrinsicContentSize()
|
||||||
let size = hosting.fittingSize
|
self.adoptMenuWidthIfAvailable(for: menu, hosting: hosting)
|
||||||
hosting.frame.size.height = size.height
|
let size = hosting.fittingSize
|
||||||
|
hosting.frame.size.height = size.height
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Keep the menu stable while it's open; refresh in the background for next open.
|
||||||
|
self.loadTask = Task { await self.refreshCache(force: false) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user