A collection of user interface components and drawing routines for building tasteful apps using AppKit.
appkit swift aqua ui mac

Drawer resizing: work around an edge case

+10 -3
+10 -3
Sources/AquaKit/Drawers/AquaDrawer.swift
··· 271 271 } 272 272 } 273 273 274 + private func finalizeClose() { 275 + self.window?.orderOut(nil) 276 + self.state = .closedState 277 + NotificationCenter.default.post(name: Self.didCloseNotification, object: self) 278 + } 279 + 274 280 public override func close() { 275 281 guard 276 282 case .openState(let edge) = state, ··· 283 289 NotificationCenter.default.post(name: Self.willCloseNotification, object: self) 284 290 state = .closingState 285 291 292 + // Edge case: when the window has zero size, its origin may turn to zero for reasons unknown. To avoid the resulting animation glitch, we just don't animate at all in this case. 293 + guard window.frame != .zero else { return finalizeClose() } 294 + 286 295 NSAnimationContext.runAnimationGroup { context in 287 296 context.duration = Self.drawerTransitionDuration 288 297 window.animator().setFrame(frame, display: true) 289 298 } completionHandler: { [weak self] in 290 299 if let self { 291 300 Task { @MainActor in 292 - self.window?.orderOut(nil) 293 - self.state = .closedState 294 - NotificationCenter.default.post(name: Self.didCloseNotification, object: self) 301 + self.finalizeClose() 295 302 } 296 303 } 297 304 }