Skip to content

Add IComposer.ColorScheme()/.Typography()/.Shapes() extension methods - #222

Merged
jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers/theme-reads-off-composer
Jun 10, 2026
Merged

jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers/theme-reads-off-composer

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Owner

Implements brainstorm idea #4 — theme reads off the composer.

Change

Replaces three static methods on MaterialTheme with three extension methods on IComposer, so theme reads at the call site read like Kotlin's MaterialTheme.colorScheme:

Before (removed) After (new)
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 across src/ and samples/ 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().OnSurface now reads like Kotlin's MaterialTheme.colorScheme.onSurface — the composer plays the role of the implicit $composer Kotlin's IR rewrite passes around.

Files touched

  • New: src/Microsoft.AndroidX.Compose/ComposeExtensions.Theme.cs — partial of ComposeExtensions with three extensions inlining BindingMaterialTheme.Instance.GetX(composer, 0) (same body the deleted statics had).
  • Deleted from MaterialTheme.cs: CurrentColorScheme / CurrentTypography / CurrentShapes and the now-unused BindingMaterialTheme alias.
  • Migrated call sites: 4 Jetchat (Conversation, JetchatApp, JetchatIcon, Profile) + 6 Reply (EmailDetailAppBar ×2, EmptyComingSoon, ReplyEmailListItem, ReplyEmailThreadItem, ReplyProfileImage, ReplySearchBar) — 11 .cs call sites total.
  • Article body: samples/JetNews/PostsRepo.cs — updated prose and recomputed MarkupType.Code/Italic offsets so the in-app demo article shows the new pattern.
  • Docs: 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-existing BG8605/BG8606 binding 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]

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]>
@jonathanpeppers
jonathanpeppers marked this pull request as ready for review June 10, 2026 00:51
Copilot AI review requested due to automatic review settings June 10, 2026 00:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.cs partial file with three IComposer extension methods (ColorScheme(), Typography(), Shapes()) that inline the same BindingMaterialTheme.Instance.GetX(composer, 0) bodies the old statics had.
  • Removed the three static methods and the BindingMaterialTheme alias from MaterialTheme.cs; updated PublicAPI.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, and PostsRepo.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
jonathanpeppers enabled auto-merge (squash) June 10, 2026 00:59
@jonathanpeppers
jonathanpeppers merged commit e11db18 into main Jun 10, 2026
1 check passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers/theme-reads-off-composer branch June 10, 2026 01:03
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants