Implement Color.mix(with:by:in:) for Compose - #503
Closed
gurmeherchawla wants to merge 1 commit into
Closed
Conversation
Mixes colors in the perceptual (Oklab) color space via Compose's androidx.compose.ui.graphics.lerp, matching SwiftUI's default, or by component-wise sRGB interpolation for Gradient.ColorSpace.device. Gives Gradient.ColorSpace an identifier so .device and .perceptual are distinguishable, and adds a bridged variant for skip-fuse-ui support. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Thank you for your pull request and welcome to the Skip community. We require contributors to sign our contributor license agreement (CLA), and we don't seem to have the user(s) @gurmeherchawla on file. In order for us to review and merge your code, for each noted user please add your GitHub username to Skip's .clabot file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements SwiftUI's
Color.mix(with:by:in:)(iOS 18 / macOS 15) for Compose..perceptual(the SwiftUI default): uses Compose'sandroidx.compose.ui.graphics.lerp, which interpolates in the Oklab color space — the same space SwiftUI uses for perceptual mixing, so results match iOS exactly (verified by the new snapshot tests)..device: converts both colors to sRGB and interpolates component-wise (including alpha).0...1, matching SwiftUI.Gradient.ColorSpacepreviously had no stored properties, making.device == .perceptual; it now carries anidentifierso the two are distinguishable.// SKIP @bridgevariant taking the color space as anInt(0 = device, 1 = perceptual) so skip-fuse-ui can lift its@available(*, unavailable)marker onmixin a follow-up.Because the mixed color is computed inside
colorImplat composition time, mixing dynamic colors (e.g. asset catalog colors with dark-mode variants) resolves against the current color scheme, as on iOS.Testing
skip test --filter ColorTests: all tests pass on both macOS (native SwiftUI, validating the expected pixel values against Apple's implementation) and Android (Robolectric):testColorMixPerceptual: 50% black/white mix renders#636363(Oklab L = 0.5) on both platformstestColorMixDevice: 50% black/white device-space mix renders#808080on both platformstestColorMixFullFraction,testColorMixFractionClampedAbove,testColorMixFractionClampedBelow: endpoint and clamping behavior🤖 Generated with Claude Code