fix: stabilize native window layout transitions
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import AppKit
|
||||
import QuartzCore
|
||||
|
||||
@MainActor
|
||||
final class CompactWindowController: NSObject {
|
||||
@@ -379,10 +378,10 @@ final class CompactWindowController: NSObject {
|
||||
frameAnimationGeneration &+= 1
|
||||
let generation = frameAnimationGeneration
|
||||
frameAnimating = true
|
||||
NSAnimationContext.runAnimationGroup { context in
|
||||
context.duration = Self.transitionDuration
|
||||
context.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
|
||||
window.animator().setFrame(frame, display: true)
|
||||
// Coordinate the resize through NSWindow. Its animator proxy races SwiftUI's
|
||||
// animated window sizing and can re-enter layout until AppKit aborts.
|
||||
NSAnimationContext.runAnimationGroup { _ in
|
||||
window.setFrame(frame, display: true, animate: true)
|
||||
} completionHandler: { [weak self, weak window] in
|
||||
MainActor.assumeIsolated {
|
||||
guard let self, let window, self.window === window, self.frameAnimating,
|
||||
@@ -397,12 +396,7 @@ final class CompactWindowController: NSObject {
|
||||
guard frameAnimating else { return }
|
||||
frameAnimating = false
|
||||
frameAnimationGeneration &+= 1
|
||||
guard let window else { return }
|
||||
// A zero-duration animator update cancels the native in-flight frame animation.
|
||||
NSAnimationContext.runAnimationGroup { context in
|
||||
context.duration = 0
|
||||
window.animator().setFrame(window.frame, display: true)
|
||||
}
|
||||
// Native resize animation has returned; invalidate only its pending completion.
|
||||
}
|
||||
|
||||
private func setState(compact: Bool, transitioning: Bool) {
|
||||
|
||||
Reference in New Issue
Block a user