Skip to content

Bump Compose UI.Graphics to 1.11.2.1, port colors to ColorKt - #77

Merged
jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers/compose-ui-graphics-color
Jun 5, 2026
Merged

jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers/compose-ui-graphics-color

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Owner

Xamarin.AndroidX.Compose.UI.Graphics 1.11.2.1 finally binds the Compose Color type that we'd been hand-packing from Android.Graphics.Color (the temporary workaround called out in Modifier.cs and tracked as dotnet/android-libraries#1437). This swaps to the real bindings.

What changed

  • Modifier.Background and Modifier.Border now take a packed Compose Color long directly, the same value Kotlin's @JvmInline value class Color(val value: ULong) uses and that ComposeBridges.Modifier{Background,Border} already expect. The hand-rolled PackComposeColor(Android.Graphics.Color) helper is gone.
  • Call sites build colors via the now-bound AndroidX.Compose.UI.Graphics.ColorKt.Color(int red, int green, int blue, int alpha) factory, so the only Color-typed thing in the facade and samples is the Compose one. using Android.Graphics; is dropped from Modifier.cs, MainActivity.cs, and samples/Jetchat/Conversation.cs.

Package version coupling

UI.Graphics 1.11.2.1 transitively requires Compose.UI.Unit [1.11.2, 1.11.3), which version-locks the rest of the 1.11.x stack to 1.11.2. There's no .1 revision yet on UI / UI.Android / Foundation.Layout{,.Android} / Runtime{,.Android} / UI.Unit{,.Android}, so those move to plain 1.11.2; Foundation{,.Android} and UI.Graphics{,.Android} go to 1.11.2.1. Material3 1.4.0.x is unchanged because its dependencies on the 1.11.x stack are minimum-version constraints.

Verification

  • dotnet test src/ComposeNet.SourceGenerators.Tests -- 37/37 passing.
  • dotnet build src/ComposeNet.Compose, src/ComposeNet.Sample, and samples/Jetchat all clean (only the pre-existing XML-cref warnings unrelated to this change).

