dotnet / dotnet/android-libraries

Compose Material3: TypographyKt.Typography(...) builder missing from binding (TextStyle inline-class mangling, related to java-interop#1440)

Open
#1,453 0 comments 0 reactions 0 assignees View on GitHub
area-androidx missing-api
Dominant language
C#
Stars
317
Forks
73
Avg merge
1d 8h
Merged PRs (30d)
17

Description

## Background

In `Xamarin.AndroidX.Compose.Material3Android` (verified against
`1.4.0.3`), the `TypographyKt` companion class only exposes the
`LocalTypography` CompositionLocal accessor — the public
`Typography(displayLarge, displayMedium, …, labelSmall)` builder
function is missing entirely:

```csharp
// AndroidX.Compose.Material3.TypographyKt (full method list)
get_class_ref() -> IntPtr
get_JniPeerMembers() -> JniPeerMembers
get_ThresholdClass() -> IntPtr
get_ThresholdType() -> Type
get_LocalTypography() -> ProvidableCompositionLocal
.ctor(IntPtr, JniHandleOwnership) -> Void
.cctor() -> Void
// ^ no Typography(...) builder
```

Upstream Kotlin (`androidx.compose.material3.TypographyKt`):

```kotlin
fun Typography(
displayLarge: TextStyle = TypographyTokens.DisplayLarge,
displayMedium: TextStyle = TypographyTokens.DisplayMedium,
displaySmall: TextStyle = TypographyTokens.DisplaySmall,
headlineLarge: TextStyle = TypographyTokens.HeadlineLarge,
...
labelSmall: TextStyle = TypographyTokens.LabelSmall,
): Typography
```

Every parameter is `androidx.compose.ui.text.TextStyle`, which is
itself a regular class but has constructors and `copy(...)` overloads
saturated with `@JvmInline value class` fields (`Color`, `TextUnit`,
`FontWeight`, `FontStyle`, `BaselineShift`, `TextGeometricTransform`,
…). That triggers the same JVM-mangling story documented in
[dotnet/java-interop#1440][interop] — the public `Typography` factory
in the bytecode is something like `Typography-…`, and the current
metadata pipeline strips it.

[interop]: https://github.com/dotnet/java-interop/pull/1440

The same package *does* expose:

- `MaterialThemeKt.MaterialTheme(ColorScheme, Shapes, Typography, …)`
- `MaterialTheme.GetTypography(IComposer, Int32)` companion accessor
- `new Typography()` parameterless ctor

— so the *type* `Typography` is fully bound and consumable; only the
**factory function** that lets you build a customized `Typography`
with the standard defaults is missing. This blocks
[jonathanpeppers/compose-net#61][cn61] (parameterizing
`MaterialTheme`).

[cn61]: https://github.com/jonathanpeppers/compose-net/issues/61

## Ask

Two paths, listed in order of preference:

1. **Long-term:** once [dotnet/java-interop#1440][interop] lands and
`@JvmInline value class` mangling is unwound at bind time, the
`Typography(...)` builder should reappear automatically. Track
this issue against that PR.

2. **Short-term workaround** (if waiting on #1440 is not viable):
add an explicit `managedName` rename in
`material3-android/Transforms/Metadata.xml` that aliases the
bytecode-mangled `Typography-…` static method back to a stable
managed name (`TypographyKt.Typography`), the same pattern used
for `Text--4IGK_g` → `Text` / `Button-bWB7cM8` → `Button` in
downstream metadata fixes.

## Verification

After the fix, this should compile (in either form):

```csharp
using AndroidX.Compose.Material3;
using AndroidX.Compose.UI.Text;

Typography typography = TypographyKt.Typography(
displayLarge: new TextStyle(fontSize: /* Sp */, fontWeight: /* … */),
/* … */);
```

## Related

- [#1438](https://github.com/dotnet/android-libraries/pull/1438) —
un-strip `ui-graphics-android` (precedent for the recipe)
- [#1439](https://github.com/dotnet/android-libraries/issues/1439) —
un-strip `ui-text-android` / `ui-unit-android` (precedent)
- [dotnet/java-interop#1440][interop] — root cause of inline-class
method-name mangling

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.