Repository navigation
Add IComposer.ColorScheme()/.Typography()/.Shapes() extension methods - #222
Merged
Merged
Conversation
Replaces the static `MaterialTheme.CurrentColorScheme(composer)` /
`CurrentTypography(composer)` / `CurrentShapes(composer)` methods with
extension methods on `IComposer` so theme reads in Render bodies look
like Kotlin's `MaterialTheme.colorScheme`:
// before
var scheme = MaterialTheme.CurrentColorScheme(c);
// after
var scheme = c.ColorScheme();
Breaking: the three Current* statics are removed; every call site is
migrated in the same commit.
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR refactors three theme-read methods (CurrentColorScheme, CurrentTypography, CurrentShapes) from static methods on MaterialTheme into extension methods on IComposer in the ComposeExtensions partial class. This aligns the C# call-site shape more closely with Kotlin's MaterialTheme.colorScheme pattern, where composer.ColorScheme() mirrors the implicit $composer rewrite Kotlin does under the hood. This is a breaking API change — all existing call sites are migrated in the same commit.
Changes:
- New
ComposeExtensions.Theme.cspartial file with threeIComposerextension methods (ColorScheme(),Typography(),Shapes()) that inline the sameBindingMaterialTheme.Instance.GetX(composer, 0)bodies the old statics had. - Removed the three static methods and the
BindingMaterialThemealias fromMaterialTheme.cs; updatedPublicAPI.Unshipped.txt(3 removals, 3 additions, re-sorted). - Migrated all 11 call sites across Jetchat (4) and Reply (7) samples, plus updated documentation references in
Composed.cs,MaterialTheme.cs,README.md,architecture.md,Jetchat/README.md, andPostsRepo.cs(with recomputed markup offsets).
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/Microsoft.AndroidX.Compose/ComposeExtensions.Theme.cs |
New partial file: three IComposer extension methods for theme reads |
src/Microsoft.AndroidX.Compose/MaterialTheme.cs |
Removed CurrentColorScheme/CurrentTypography/CurrentShapes statics and BindingMaterialTheme alias; updated <remarks> cref links |
src/Microsoft.AndroidX.Compose/PublicAPI.Unshipped.txt |
3 old entries removed, 3 new entries added, re-sorted |
src/Microsoft.AndroidX.Compose/Composed.cs |
Updated <summary> and <remarks> doc references to new extension methods |
samples/Jetchat/Conversation.cs |
Migrated MaterialTheme.CurrentColorScheme(c) → c.ColorScheme() |
samples/Jetchat/JetchatApp.cs |
Migrated call site |
samples/Jetchat/JetchatIcon.cs |
Migrated call site |
samples/Jetchat/Profile.cs |
Migrated call site |
samples/Reply/EmailDetailAppBar.cs |
Migrated 2 call sites |
samples/Reply/EmptyComingSoon.cs |
Migrated call site |
samples/Reply/ReplyEmailListItem.cs |
Migrated call site |
samples/Reply/ReplyEmailThreadItem.cs |
Migrated call site |
samples/Reply/ReplyProfileImage.cs |
Migrated call site |
samples/Reply/ReplySearchBar.cs |
Migrated call site |
samples/JetNews/PostsRepo.cs |
Updated article body text and recomputed Markup offsets |
README.md |
Updated "Theme & layout" table to show new API shape |
docs/architecture.md |
Updated theming reads documentation |
samples/Jetchat/README.md |
Updated two references to old API (2 locations) |
Matches the convention used across the rest of ComposeExtensions (ColorResource, SideEffect, RememberCore, etc.) and the repo style guide's mandate for ArgumentNullException.ThrowIfNull(x) on net10.0 projects. Without the guard the call would NRE inside the binding when composer is null, which is harder to diagnose. Co-authored-by: Copilot <[email protected]>
jonathanpeppers
enabled auto-merge (squash)
June 10, 2026 00:59
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.
Implements brainstorm idea #4 — theme reads off the composer.
Change
Replaces three static methods on
MaterialThemewith three extension methods onIComposer, so theme reads at the call site read like Kotlin'sMaterialTheme.colorScheme:MaterialTheme.CurrentColorScheme(composer)composer.ColorScheme()MaterialTheme.CurrentTypography(composer)composer.Typography()MaterialTheme.CurrentShapes(composer)composer.Shapes()Breaking — the three
MaterialTheme.CurrentX(IComposer)statics are deleted; all 13 call sites acrosssrc/andsamples/are migrated in this commit.Win at the call site
samples/Jetchat/Conversation.cs:new Composed(c => { - var scheme = MaterialTheme.CurrentColorScheme(c); + var scheme = c.ColorScheme(); var root = new Column ...composer.ColorScheme().OnSurfacenow reads like Kotlin'sMaterialTheme.colorScheme.onSurface— the composer plays the role of the implicit$composerKotlin's IR rewrite passes around.Files touched
src/Microsoft.AndroidX.Compose/ComposeExtensions.Theme.cs— partial ofComposeExtensionswith three extensions inliningBindingMaterialTheme.Instance.GetX(composer, 0)(same body the deleted statics had).MaterialTheme.cs:CurrentColorScheme/CurrentTypography/CurrentShapesand the now-unusedBindingMaterialThemealias.Conversation,JetchatApp,JetchatIcon,Profile) + 6 Reply (EmailDetailAppBar×2,EmptyComingSoon,ReplyEmailListItem,ReplyEmailThreadItem,ReplyProfileImage,ReplySearchBar) — 11.cscall sites total.samples/JetNews/PostsRepo.cs— updated prose and recomputedMarkupType.Code/Italicoffsets so the in-app demo article shows the new pattern.docs/architecture.md,samples/Jetchat/README.md(twice),README.md,src/Microsoft.AndroidX.Compose/Composed.cs<remarks>,src/Microsoft.AndroidX.Compose/MaterialTheme.cs<remarks>.PublicAPI.Unshipped.txt: 3 old entries removed, 3 new ones added, file re-sorted.Verified
dotnet build src/Microsoft.AndroidX.Compose— facade, only pre-existingBG8605/BG8606binding warnings, 0 errors.dotnet build src/Microsoft.AndroidX.Compose.Gallery— full Android build, 0 warnings, 0 errors.dotnet test src/Microsoft.AndroidX.Compose.SourceGenerators.Tests— 130/130 passed.Co-authored-by: Copilot [email protected]