Skip to content

Commit b9da62c

Browse files
Material Engcopybara-github
authored andcommitted
Correct logic for tonePrefersLightForeground in Swift.
PiperOrigin-RevId: 545717210
1 parent 7b66542 commit b9da62c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

swift/Sources/MaterialColorUtilities/DynamicColor/DynamicColor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ class DynamicColor {
366366
/// - Parameter tone: The tone to be judged.
367367
/// - Returns: whether `tone` prefers a light foreground.
368368
static func tonePrefersLightForeground(_ tone: Double) -> Bool {
369-
return round(tone) <= 60
369+
return round(tone) < 60
370370
}
371371

372372
/// Returns whether `tone` can reach a contrast ratio of 4.5 with a lighter

swift/Tests/MaterialColorUtilitiesTests/SchemeTests/SchemeFidelityTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,4 +379,17 @@ final class SchemeFidelityTests: XCTestCase {
379379
XCTAssertEqual(MaterialDynamicColors.onTertiaryFixed.getArgb(scheme), 0xff00_0000)
380380
XCTAssertEqual(MaterialDynamicColors.onTertiaryFixedVariant.getArgb(scheme), 0xff37_0000)
381381
}
382+
383+
func testEdgeCaseWithTone60() {
384+
let scheme = SchemeFidelity(
385+
sourceColorHct: Hct.fromInt(0xffff_0000),
386+
isDark: false,
387+
contrastLevel: 0
388+
)
389+
390+
XCTAssertEqual(MaterialDynamicColors.secondary.getArgb(scheme), 0xffb7_2114)
391+
XCTAssertEqual(MaterialDynamicColors.onSecondary.getArgb(scheme), 0xffff_ffff)
392+
XCTAssertEqual(MaterialDynamicColors.secondaryContainer.getArgb(scheme), 0xffff_6f5b)
393+
XCTAssertEqual(MaterialDynamicColors.onSecondaryContainer.getArgb(scheme), 0xff27_0000)
394+
}
382395
}

0 commit comments

Comments
 (0)