@@ -18,22 +18,15 @@ class ChatIconSwiftUIBridge: NSView {
1818 height: size
1919 ) )
2020
21+ translatesAutoresizingMaskIntoConstraints = false
22+
2123 setupView ( )
2224 updateAvatar ( )
2325 }
2426
2527 func setupView( ) {
26- // Layer optimization
2728 wantsLayer = true
2829 layerContentsRedrawPolicy = . onSetNeedsDisplay
29- layer? . drawsAsynchronously = true
30-
31- // Only enable if content rarely changes
32- layer? . shouldRasterize = true
33- layer? . rasterizationScale = window? . backingScaleFactor ?? 2.0
34-
35- // 3. For manual layout, set this to true
36- translatesAutoresizingMaskIntoConstraints = true
3730 }
3831
3932 @available ( * , unavailable)
@@ -53,14 +46,15 @@ class ChatIconSwiftUIBridge: NSView {
5346 size: size
5447 )
5548 let newHostingView = NSHostingView ( rootView: swiftUIView)
56-
57- // 4. For manual layout, set this to true
58- newHostingView. translatesAutoresizingMaskIntoConstraints = true
59-
60- // 5. Set initial frame
61- newHostingView. frame = bounds
49+ newHostingView. translatesAutoresizingMaskIntoConstraints = false
6250
6351 addSubview ( newHostingView)
52+ NSLayoutConstraint . activate ( [
53+ newHostingView. topAnchor. constraint ( equalTo: topAnchor) ,
54+ newHostingView. bottomAnchor. constraint ( equalTo: bottomAnchor) ,
55+ newHostingView. leadingAnchor. constraint ( equalTo: leadingAnchor) ,
56+ newHostingView. trailingAnchor. constraint ( equalTo: trailingAnchor) ,
57+ ] )
6458 hostingView = newHostingView
6559 }
6660
@@ -74,8 +68,5 @@ class ChatIconSwiftUIBridge: NSView {
7468
7569 override func layout( ) {
7670 super. layout ( )
77-
78- // 7. Update hosting view frame during layout
79- hostingView? . frame = bounds
8071 }
8172}
0 commit comments