Skip to content

Commit 1a6c9f3

Browse files
authored
Add Color opacity support (#335)
* Update Package.swift for compatibility test * Add Color.opacity support * Add MixProvider and GradientColorSpace * Add CustomVibrantColor_Watch * Add Color UI test case * [NFC] Migrate OpenSwiftUIUITests into unit test target to support host app bundle for NamedColor * Disable NamedColor test for macOS * Fix Linux build issue * Fix opacity test case on non-Darwin platform
1 parent a998133 commit 1a6c9f3

File tree

31 files changed

+701
-487
lines changed

31 files changed

+701
-487
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
IPHONEOS_DEPLOYMENT_TARGET = 18.0
22
MACOSX_DEPLOYMENT_TARGET = 15.0
33

4+
SWIFT_VERSION = 5.0
5+
46
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) $(GCC_PREPROCESSOR_DEFINITIONS_OPENSWIFTUI) $(GCC_PREPROCESSOR_DEFINITIONS_DEBUG)
57
SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) $(SWIFT_ACTIVE_COMPILATION_CONDITIONS_OPENSWIFTUI) $(SWIFT_ACTIVE_COMPILATION_CONDITIONS_DEBUG)
68
OTHER_SWIFT_FLAGS = $(inherited) $(OPENSWIFTUI_AVAILABILITY_MACRO)

Example/Example.xcodeproj/project.pbxproj

Lines changed: 145 additions & 394 deletions
Large diffs are not rendered by default.

Example/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
parallelizable = "YES">
3636
<BuildableReference
3737
BuildableIdentifier = "primary"
38-
BlueprintIdentifier = "275751F42DEE1456003E467C"
38+
BlueprintIdentifier = "279283B82DFF11CE00234D64"
3939
BuildableName = "OpenSwiftUIUITests.xctest"
4040
BlueprintName = "OpenSwiftUIUITests"
4141
ReferencedContainer = "container:Example.xcodeproj">

Example/Example.xcodeproj/xcshareddata/xcschemes/OpenSwiftUIUITests.xcscheme

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
buildArchitectures = "Automatic">
99
</BuildAction>
1010
<TestAction
11-
buildConfiguration = "SwiftUIDebug"
11+
buildConfiguration = "OpenSwiftUIDebug"
1212
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
1313
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
1414
shouldUseLaunchSchemeArgsEnv = "YES">
@@ -24,7 +24,7 @@
2424
parallelizable = "YES">
2525
<BuildableReference
2626
BuildableIdentifier = "primary"
27-
BlueprintIdentifier = "275751F42DEE1456003E467C"
27+
BlueprintIdentifier = "279283B82DFF11CE00234D64"
2828
BuildableName = "OpenSwiftUIUITests.xctest"
2929
BlueprintName = "OpenSwiftUIUITests"
3030
ReferencedContainer = "container:Example.xcodeproj">
@@ -42,15 +42,6 @@
4242
debugDocumentVersioning = "YES"
4343
debugServiceExtension = "internal"
4444
allowLocationSimulation = "YES">
45-
<MacroExpansion>
46-
<BuildableReference
47-
BuildableIdentifier = "primary"
48-
BlueprintIdentifier = "275751E22DEE1441003E467C"
49-
BuildableName = "TestingHost.app"
50-
BlueprintName = "TestingHost"
51-
ReferencedContainer = "container:Example.xcodeproj">
52-
</BuildableReference>
53-
</MacroExpansion>
5445
</LaunchAction>
5546
<ProfileAction
5647
buildConfiguration = "SwiftUIDebug"

Example/OpenSwiftUIUITests/Export.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import XCTest
66
import SnapshotTesting
77

88
#if OPENSWIFTUI
9+
@_exported import OpenSwiftUI
910
let shouldRecord: Bool? = nil
1011
#else
12+
@_exported import SwiftUI
1113
let shouldRecord: Bool? = true
1214
#endif
1315
let diffTool: SnapshotTestingConfiguration.DiffTool = .default

Example/OpenSwiftUIUITests/FB/FB13341321.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
// Status Update:
2626
// Fixed on macOS 15.1
2727

28+
#if !OPENSWIFTUI
29+
2830
import SwiftUI
2931
import Observation
3032

