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
+9 -14
View File
@@ -19,23 +19,23 @@ import SwiftUI
let ideal = host.fittingSize
precondition(ideal.width.isFinite && ideal.height.isFinite, "Unconstrained fitting must stay finite")
let before = bitmap(host)
precondition(probe.appearances == 1 && probe.animates && probe.locale == "en_US" && probe.font == .system(size: 22, weight: .medium))
precondition(probe.appearances == 1 && probe.locale == "en_US" && probe.font == .system(size: 22, weight: .medium))
precondition(redPixels(before) > 30, "Foreground style must cross the native boundary")
let originalLifetime = ObjectIdentifier(probe.lifetime!)
host.rootView = Example(value: "345", probe: probe)
try? await Task.sleep(for: .milliseconds(140))
let middle = bitmap(host)
let settled = bitmap(host)
try? await Task.sleep(for: .milliseconds(600))
let after = bitmap(host)
precondition(before.bitmapData != nil && after.bitmapData != nil)
precondition(pixels(before) != pixels(after), "Changed values must reach the retained child host")
precondition(pixels(middle) != pixels(before) && pixels(middle) != pixels(after),
"The system numeric transition must still have an intermediate frame")
precondition(pixels(settled) == pixels(after),
"A sample must settle immediately without numeric rolling or a later animation frame")
precondition(probe.appearances == 1 && probe.lifetime.map(ObjectIdentifier.init) == originalLifetime,
"Sampling must update mounted content, not remount it")
host.rootView = Example(value: "345", probe: probe, reduced: true, locale: "zh_CN")
host.rootView = Example(value: "345", probe: probe, locale: "zh_CN")
try? await Task.sleep(for: .milliseconds(100))
precondition(!probe.animates && probe.locale == "zh_CN")
precondition(probe.locale == "zh_CN")
window.setContentSize(NSSize(width: 360, height: 100))
try? await Task.sleep(for: .milliseconds(100))
@MainActor func childHost(_ view: NSView) -> NSHostingView<AnyView>? {
@@ -55,7 +55,7 @@ import SwiftUI
window.orderOut(nil)
window.contentView = nil
window.close()
print("PASS: card host preserves system numeric intermediate frames, inherited font/style/locale/motion, child state, resize and unmount")
print("PASS: static card host preserves immediate stable text, inherited font/style/locale, child state, resize and unmount")
fflush(stdout)
NSApp.terminate(nil)
}
@@ -66,7 +66,6 @@ import SwiftUI
@MainActor private final class Probe {
var appearances = 0
var disappearances = 0
var animates = false
var locale = ""
var font: Font?
weak var lifetime: Lifetime?
@@ -74,7 +73,6 @@ import SwiftUI
private struct Example: View {
let value: String
let probe: Probe
var reduced = false
var locale = "en_US"
var visible = true
var body: some View {
@@ -84,29 +82,26 @@ import SwiftUI
.font(.system(size: 22, weight: .medium))
.foregroundStyle(.red)
.environment(\.locale, Locale(identifier: locale))
.environment(\.metricAnimationsEnabled, !reduced)
}
}
private struct Content: View {
let value: String
let probe: Probe
@Environment(\.metricAnimationsEnabled) private var animates
@Environment(\.locale) private var locale
@Environment(\.font) private var font
@State private var lifetime = Lifetime()
var body: some View {
AnimatedMetricText(value: value)
MetricText(value: value)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.onAppear {
probe.appearances += 1; probe.lifetime = lifetime
recordEnvironment()
}
.onDisappear { probe.disappearances += 1 }
.onChange(of: animates) { recordEnvironment() }
.onChange(of: locale) { recordEnvironment() }
}
private func recordEnvironment() {
probe.animates = animates; probe.locale = locale.identifier; probe.font = font
probe.locale = locale.identifier; probe.font = font
}
}
@MainActor private static func bitmap(_ view: NSView) -> NSBitmapImageRep {