Skip to content

Commit 7ff2ef0

Browse files
committed
Fix macOS issue
1 parent 8ca37b5 commit 7ff2ef0

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

Example/OpenSwiftUIUITests/UITests/AnimationDebugController.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// OpenSwiftUIUITests
44

55
import Foundation
6-
import UIKit
76
import OpenSwiftUI_SPI
87

98
struct AnimationTestModel: Hashable {
@@ -40,8 +39,8 @@ final class AnimationDebugController<V>: PlatformHostingController<V> where V: V
4039
fatalError("init(coder:) has not been implemented")
4140
}
4241

43-
private var host: _UIHostingView<V> {
44-
view as! _UIHostingView<V>
42+
private var host: PlatformHostingView<V> {
43+
view as! PlatformHostingView<V>
4544
}
4645

4746
func advance(interval: Double) {
@@ -54,12 +53,16 @@ final class AnimationDebugController<V>: PlatformHostingController<V> where V: V
5453

5554
override func viewDidLoad() {
5655
super.viewDidLoad()
56+
#if os(iOS) || os(visionOS)
5757
Self.hookLayoutSubviews(type(of: host))
5858
Self.hookDisplayLinkTimer()
59+
#endif
5960
}
6061

62+
#if os(iOS) || os(visionOS)
6163
var disableLayoutSubview = false
6264

65+
// Fix swift-snapshot framework snapshot will trigger uncessary _UIHostingView.layoutSubview issue
6366
static func hookLayoutSubviews(_ cls: AnyClass?) {
6467
let originalSelector = #selector(PlatformView.layoutSubviews)
6568
let swizzledSelector = #selector(PlatformView.swizzled_layoutSubviews)
@@ -89,8 +92,10 @@ final class AnimationDebugController<V>: PlatformHostingController<V> where V: V
8992
func swizzled_displayLinkTimerWithLink(_ sender: CADisplayLink) {
9093
sender.isPaused = true
9194
}
95+
#endif
9296
}
9397

98+
#if os(iOS) || os(visionOS)
9499
// Avoid generic parameter casting
95100
private protocol AnimationDebuggableController: PlatformViewController {
96101
var disableLayoutSubview: Bool { get set }
@@ -111,3 +116,4 @@ extension PlatformView {
111116
vc.disableLayoutSubview = true
112117
}
113118
}
119+
#endif

Example/OpenSwiftUIUITests/UITests/SnapshotTesting+Testing.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Foundation
99
#if canImport(AppKit)
1010
import AppKit
1111
typealias PlatformHostingController = NSHostingController
12+
typealias PlatformHostingView = NSHostingView
1213
typealias PlatformViewController = NSViewController
1314
typealias PlatformView = NSView
1415
typealias PlatformImage = NSImage
@@ -21,6 +22,7 @@ extension Color {
2122
#else
2223
import UIKit
2324
typealias PlatformHostingController = UIHostingController
25+
typealias PlatformHostingView = _UIHostingView
2426
typealias PlatformViewController = UIViewController
2527
typealias PlatformView = UIView
2628
typealias PlatformImage = UIImage

Sources/OpenSwiftUI/Integration/Hosting/AppKit/View/NSHostingView.swift

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,36 @@ open class NSHostingView<Content>: NSView, XcodeViewDebugDataProvider where Cont
416416
@available(visionOS, unavailable)
417417
extension NSHostingView {
418418
public func _renderForTest(interval: Double) {
419-
// TODO
419+
// FIXME: Copy from iOS version
420+
_openSwiftUIUnimplementedWarning()
421+
422+
func shouldContinue() -> Bool {
423+
if propertiesNeedingUpdate == [], !CoreTesting.needsRender {
424+
false
425+
} else {
426+
times >= 0
427+
}
428+
}
429+
advanceTimeForTest(interval: interval)
430+
canAdvanceTimeAutomatically = false
431+
var times = 16
432+
repeat {
433+
times -= 1
434+
CoreTesting.needsRender = false
435+
updateGraph { host in
436+
host.flushTransactions()
437+
}
438+
RunLoop.flushObservers()
439+
render(targetTimestamp: nil)
440+
CATransaction.flush()
441+
} while shouldContinue()
442+
CoreTesting.needsRender = false
443+
canAdvanceTimeAutomatically = true
420444
}
421445

422446
public func _renderAsyncForTest(interval: Double) -> Bool {
423-
// TODO
424-
false
447+
_openSwiftUIUnimplementedWarning()
448+
return false
425449
}
426450
}
427451

0 commit comments

Comments
 (0)