Switches Modifier.Background/Border to take a packed Compose Colorlong directly (the value Kotlin's @JvmInline value class Color uses)
instead of an Android.Graphics.Color that we hand-packed via
PackComposeColor. Call sites build the packed long via the now-bound
AndroidX.Compose.UI.Graphics.ColorKt.Color(int red, int green,
int blue, int alpha) factory.

Xamarin.AndroidX.Compose.UI.Graphics{,.Android} 1.11.2.1 transitively
requires Compose.UI.Unit 1.11.2.x, which version-locks the rest of the
1.11.x stack to 1.11.2 (no .1 published yet for UI/UI.Android/
Foundation.Layout/Runtime). Bumped accordingly in
Directory.Build.targets. Material3 1.4.0.x has minimum-version
dependencies on the 1.11.x stack so it stays put.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings June 5, 2026 15:37

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

Updates the repo’s Compose dependency set to the 1.11.2/1.11.2.1 line and switches the facade/samples from Android.Graphics.Color to the now-bound Compose Color packing (represented as a long), constructed via AndroidX.Compose.UI.Graphics.ColorKt.

Changes:

  • Bumped central Compose package versions and added Xamarin.AndroidX.Compose.UI.Graphics{,.Android} references.
  • Updated Modifier.Background/Border APIs to accept packed Compose Color (long) directly and removed the Android Color packing helper.
  • Updated sample and Jetchat call sites/docs to create colors via ColorKt.Color(...) and dropped using Android.Graphics;.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/ComposeNet.Sample/MainActivity.cs Switched sample color creation to ColorKt.Color(...) and removed Android Color usage.
src/ComposeNet.Compose/Modifier.cs Changed Background/Border to take packed Compose Color (long), removed packing helper, updated XML docs.
src/ComposeNet.Compose/ComposeNet.Compose.csproj Added Compose UI.Graphics package references needed for ColorKt usage.
samples/Jetchat/README.md Updated documentation to reflect new Background(long) / Border(int, long, ...) signatures and ColorKt construction.
samples/Jetchat/Conversation.cs Converted static palette colors from Android.Graphics.Color to packed Compose long via ColorKt.
README.md Updated Compose version references in repo-level docs to 1.11.2.x.
Directory.Build.targets Central package version bump to 1.11.2 / 1.11.2.1 and added UI.Graphics version entries.

Comment thread src/ComposeNet.Compose/Modifier.cs Resolved
Reorder the two ColorKt.Color factories the doc comment points at to
recommend the per-channel (int, int, int, int) overload first, since
the (int) overload can't be called with a bare 0xAARRGGBB literal in
C# when alpha is set (0xFF... is uint, not int). Notes the
unchecked((int)0xFF...) cast for consumers who do reach for the int
overload.

Co-authored-by: Copilot <[email protected]>
@jonathanpeppers
jonathanpeppers merged commit 556c1ab into main Jun 5, 2026
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers/compose-ui-graphics-color branch June 5, 2026 15:50
jonathanpeppers added a commit that referenced this pull request Jun 5, 2026
Add C# representations for Compose `@JvmInline value class` params
(Dp, Sp/Em, TextAlign, FontWeight, TextDecoration, Shape) plus the
bridge generator plumbing to lower them to JNI primitives with auto
`$default`-bit clearing.

`androidx.compose.ui.graphics.Color` is intentionally left out of the
value-type registry. PR #77 just bound it via
`Xamarin.AndroidX.Compose.UI.Graphics`, but Kotlin's
`@JvmInline value class Color(val value: ULong)` surfaces as a raw
packed `long` once you reference the binding, so call sites already
pass `long` straight through to `ModifierBackground`/`ModifierBorder`
via `ColorKt.Color(r,g,b,a)`. There is no C# struct to lower from,
and re-wrapping it would only force callers into a more verbose
`new Color(ColorKt.Color(...))` style for no benefit.

## Generator changes

- New `ComposeValueTypes` registry keyed on full C# type name, with
  per-entry JNI slot character and lowering template.
- `EmitUserArgValue` has a value-type branch; auto-default-mask
  recognizes value types and `IntPtr?` (mirroring `IModifier?`); when
  the user passes a non-null value the matching `$default` bit is
  cleared.
- `NeedsKeepAlive` skips recognized value types (no `IJavaPeerable`
  peer to keep alive).
- New **CN2007** diagnostic - recognized value type on a no-`$default`
  bridge fails fast (auto-mask only fires when there's a bit to
  clear).

## Value type files

- `Dp`, `Sp`, `Em`, `TextAlign` -- `readonly record struct` wrappers
  with `Pack(T?)` static helpers. Kotlin `@JvmInline value class` so
  the binder will never surface them as value types regardless of
  un-stripping.
- `FontWeight`, `TextDecoration`, `Shape` -- `sealed class :
  Java.Lang.Object` with JNI-resolved companion statics / factories,
  designed to swap to bound types once dotnet/android-libraries#1439
  ships and the Compose UI Text/Graphics text packages stop being
  Java-library-only stubs. These use the existing reference-type
  lowering path, not the value-type registry.

No existing bridges or facades are converted in this PR -- the
infrastructure is staged so the next batch of bridges (`Text` colors,
font sizes, padding, etc.) can use typed parameters straight away.

## Tests

Four new generator tests cover Dp on a non-`@Composable` extension
shape, Sp/Em/TextAlign on a `@Composable` shape, FontWeight on the
existing reference-type path, and the CN2007 fail-fast. All 53
generator tests pass; `ComposeNet.Compose`, `ComposeNet.Sample`, and
`samples/Jetchat` all build clean.

Closes #65

Co-authored-by: Copilot <[email protected]>
jonathanpeppers added a commit that referenced this pull request Jun 5, 2026
Add C# representations for Compose `@JvmInline value class` params
(Dp, Sp/Em, TextAlign, FontWeight, TextDecoration, Shape) plus the
bridge generator plumbing to lower them to JNI primitives with auto
`$default`-bit clearing.

`androidx.compose.ui.graphics.Color` is intentionally left out of the
value-type registry. PR #77 just bound it via
`Xamarin.AndroidX.Compose.UI.Graphics`, but Kotlin's
`@JvmInline value class Color(val value: ULong)` surfaces as a raw
packed `long` once you reference the binding, so call sites already
pass `long` straight through to `ModifierBackground`/`ModifierBorder`
via `ColorKt.Color(r,g,b,a)`. There is no C# struct to lower from,
and re-wrapping it would only force callers into a more verbose
`new Color(ColorKt.Color(...))` style for no benefit.

## Generator changes

- New `ComposeValueTypes` registry keyed on full C# type name, with
  per-entry JNI slot character and lowering template.
- `EmitUserArgValue` has a value-type branch; auto-default-mask
  recognizes value types and `IntPtr?` (mirroring `IModifier?`); when
  the user passes a non-null value the matching `$default` bit is
  cleared.
- `NeedsKeepAlive` skips recognized value types (no `IJavaPeerable`
  peer to keep alive).
- New **CN2007** diagnostic - recognized value type on a no-`$default`
  bridge fails fast (auto-mask only fires when there's a bit to
  clear).

## Value type files

- `Dp`, `Sp`, `Em`, `TextAlign` -- `readonly record struct` wrappers
  with `Pack(T?)` static helpers. Kotlin `@JvmInline value class` so
  the binder will never surface them as value types regardless of
  un-stripping.
- `FontWeight`, `TextDecoration`, `Shape` -- `sealed class :
  Java.Lang.Object` with JNI-resolved companion statics / factories,
  designed to swap to bound types once dotnet/android-libraries#1439
  ships and the Compose UI Text/Graphics text packages stop being
  Java-library-only stubs. These use the existing reference-type
  lowering path, not the value-type registry.

No existing bridges or facades are converted in this PR -- the
infrastructure is staged so the next batch of bridges (`Text` colors,
font sizes, padding, etc.) can use typed parameters straight away.

## Tests

Four new generator tests cover Dp on a non-`@Composable` extension
shape, Sp/Em/TextAlign on a `@Composable` shape, FontWeight on the
existing reference-type path, and the CN2007 fail-fast. All 53
generator tests pass; `ComposeNet.Compose`, `ComposeNet.Sample`, and
`samples/Jetchat` all build clean.

Closes #65

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