Skip to content

Commit 128c26b

Browse files
authored
Merge pull request #878 from RomanticD/fix/issue-854-light-mode-secondary-color-is-white
Fix light mode secondary/tertiary colors rendering as white (#854)
2 parents 34d8429 + deca8ac commit 128c26b

2 files changed

Lines changed: 61 additions & 4 deletions

File tree

Sources/Ignite/Themes/Theme-DefaultImplementation.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ public extension Theme {
5454

5555
var secondary: Color {
5656
colorScheme == .dark ?
57-
Color(red: 222, green: 226, blue: 230, opacity: 0.75) :
58-
Color(red: 33, green: 37, blue: 41, opacity: 0.75)
57+
Color(red: 222, green: 226, blue: 230, opacity: 75%) :
58+
Color(red: 33, green: 37, blue: 41, opacity: 75%)
5959
}
6060

6161
var tertiary: Color {
6262
colorScheme == .dark ?
63-
Color(red: 222, green: 226, blue: 230, opacity: 0.5) :
64-
Color(red: 33, green: 37, blue: 41, opacity: 0.5)
63+
Color(red: 222, green: 226, blue: 230, opacity: 50%) :
64+
Color(red: 33, green: 37, blue: 41, opacity: 50%)
6565
}
6666

6767
var background: Color {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// ThemeDefaultColors.swift
3+
// Ignite
4+
// https://www.github.com/twostraws/Ignite
5+
// See LICENSE for license information.
6+
//
7+
8+
import Foundation
9+
import Testing
10+
11+
@testable import Ignite
12+
13+
/// Tests for the default `Theme` colors that rely on `colorScheme` to pick
14+
/// a light- or dark-mode value. Regression coverage for #854, where the
15+
/// default `secondary` and `tertiary` colors were rendered as white because
16+
/// the call sites passed `opacity: 0.75`/`0.5` (a `Double`) instead of
17+
/// `75%`/`50%` (a `Percentage`), causing Swift to pick the 0-1 RGB `Double`
18+
/// initializer and scale the integer RGB components by 255.
19+
@Suite("Default Theme Colors")
20+
@MainActor
21+
struct ThemeDefaultColorsTests {
22+
@Test("Default light theme secondary color stays within valid RGB range")
23+
func lightSecondaryStaysInRGBRange() {
24+
let color = DefaultLightTheme().secondary
25+
#expect(color.red == 33)
26+
#expect(color.green == 37)
27+
#expect(color.blue == 41)
28+
#expect(color.opacity == 75)
29+
}
30+
31+
@Test("Default dark theme secondary color stays within valid RGB range")
32+
func darkSecondaryStaysInRGBRange() {
33+
let color = DefaultDarkTheme().secondary
34+
#expect(color.red == 222)
35+
#expect(color.green == 226)
36+
#expect(color.blue == 230)
37+
#expect(color.opacity == 75)
38+
}
39+
40+
@Test("Default light theme tertiary color stays within valid RGB range")
41+
func lightTertiaryStaysInRGBRange() {
42+
let color = DefaultLightTheme().tertiary
43+
#expect(color.red == 33)
44+
#expect(color.green == 37)
45+
#expect(color.blue == 41)
46+
#expect(color.opacity == 50)
47+
}
48+
49+
@Test("Default dark theme tertiary color stays within valid RGB range")
50+
func darkTertiaryStaysInRGBRange() {
51+
let color = DefaultDarkTheme().tertiary
52+
#expect(color.red == 222)
53+
#expect(color.green == 226)
54+
#expect(color.blue == 230)
55+
#expect(color.opacity == 50)
56+
}
57+
}

0 commit comments

Comments
 (0)