Skip to content

Commit 6989e7b

Browse files
authored
Add ForegroundStyle and BackgroundStyle support (#785)
* Update ImplicitShapeStyle * Implement BackgroundStyle * Add InterpolatedShapeStyle * Update OffsetShapeStyle * Update ShapeStyleShape and name * Implement ForegroundStyle * Add UI test case for Foreground and Background style * Fix macOS ui test case
1 parent 9916291 commit 6989e7b

File tree

11 files changed

+1119
-298
lines changed

11 files changed

+1119
-298
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
//
2+
// BackgroundStyleUITests.swift
3+
// OpenSwiftUIUITests
4+
5+
import Testing
6+
import SnapshotTesting
7+
8+
@MainActor
9+
@Suite(.snapshots(record: .never, diffTool: diffTool))
10+
struct BackgroundStyleUITests {
11+
@Test
12+
func backgroundDefault() {
13+
struct ContentView: View {
14+
var body: some View {
15+
Rectangle()
16+
.fill(.background)
17+
.frame(width: 100, height: 100)
18+
}
19+
}
20+
openSwiftUIAssertSnapshot(of: ContentView())
21+
}
22+
23+
@Test(.disabled {
24+
#if os(macOS)
25+
// FIXME: Update RenderShape DL
26+
true
27+
#else
28+
false
29+
#endif
30+
})
31+
func backgroundInGroup() {
32+
struct ContentView: View {
33+
var body: some View {
34+
VStack(spacing: 0) {
35+
Rectangle()
36+
.fill(.background)
37+
.frame(width: 100, height: 50)
38+
Rectangle()
39+
.fill(.background)
40+
.frame(width: 100, height: 50)
41+
._addingBackgroundGroup()
42+
}
43+
}
44+
}
45+
openSwiftUIAssertSnapshot(of: ContentView())
46+
}
47+
48+
@Test
49+
func backgroundInLayer() {
50+
struct ContentView: View {
51+
var body: some View {
52+
VStack(spacing: 0) {
53+
Rectangle()
54+
.fill(.background)
55+
.frame(width: 100, height: 50)
56+
Rectangle()
57+
.fill(.background)
58+
.frame(width: 100, height: 50)
59+
._addingBackgroundLayer()
60+
}
61+
}
62+
}
63+
openSwiftUIAssertSnapshot(of: ContentView())
64+
}
65+
66+
@Test
67+
func backgroundCustomStyle() {
68+
struct ContentView: View {
69+
var body: some View {
70+
Rectangle()
71+
.fill(.background)
72+
.frame(width: 100, height: 100)
73+
.backgroundStyle(.blue)
74+
}
75+
}
76+
openSwiftUIAssertSnapshot(of: ContentView())
77+
}
78+
79+
@Test
80+
func backgroundNestedCustomStyle() {
81+
struct ContentView: View {
82+
var body: some View {
83+
VStack(spacing: 0) {
84+
Rectangle()
85+
.fill(.background)
86+
.frame(width: 100, height: 50)
87+
Rectangle()
88+
.fill(.background)
89+
.frame(width: 100, height: 50)
90+
.backgroundStyle(.red)
91+
}
92+
.backgroundStyle(.blue)
93+
}
94+
}
95+
openSwiftUIAssertSnapshot(of: ContentView())
96+
}
97+
98+
@Test
99+
func backgroundWithContent() {
100+
struct ContentView: View {
101+
var body: some View {
102+
ZStack {
103+
Rectangle()
104+
.fill(.background)
105+
Capsule()
106+
.foregroundStyle(.primary)
107+
}
108+
.frame(width: 100, height: 100)
109+
}
110+
}
111+
openSwiftUIAssertSnapshot(of: ContentView())
112+
}
113+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//
2+
// ForegroundStyleUITests.swift
3+
// OpenSwiftUIUITests
4+
5+
import Testing
6+
import SnapshotTesting
7+
8+
@MainActor
9+
@Suite(.snapshots(record: .never, diffTool: diffTool))
10+
struct ForegroundStyleUITests {
11+
@Test
12+
func foregroundDefault() {
13+
struct ContentView: View {
14+
var body: some View {
15+
Rectangle()
16+
.fill(.foreground)
17+
.frame(width: 100, height: 100)
18+
}
19+
}
20+
openSwiftUIAssertSnapshot(of: ContentView())
21+
}
22+
23+
@Test
24+
func foregroundSingleStyle() {
25+
struct ContentView: View {
26+
var body: some View {
27+
Rectangle()
28+
.frame(width: 100, height: 100)
29+
.foregroundStyle(.blue)
30+
}
31+
}
32+
openSwiftUIAssertSnapshot(of: ContentView())
33+
}
34+
35+
@Test
36+
func foregroundPairStyle() {
37+
struct ContentView: View {
38+
var body: some View {
39+
VStack(spacing: 0) {
40+
Rectangle()
41+
.fill(.primary)
42+
.frame(width: 100, height: 50)
43+
Rectangle()
44+
.fill(.secondary)
45+
.frame(width: 100, height: 50)
46+
}
47+
.foregroundStyle(.red, .blue)
48+
}
49+
}
50+
openSwiftUIAssertSnapshot(of: ContentView())
51+
}
52+
53+
@Test
54+
func foregroundTripleStyle() {
55+
struct ContentView: View {
56+
var body: some View {
57+
VStack(spacing: 0) {
58+
Rectangle()
59+
.fill(.primary)
60+
.frame(width: 100, height: 34)
61+
Rectangle()
62+
.fill(.secondary)
63+
.frame(width: 100, height: 33)
64+
Rectangle()
65+
.fill(.tertiary)
66+
.frame(width: 100, height: 33)
67+
}
68+
.foregroundStyle(.red, .green, .blue)
69+
}
70+
}
71+
openSwiftUIAssertSnapshot(of: ContentView())
72+
}
73+
74+
@Test
75+
func foregroundNestedStyle() {
76+
struct ContentView: View {
77+
var body: some View {
78+
VStack(spacing: 0) {
79+
Rectangle()
80+
.frame(width: 100, height: 50)
81+
Rectangle()
82+
.frame(width: 100, height: 50)
83+
.foregroundStyle(.red)
84+
}
85+
.foregroundStyle(.blue)
86+
}
87+
}
88+
openSwiftUIAssertSnapshot(of: ContentView())
89+
}
90+
91+
@Test(.disabled("Text is not supported yet"))
92+
func foregroundWithText() {
93+
struct ContentView: View {
94+
var body: some View {
95+
Text("Hello")
96+
.font(.largeTitle)
97+
.foregroundStyle(.blue)
98+
}
99+
}
100+
openSwiftUIAssertSnapshot(of: ContentView())
101+
}
102+
103+
@Test
104+
func foregroundHierarchical() {
105+
struct ContentView: View {
106+
var body: some View {
107+
VStack(spacing: 0) {
108+
Rectangle()
109+
.fill(.primary)
110+
.frame(width: 100, height: 50)
111+
Rectangle()
112+
.fill(.secondary)
113+
.frame(width: 100, height: 50)
114+
}
115+
.foregroundStyle(.blue)
116+
}
117+
}
118+
openSwiftUIAssertSnapshot(of: ContentView())
119+
}
120+
}

0 commit comments

Comments
 (0)