Add Spacer.Width/.Height/.Size/.Weight static factories#225
Merged
Conversation
Replaces the verbose `new Spacer(Modifier.Companion.Width(8))` shape with `Spacer.Width(8)`. Five static factories on `Spacer`: * `Spacer.Width(Dp)` / `Spacer.Height(Dp)` / `Spacer.Size(Dp)` * `Spacer.Size(Dp width, Dp height)` (mirrors `Modifier.Size(Dp, Dp)`) * `Spacer.Weight(float weight, bool fill = true)` for the push-siblings-apart idiom inside `Row` / `Column`. Migrates 24 call sites across samples and the gallery demo. Keeps the existing `Spacer()` and `Spacer(Modifier)` ctors -- the latter still has one legitimate caller (`StatusBarsPadding`) so removing it would be a breaking change with no real ergonomics win. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds five static factory methods to Spacer (Width, Height, Size (two overloads), and Weight) to shorten the common "insert a gap" idiom from new Spacer(Modifier.Companion.Width(8)) to Spacer.Width(8). Each factory is a trivial delegation to the existing Modifier.Companion instance method. The two existing constructors are preserved, keeping this a non-breaking change. All 24 eligible call sites across the sample apps and gallery are mechanically migrated.
Changes:
- Added 5 new static factory methods on
Spacerwith comprehensive XML docs, each delegating toModifier.Companion.Width/Height/Size/Weight. - Migrated 24 call sites in 10 files (samples/Jetchat, samples/JetNews, samples/Reply, Gallery) from
new Spacer(Modifier.Companion.X(...))to the new short form. - Updated
PublicAPI.Unshipped.txtwith the 5 new public API entries.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/Microsoft.AndroidX.Compose/Spacer.cs |
Adds Width(Dp), Height(Dp), Size(Dp), Size(Dp, Dp), Weight(float, bool) static factories |
src/Microsoft.AndroidX.Compose/PublicAPI.Unshipped.txt |
Registers 5 new public API entries (sorted, correct signatures) |
samples/Jetchat/Conversation.cs |
Migrates 7 spacer call sites |
samples/Jetchat/JetchatDrawer.cs |
Migrates 1 spacer call site |
samples/Jetchat/Profile.cs |
Migrates 3 spacer call sites |
samples/Jetchat/RecordButton.cs |
Migrates 2 spacer call sites |
samples/JetNews/HomeCards.cs |
Migrates 2 spacer call sites (including 1 Weight) |
samples/JetNews/JetnewsDrawer.cs |
Migrates 1 spacer call site |
samples/JetNews/PostBody.cs |
Migrates 1 spacer call site |
samples/JetNews/PostScreen.cs |
Migrates 2 spacer call sites |
samples/Reply/EmptyComingSoon.cs |
Migrates 1 spacer call site |
src/Microsoft.AndroidX.Compose.Gallery/Demos/Navigation/BackHandlerDemo.cs |
Migrates 4 spacer call sites |
…r-static-factories # Conflicts: # samples/Jetchat/Conversation.cs
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 <223556219+Copilot@users.noreply.github.com>
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.
Brainstorm idea #7 — make the "insert a small gap" idiom one expression instead of three.
Motivation
Inserting an 8-dp gap reads:
Mirrors the shape of
Modifier.Width/Height/Size. Same lowering — each factory isnew Spacer(Modifier.Companion.X(...))under the hood, no new properties onSpacer, no behavioural change.API
Five new statics on
AndroidX.Compose.Spacer:Spacer.Width(Dp)new Spacer(Modifier.Width(dp))Spacer.Height(Dp)new Spacer(Modifier.Height(dp))Spacer.Size(Dp)new Spacer(Modifier.Size(dp))Spacer.Size(Dp, Dp)new Spacer(Modifier.Size(w, h))Spacer.Weight(float, bool fill = true)new Spacer(Modifier.Weight(w, fill))All take
Dp; the existingimplicit operator Dp(int)lets callers writeSpacer.Width(8)literally.The two existing ctors (
Spacer(),Spacer(Modifier)) are kept — one site (JetchatDrawer.cs:32StatusBarsPadding) still legitimately uses the modifier ctor and four sentinelnew Spacer()calls live in pattern-match defaults. Not removing them; this PR is non-breaking despite the original suggestion's openness to breaking changes.Migrated call sites (24)
Out-of-scope (untouched): 4 sentinel
new Spacer()arms inHomeScreen.cs/PostScreen.cs, plus 1new Spacer(Modifier.Companion.StatusBarsPadding())inJetchatDrawer.cs.Coordination — Modifier-statics race
The Modifier-statics PR (
jonathanpeppers/modifier-static-factories) hasn't merged. Factory bodies useModifier.Companion.Width(dp)(existing instance method onModifier.Companion), notModifier.Width(dp)(the not-yet-merged static). Once that PR lands a trivial mechanical follow-up can strip.Companionfrom these five lines inSpacer.cs.Verified
dotnet test src/Microsoft.AndroidX.Compose.SourceGenerators.Tests— 130/130 passingdotnet build src/Microsoft.AndroidX.Compose— 0 errorsdotnet build src/Microsoft.AndroidX.Compose.Gallery— 0 errors, 0 warningsdotnet build samples/{Jetchat,JetNews,Reply}— all greenNo device deploy.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com