Skip to content

Commit a1cd25e

Browse files
authored
Add AppearanceActionModifierTests (#206)
1 parent 3dbe1d3 commit a1cd25e

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

Example/HostingExample/ViewController.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ struct ContentView: View {
5555
first.toggle()
5656
}
5757
}
58-
// .id(first)
59-
// .onDisappear {
60-
// print("Red disappear")
61-
// }
58+
.onDisappear {
59+
print("Red disappear")
60+
}
61+
.id(first)
6262
// } else {
6363
// Color.blue
6464
// .onAppear {

Sources/OpenSwiftUICore/View/IDView.swift

+5-4
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ extension View {
5353
extension IDView {
5454
@usableFromInline
5555
package static func _makeView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs {
56-
if _SemanticFeature_v2.isEnabled {
57-
return makeImplicitRoot(view: view, inputs: inputs)
58-
} else {
56+
// Disable SemanticFeature_v2 temporary as makeImplicitRoot has not been implemented yet
57+
// if _SemanticFeature_v2.isEnabled {
58+
// return makeImplicitRoot(view: view, inputs: inputs)
59+
// } else {
5960
let id = view.value[offset:{ .of(&$0.id) }]
6061
let phase = IDPhase(id: id, phase: inputs.viewPhase, lastID: nil, delta: 0)
6162
var inputs = inputs
6263
inputs.viewPhase = Attribute(phase)
6364
return Content.makeDebuggableView(view: view[offset: { .of(&$0.content)}], inputs: inputs)
64-
}
65+
// }
6566
}
6667
}
6768

Tests/OpenSwiftUICompatibilityTests/SwiftUICore/Modifier/ViewModifier/AppearanceActionModifierTests.swift

+44-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
// AppearanceActionModifierTests.swift
33
// OpenSwiftUICompatibilityTests
44

5+
#if canImport(Darwin)
56
import Testing
67

7-
#if canImport(Darwin)
8+
import Foundation
9+
#if os(iOS)
10+
import UIKit
11+
#endif
12+
13+
@MainActor
814
struct AppearanceActionModifierTests {
915
@Test
1016
func appear() async throws {
@@ -27,7 +33,42 @@ struct AppearanceActionModifierTests {
2733
}
2834
#endif
2935
}
30-
31-
// TODO: Add disappear support and test case
36+
37+
#if !DEBUG || compiler(>=6.1)
38+
// For Xcode 16.3-/Swift 6.1-, Xcode will infer OpaqueTypeErasure to be true which will make some difference to the result.
39+
// And there is no way to opt-out it for package yet.
40+
@Test
41+
func idTest() async throws {
42+
enum Helper {
43+
@MainActor
44+
static var result = ""
45+
}
46+
47+
struct ContentView: View {
48+
@State private var toggle = false
49+
50+
var body: some View {
51+
Color.red
52+
.onAppear {
53+
Helper.result += "A"
54+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
55+
toggle.toggle()
56+
}
57+
}
58+
.onDisappear {
59+
Helper.result += "D"
60+
}
61+
.id(toggle)
62+
}
63+
}
64+
#if os(iOS)
65+
let vc = UIHostingController(rootView: ContentView())
66+
vc.triggerLayout()
67+
workaroundIssue87(vc)
68+
try await Task.sleep(nanoseconds: 1 * 1_000_000_000)
69+
#expect(Helper.result.hasPrefix("AAD"))
70+
#endif
71+
}
72+
#endif
3273
}
3374
#endif

0 commit comments

Comments
 (0)