Repository navigation
Add implicit long → Color conversion and IsSpecified/IsUnspecified - #221
Merged
jonathanpeppers merged 1 commit intoJun 10, 2026
Merged
Conversation
`Color` already has an implicit `Color → long` operator so wrappers flow
into bindings without ceremony, but the inverse was missing. Theme color
getters on the bound `ColorScheme` (and other binding-typed APIs) return
`long` because Kotlin's `androidx.compose.ui.graphics.Color` is a
`@JvmInline value class` over `ULong`, so every call site had to wrap:
Color = new Color(scheme.OnSurface),
This adds the inverse implicit so the same call site reads:
Color = scheme.OnSurface,
Also adds the missing `IsSpecified` / `IsUnspecified` properties that
Kotlin's `Color` exposes via extension members on the inline class.
Useful for "fall back to the parent / theme default" branches where
`Color.Unspecified` is the sentinel.
Drops the now-redundant `new Color(...)` wraps across the Jetchat and
Reply samples (the only places they appeared); the implicit fires once
at the property / parameter slot instead. Hex-literal constructors
(`new Color(0xFFAARRGGBB)`) and other ctor shapes are unaffected.
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR adds the inverse of the existing Color → long implicit conversion (long → Color), plus two IsSpecified/IsUnspecified convenience properties that mirror Kotlin's Color.isSpecified/Color.isUnspecified. The new implicit eliminates boilerplate new Color(...) wraps when using long-typed theme colors from the bound ColorScheme, and the sentinel properties support "fall back to theme default" branching against Color.Unspecified.
Changes:
- Three new public members on
Color:implicit operator Color(long),IsSpecified, andIsUnspecified, with correct XML docs and public API tracking entries. - Sample apps (
Jetchat,Reply) updated to drop allnew Color(scheme.*)/new Color(localLong)wraps, exercising the new implicit conversion throughout. MessageFormatter.cslocals changed fromColor→long(matching theColorSchemereturn type), relying on the implicit at theAppendSymbolAnnotationcall boundary.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/Microsoft.AndroidX.Compose/Color.cs |
Adds implicit operator Color(long), IsSpecified, and IsUnspecified |
src/Microsoft.AndroidX.Compose/PublicAPI.Unshipped.txt |
Three new public API entries, correctly sorted |
samples/Jetchat/Conversation.cs |
Drops new Color(...) wraps for theme colors and local long vars |
samples/Jetchat/JetchatDrawer.cs |
Drops new Color(...) wraps for theme colors |
samples/Jetchat/Profile.cs |
Drops new Color(...) wraps for theme colors |
samples/Jetchat/EmojiSelector.cs |
Drops new Color(...) wraps for theme colors |
samples/Jetchat/RecordButton.cs |
Drops new Color(...) wraps for theme colors |
samples/Jetchat/MessageFormatter.cs |
Changes Color locals to long; implicit fires at callee boundary |
samples/Reply/ReplySearchBar.cs |
Drops new Color(...) wraps for theme colors |
samples/Reply/ReplyProfileImage.cs |
Drops new Color(...) wraps for theme colors |
samples/Reply/ReplyEmailThreadItem.cs |
Drops new Color(...) wraps for theme colors |
samples/Reply/ReplyEmailListItem.cs |
Drops new Color(...) wraps for theme colors |
samples/Reply/EmptyComingSoon.cs |
Drops new Color(...) wraps for theme colors |
samples/Reply/EmailDetailAppBar.cs |
Drops new Color(...) wraps for theme colors |
jonathanpeppers
enabled auto-merge (squash)
June 10, 2026 00:45
jonathanpeppers
deleted the
jonathanpeppers/color-implicit-and-isspecified
branch
June 10, 2026 00:46
jonathanpeppers
added a commit
that referenced
this pull request
Jun 10, 2026
After [#221](../pull/221) (implicit `long → Color` conversion) and [#222](../pull/222) (theme reads off composer), the `*Argb` suffix on color properties is vestigial — callers can pass `scheme.OnSurface` (a `long`) straight to a `Color?` property and the implicit conversion does the rest. The five hand-written facades that still exposed `long? *Argb` are renamed here to match the shape the source-generated `Text` facade already uses (`public Color? Color`). ### Renames | File | Before | After | |------|--------|-------| | `Icon.cs` | `long? TintArgb` | `Color? Tint` | | `HorizontalDivider.cs` | `long? ColorArgb` | `Color? Color` | | `VerticalDivider.cs` | `long? ColorArgb` | `Color? Color` | | `CircularProgressIndicator.cs` | `long? ColorArgb`, `long? TrackColorArgb` | `Color? Color`, `Color? TrackColor` | | `LinearProgressIndicator.cs` | `long? ColorArgb`, `long? TrackColorArgb` | `Color? Color`, `Color? TrackColor` | The render bodies still call the bound `DividerKt` / `ProgressIndicatorKt` / `IconKt` bindings (and the `IconPainter` bridge) with a `long` color slot; the new properties are converted via `Color is { } c ? c : 0L`. ### No `[Obsolete]` aliases Same rationale as [#221](../pull/221), [#223](../pull/223), [#225](../pull/225), [#226](../pull/226), [#229](../pull/229): every removed entry was in `PublicAPI.Unshipped.txt`, never `Shipped.txt`, so a clean break is acceptable pre-1.0. Verified — only `Color.FromArgb(...)` factories remain (intentional, those aren't being renamed). ### Sweep 19 callsite renames across two samples; JetNews and the Gallery had no references. | Sample | File | Hits | |--------|------|------| | Jetchat | `Conversation.cs` | 5 | | Jetchat | `Profile.cs` | 4 | | Jetchat | `RecordButton.cs` | 2 | | Jetchat | `JetchatIcon.cs` | 2 | | Jetchat | `JetchatDrawer.cs` | 1 | | Reply | `EmailDetailAppBar.cs` | 1 | | Reply | `ReplyEmailListItem.cs` | 1 | | Reply | `ReplyEmailThreadItem.cs` | 1 | | Reply | `ReplyProfileImage.cs` | 1 | | Reply | `ReplySearchBar.cs` | 1 | ### Verified - ✅ `dotnet test src/Microsoft.AndroidX.Compose.SourceGenerators.Tests` — 132/132 - ✅ `dotnet build src/Microsoft.AndroidX.Compose` — clean (no RS0016/RS0017) - ✅ `dotnet build src/Microsoft.AndroidX.Compose.Gallery` - ✅ `dotnet build samples/Jetchat` - ✅ `dotnet build samples/JetNews` - ✅ `dotnet build samples/Reply` Not deployed to a device — leaving smoke-test for the user. ### Coordination Round-2 #2. Disjoint file set from sibling round-2 PRs except for `PublicAPI.Unshipped.txt` — expect a mechanical sort conflict on merge with round-2 #1 (`Modifier.Padding` defaults) and round-2 #3 (`Func<IComposer, ComposableNode>` implicit). Co-authored-by: Copilot <[email protected]>
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.
Brings
AndroidX.Compose.Colorcloser to Kotlin'sandroidx.compose.ui.graphics.Colorsurface by adding the missing inverse of the existingColor → longimplicit, plus the twoIsSpecified/IsUnspecifiedproperties.From the "API improvement ideas" brainstorm session (parent:
jonathanpeppers/fictional-happiness).Why
Theme color getters on the bound
ColorSchemereturnlongbecause Compose'sandroidx.compose.ui.graphics.Coloris a@JvmInline value classoverULong. We already haveimplicit operator long(Color)going one way, so aColorflows into bindings without ceremony. The inverse was missing, so every call site reading a theme color into a facade slot wrapped it explicitly:After this change:
Kotlin's
Coloralso exposesisSpecified/isUnspecifiedextension members on the inline class that peek at the packed sentinel. We didn't expose either — useful for "fall back to the parent / theme default" branches whereColor.Unspecifiedis the marker:What changed
src/Microsoft.AndroidX.Compose/Color.cs— three new public members alongside the existing implicit operator:public static implicit operator Color(long packedValue)→new(packedValue)public bool IsSpecified→PackedValue != Unspecified.PackedValuepublic bool IsUnspecified→ inversesamples/Jetchat/,samples/Reply/— dropped the now-redundantnew Color(...)wraps around binding-typedlongs (theme colors +longlocals derived from them). The implicit fires once at the property / parameter slot instead. InMessageFormatter.cstwovarlocals became explicitlongsince they're plumbed through toColorparameters elsewhere.PublicAPI.Unshipped.txt— three new entries.Hex-literal constructors (
new Color(0xFFAARRGGBB)) and otherColor(…)ctor shapes are unaffected — onlynew Color(<binding long>)wraps were dropped.Ambiguity check
Confirmed via grep before adding the implicit:
longandColorparameters where overload resolution would flip.(long)casts onColorexist insrc/or samples.Color.Unspecifiedtoday (so theIsSpecifiedmigration step is a no-op for now — the property is still added for parity with Kotlin).Color == longbecoming legal (via implicit lift) is benign — noColor == 0or similar usages exist.Verification
Not deployed —
@jonathanpeppersis smoke-testing locally.Co-authored-by: Copilot [email protected]