Skip to content

Commit 9728864

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

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

Sources/OpenSwiftUI/Core/Update/Update.swift

Lines changed: 19 additions & 4 deletions
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
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// AppearanceActionModifierTests.swift
3+
// OpenSwiftUICompatibilityTests
4+
5+
import Testing
6+
7+
@MainActor
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+
await confirmation { confirmation in
23+
#if os(iOS)
24+
let vc = UIHostingController(rootView: ContentView(confirmation: confirmation))
25+
vc.triggerLayout()
26+
workaroundIssue87(vc)
27+
#endif
28+
}
29+
}
30+
31+
// TODO: Add disappear support and test case
32+
}

0 commit comments

Comments
 (0)