blob: 5cd719710e1ef3165e792f02b4159448d40c661b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import SwiftUI
fileprivate class NSWindowAccessorView: NSView {
let executeBlock: (_ window: NSWindow? ) -> ()
init(_ inConfigFunction: @escaping (_ window: NSWindow? ) -> () ) {
executeBlock = inConfigFunction
super.init( frame: NSRect() )
}
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
public override func viewDidMoveToWindow() {
super.viewDidMoveToWindow()
executeBlock( self.window ) // We pass it through even if it is nil.
}
}
public struct NSWindowAccessor: NSViewRepresentable {
var configCode: (_ window: NSWindow? ) -> ()
public init(_ configCode: @escaping (_: NSWindow?) -> Void) { self.configCode = configCode }
public func makeNSView(context: Context) -> NSView { return NSWindowAccessorView( configCode ) }
public func updateNSView(_ nsView: NSView, context: Context) {}
}
|