feat(ui): 完善详情进入动效并记录 B 阶段本机验收

This commit is contained in:
2026-10-30 01:30:50 +08:00
parent 0c846a2127
commit a871d7046e
6 changed files with 65 additions and 3 deletions
@@ -63,6 +63,7 @@ struct HoverDetailPresenter<Detail: View>: NSViewRepresentable {
.padding(12)
.frame(width: 280)
.fixedSize(horizontal: false, vertical: true)
.modifier(DetailEntrance())
.onHover { [weak self] inside in self?.onHover(inside) })
if panel == nil {
let panel = DetailPanel(contentRect: .zero, styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
@@ -122,3 +123,28 @@ 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 }
}
}
}
}