Surface Kotlin object companions on Compose class bindings via CompanionStatic rename#1468
Draft
Copilot wants to merge 4 commits into
Draft
Surface Kotlin object companions on Compose class bindings via CompanionStatic rename#1468Copilot wants to merge 4 commits into
Copilot wants to merge 4 commits into
Conversation
…ionStatic rename Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix Kotlin object companion field visibility on outer class binding
Surface Kotlin object companions on Compose class bindings
Jun 10, 2026
The previous commit enumerated 7 specific Kotlin companion classes by name
across foundation-android (1), ui-graphics-android (1), and ui-text-android
(5). That fixed those 7 but left 62 more classes with the same problem in
just these three packages: ScrollState.Companion, LazyListState.Companion,
BlendMode.Companion, Brush.Companion, Path.Companion, ImeAction.Companion,
TextRange.Companion, AnnotatedString.Companion, and many others were still
unreachable without raw JNI.
Replace the per-class entries with the same wildcard XPath that
kotlin-stdlib, okio-jvm, com.google.ai.edge.aicore, and com.google.mlkit
genai-prompt already use:
<attr path="/api/package/class[substring(@name,string-length(@name)-9)
='.Companion']"
name="managedName">CompanionStatic</attr>
This renames every nested *.Companion peer in the package to CompanionStatic,
letting the binding generator emit `public static <Outer>.CompanionStatic
Companion { get; }` on every outer class.
After this change:
foundation-android : 24 new static Companion accessors
ui-graphics-android: 35 new static Companion accessors
ui-text-android : 45 new static Companion accessors
---
104 total (vs. 7 in the previous revision)
Interface companions are unaffected — the binding generator hoists them to
top-level <Outer>Companion before this rename matches, so `Path.Companion`,
`ImageBitmap.Companion`, `DrawScope.Companion`, etc. surface correctly via
their hoisted peer.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
e4c6515 to
90d2610
Compare
# Conflicts: # source/androidx.compose.ui/ui-graphics-android/Transforms/Metadata.xml
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.
Fixes #1467.
Problem
When a Kotlin
classhas anobject Companion, the JVM emits two things on the outer class:<Outer>.Companionpublic static final Companion Companion;field that holds the singletonC# does not allow a nested type and a static member to share a name on the same class, so the binding generator silently drops the static field. Net effect: consumers can see the nested
Companiontype but cannot get an instance of it, leaving members likeColor.Companion.Red,BlendMode.Companion.Clear,KeyboardOptions.Companion.Default,TextStyle.Companion.Default,FontWeight.Companion.Bold,Brush.Companion.HorizontalGradient(...), etc. unreachable from C# (they're only available via raw JNI).Fix
Rename every
*.Companionnested peer toCompanionStaticvia a one-line wildcard XPath in the affected packages'Transforms/Metadata.xml:The collision is resolved at the type level so the consumer-facing property keeps its natural Kotlin/Java name. The generator now emits
public static <Outer>.CompanionStatic Companion { get; }on every outer class whose Kotlinobject Companionpeer was previously colliding:CompanionStaticonly appears as a return type in IntelliSense / decompiled signatures — it doesn't appear in normal call-site code.This is the same wildcard pattern (and the same
CompanionStaticrename) that this repo already uses inkotlin-stdlib,okio-jvm,aicore, andgenai-prompt.Interface companions are unaffected — the generator hoists those to top-level
<Outer>Companionbefore this rename matches.Packages updated
Companionaccessorsandroidx.compose.foundation/foundation-androidandroidx.compose.ui/ui-graphics-androidandroidx.compose.ui/ui-text-androidEach accessor returns the renamed
<Outer>.CompanionStaticpeer, so all of its members (constants, factory methods, savers, defaults) are reachable directly from C# via the natural<Outer>.Companion.Foosyntax.ui-graphics-androidbumps the NuGet revision to1.11.2.3(stacking on top of #1471's1.11.2.2);ui-graphics-android/Transforms/Metadata.xmlcarries both #1471'sSolidColor(long)constructor re-introduction and the new companion rename.Verification
net9.0-android35.0andnet10.0-android36.0.dotnet cake --target=metadata-verifypasses.PublicAPI.Unshipped.txtupdated for the three packages with the new staticCompanion.getaccessors plus the renamed nestedCompanionStatictypes and their members.main(picks up Bind stripped SolidColor(long) constructor in Compose UI.Graphics #1471) — both fixes coexist on ui-graphics-android.