Skip to content

Commit 26e915d

Browse files
committed
refactor(nsview): use layoutSubtreeIfNeeded
Lay out the NSView hierarchy explicitly as described in pointfreeco#412
1 parent a8ca3ac commit 26e915d

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Sources/SnapshotTesting/Snapshotting/NSView.swift

+3-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extension Snapshotting where Value == NSView, Format == NSImage {
3131

3232
let initialFrame = view.frame
3333
if let size = size { view.frame.size = size }
34+
view.layoutSubtreeIfNeeded()
3435
guard view.frame.width > 0, view.frame.height > 0 else {
3536
fatalError("View not renderable to image at size \(view.frame.size)")
3637
}
@@ -72,11 +73,8 @@ extension Snapshotting where Value == NSView, Format == NSImage {
7273

7374
}
7475

75-
// This is to maintain compatibility with `recursiveDescription` because the current
76-
// test snapshots expect `.needsLayout = false` and for some apple magic reason
77-
// `view.needsLayout = false` does not do anything, but this does.
78-
let bitmapRep2 = view.bitmapImageRepForCachingDisplay(in: view.bounds)!
79-
view.cacheDisplay(in: view.bounds, to: bitmapRep2)
76+
// This is to maintain compatibility with `recursiveDescription`
77+
view.layoutSubtreeIfNeeded()
8078
}
8179

8280
}

0 commit comments

Comments
 (0)