@@ -112,3 +114,4 @@ extension View {
112114
FB13341321.ContentView()
113115
.padding(20)
114116
}
117+
#endif
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//
2+
// ColorUITests.swift
3+
// OpenSwiftUIUITests
4+
5+
import Testing
6+
import SnapshotTesting
7+
8+
@MainActor
9+
@Suite(.snapshots(record: .never, diffTool: diffTool))
10+
struct ColorUITests {
11+
@Test(
12+
arguments: [
13+
(Color(red: 1.0, green: 0.0, blue: 0.0), "red"),
14+
(Color(red: 0.0, green: 1.0, blue: 0.0), "green"),
15+
(Color(red: 0.0, green: 0.0, blue: 1.0), "blue"),
16+
(Color(red: 1.0, green: 1.0, blue: 0.0), "yellow"),
17+
(Color(red: 1.0, green: 0.0, blue: 1.0), "magenta"),
18+
(Color(red: 0.0, green: 1.0, blue: 1.0), "cyan"),
19+
(Color(red: 0.5, green: 0.5, blue: 0.5), "gray"),
20+
]
21+
)
22+
func rgbColors(_ color: Color, name: String) {
23+
openSwiftUIAssertSnapshot(
24+
of: color,
25+
testName: "rgb_\(name)"
26+
)
27+
}
28+
29+
@Test(
30+
arguments: [
31+
(Color(white: 0.0), "black"),
32+
(Color(white: 0.25), "dark_gray"),
33+
(Color(white: 0.5), "medium_gray"),
34+
(Color(white: 0.75), "light_gray"),
35+
(Color(white: 1.0), "white"),
36+
]
37+
)
38+
func grayscaleColors(_ color: Color, name: String) {
39+
openSwiftUIAssertSnapshot(
40+
of: color,
41+
testName: "grayscale_\(name)"
42+
)
43+
}
44+
45+
@Test(
46+
arguments: [
47+
(Color(hue: 0.0, saturation: 1.0, brightness: 1.0), "red"),
48+
(Color(hue: 0.33, saturation: 1.0, brightness: 1.0), "green"),
49+
(Color(hue: 0.67, saturation: 1.0, brightness: 1.0), "blue"),
50+
(Color(hue: 0.5, saturation: 0.5, brightness: 1.0), "desaturated_cyan"),
51+
(Color(hue: 0.0, saturation: 1.0, brightness: 0.5), "dark_red"),
52+
]
53+
)
54+
func hsbColors(_ color: Color, name: String) {
55+
openSwiftUIAssertSnapshot(
56+
of: color,
57+
testName: "hsb_\(name)"
58+
)
59+
}
60+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// ModifiedColorUITests.swift
3+
// OpenSwiftUIUITests
4+
5+
import Testing
6+
import SnapshotTesting
7+
8+
@MainActor
9+
@Suite(.snapshots(record: .never, diffTool: diffTool))
10+
struct ModifiedColorUITests {
11+
func opacity() {
12+
openSwiftUIAssertSnapshot(
13+
of: Color.red.opacity(0.3)
14+
)
15+
}
16+
17+
@Test
18+
func multipleOpacityLayers() {
19+
openSwiftUIAssertSnapshot(
20+
of: Color.red.opacity(0.6).opacity(0.5)
21+
)
22+
}
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// NamedColorUITests.swift
3+
// OpenSwiftUIUITests
4+
5+
import Testing
6+
import SnapshotTesting
7+
8+
import Foundation
9+
10+
@MainActor
11+
@Suite(.snapshots(record: .never, diffTool: diffTool))
12+
struct NamedColorUITests {
13+
@Test(.disabled {
14+
#if os(macOS)
15+
true
16+
#else
17+
false
18+
#endif
19+
})
20+
func namedColor() {
21+
let bundle = Bundle.main
22+
openSwiftUIAssertSnapshot(
23+
of: Color("custom")
24+
)
25+
}
26+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// SystemColorUITests.swift
3+
// OpenSwiftUIUITests
4+
5+
import Testing
6+
import SnapshotTesting
7+
8+
@MainActor
9+
@Suite(.snapshots(record: .never, diffTool: diffTool))
10+
struct SystemColorUITests {
11+
@Test(
12+
arguments: [
13+
(Color.red, "red"),
14+
(Color.blue, "blue"),
15+
(Color.green, "green"),
16+
(Color.yellow, "yellow"),
17+
(Color.orange, "orange"),
18+
(Color.purple, "purple"),
19+
(Color.pink, "pink"),
20+
(Color.black, "black"),
21+
(Color.white, "white"),
22+
(Color.gray, "gray"),
23+
(Color.clear, "clear"),
24+
]
25+
)
26+
func systemColors(_ color: Color, name: String) {
27+
openSwiftUIAssertSnapshot(
28+
of: color,
29+
testName: "system_color_\(name)"
30+
)
31+
}
32+
33+
@Test(
34+
arguments: [
35+
(Color.primary, "primary"),
36+
(Color.secondary, "secondary"),
37+
]
38+
)
39+
func hierarchicalColors(_ color: Color, name: String) {
40+
openSwiftUIAssertSnapshot(
41+
of: color,
42+
testName: "hierarchical_color_\(name)"
43+
)
44+
}
45+
}

0 commit comments

Comments
 (0)