perf(ui): 移除监控动效并精简原生图表绘制

This commit is contained in:
2026-11-07 14:39:27 +08:00
parent 10c73c6026
commit 80706fa52e
54 changed files with 264 additions and 778 deletions
+5 -43
View File
@@ -64,33 +64,20 @@ struct HoverDetailPresenter<Detail: View>: NSViewRepresentable {
.padding(12)
.frame(width: 280)
.fixedSize(horizontal: false, vertical: true)
.modifier(DetailEntrance())
.background(Color("PanelCard"), in: .rect(cornerRadius: 12))
.overlay(RoundedRectangle(cornerRadius: 12).strokeBorder(.primary.opacity(0.14)))
.onHover { [weak self] inside in self?.onHover(inside) })
if panel == nil {
let panel = DetailPanel(contentRect: .zero, styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
panel.isReleasedWhenClosed = false
panel.isOpaque = false
panel.backgroundColor = .clear
panel.hasShadow = true
panel.hasShadow = false
panel.animationBehavior = .none
panel.hidesOnDeactivate = false
panel.level = parent.level
let material = NSVisualEffectView()
material.material = .menu
material.blendingMode = .behindWindow
material.state = .active
material.wantsLayer = true
material.layer?.cornerRadius = 12
material.layer?.masksToBounds = true
let host = NSHostingView(rootView: content)
host.translatesAutoresizingMaskIntoConstraints = false
material.addSubview(host)
NSLayoutConstraint.activate([
host.leadingAnchor.constraint(equalTo: material.leadingAnchor),
host.trailingAnchor.constraint(equalTo: material.trailingAnchor),
host.topAnchor.constraint(equalTo: material.topAnchor),
host.bottomAnchor.constraint(equalTo: material.bottomAnchor)
])
panel.contentView = material
panel.contentView = host
self.panel = panel
self.host = host
parent.addChildWindow(panel, ordered: .above)
@@ -124,28 +111,3 @@ struct HoverDetailPresenter<Detail: View>: NSViewRepresentable {
override var canBecomeMain: Bool { false }
}
}
/// One entrance per mounted child panel; sampling updates retain the revealed state.
private struct DetailEntrance: ViewModifier {
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@State private var revealed = false
func body(content: Content) -> some View {
content
.opacity(revealed || reduceMotion ? 1 : 0)
.scaleEffect(revealed || reduceMotion ? 1 : 0.97)
.task {
guard !reduceMotion else { revealed = true; return }
do { try await Task.sleep(for: .milliseconds(16)) } catch { return }
guard !Task.isCancelled else { return }
withAnimation(.spring(duration: 0.2, bounce: 0)) { revealed = true }
}
.onChange(of: reduceMotion) { _, reduced in
if reduced {
var transaction = Transaction()
transaction.disablesAnimations = true
withTransaction(transaction) { revealed = true }
}
}
}
}