Skip to content

Commit bb0761e

Browse files
committed
Add appear test case
1 parent 833728b commit bb0761e

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

Sources/OpenSwiftUI/Core/Update/Update.swift

+19-4
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,24 @@ enum Update {
7171

7272
@inline(__always)
7373
static func dispatchActions() {
74-
// FIXME
75-
for action in actions {
76-
action()
74+
guard !actions.isEmpty else {
75+
return
76+
}
77+
78+
let actions = Update.actions
79+
Update.actions = []
80+
performOnMainThread {
81+
// TODO: Signpost.postUpdateActions
82+
begin()
83+
for action in actions {
84+
let oldDepth = depth
85+
action()
86+
let newDepth = depth
87+
if newDepth != oldDepth {
88+
fatalError("Action caused unbalanced updates.")
89+
}
90+
}
91+
end()
7792
}
7893
}
7994

@@ -107,5 +122,5 @@ extension Update {
107122
// FIXME: migrate to use @_extern(c, "xx") in Swift 6
108123
extension MovableLock {
109124
@_silgen_name("_MovableLockSyncMain")
110-
static func syncMain(lock: MovableLock ,body: @escaping () -> Void)
125+
static func syncMain(lock: MovableLock, body: @escaping () -> Void)
111126
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// AppearanceActionModifierTests.swift
3+
// OpenSwiftUICompatibilityTests
4+
5+
import Testing
6+
7+
#if canImport(Darwin)
8+
struct AppearanceActionModifierTests {
9+
@Test
10+
func appear() async throws {
11+
struct ContentView: View {
12+
var confirmation: Confirmation
13+
14+
var body: some View {
15+
AnyView(EmptyView())
16+
.onAppear {
17+
confirmation()
18+
}
19+
}
20+
}
21+
22+
#if os(iOS)
23+
await confirmation { @MainActor confirmation in
24+
let vc = UIHostingController(rootView: ContentView(confirmation: confirmation))
25+
vc.triggerLayout()
26+
workaroundIssue87(vc)
27+
}
28+
#endif
29+
}
30+
31+
// TODO: Add disappear support and test case
32+
}
33+
#endif

0 commit comments

Comments
 (0)