@@ -1725,21 +1725,38 @@ public final class AppKitBackend: AppBackend {
17251725 return SIMD2 ( x: Int ( size. width) , y: Int ( size. height) )
17261726 }
17271727
1728- public func showSheet( _ sheet: NSCustomSheet , window : NSCustomWindow ) {
1728+ public func showSheet( _ sheet: NSCustomSheet , sheetParent : Any ) {
17291729 // Critical sheets stack. beginSheet only shows a nested sheet
17301730 // after its parent gets dismissed.
1731+ let window = sheetParent as! NSCustomWindow
17311732 window. beginCriticalSheet ( sheet)
1733+ window. managedAttachedSheet = sheet
17321734 }
17331735
1734- public func dismissSheet( _ sheet: NSCustomSheet , window: NSCustomWindow ) {
1736+ public func dismissSheet( _ sheet: NSCustomSheet , sheetParent: Any ) {
1737+ let window = sheetParent as! NSCustomWindow
1738+
1739+ if let nestedSheet = sheet. managedAttachedSheet {
1740+ dismissSheet ( nestedSheet, sheetParent: sheet)
1741+ }
1742+
1743+ defer { window. managedAttachedSheet = nil }
1744+
17351745 window. endSheet ( sheet)
17361746 }
17371747
17381748 public func setPresentationBackground( of sheet: NSCustomSheet , to color: Color ) {
1749+ if let backgroundView = sheet. backgroundView {
1750+ backgroundView. layer? . backgroundColor = color. nsColor. cgColor
1751+ return
1752+ }
1753+
17391754 let backgroundView = NSView ( )
17401755 backgroundView. wantsLayer = true
17411756 backgroundView. layer? . backgroundColor = color. nsColor. cgColor
17421757
1758+ sheet. backgroundView = backgroundView
1759+
17431760 if let existingContentView = sheet. contentView {
17441761 let container = NSView ( )
17451762 container. translatesAutoresizingMaskIntoConstraints = false
@@ -1777,6 +1794,8 @@ public final class NSCustomSheet: NSCustomWindow, NSWindowDelegate {
17771794
17781795 public var interactiveDismissDisabled : Bool = false
17791796
1797+ public var backgroundView : NSView ?
1798+
17801799 public func dismiss( ) {
17811800 onDismiss ? ( )
17821801 self . contentViewController? . dismiss ( self )
@@ -2209,6 +2228,8 @@ public class NSCustomWindow: NSWindow {
22092228 var customDelegate = Delegate ( )
22102229 var persistentUndoManager = UndoManager ( )
22112230
2231+ var managedAttachedSheet : NSCustomSheet ?
2232+
22122233 /// Allows the backing scale factor to be overridden. Useful for keeping
22132234 /// UI tests consistent across devices.
22142235 ///
0 commit comments