Skip to content

Bind Scaffold and use it in the sample - #19

Merged
jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers/bind-scaffold
Jun 3, 2026
Merged

jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers/bind-scaffold

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Owner

Closes #12.

What

Binds androidx.compose.material3.ScaffoldKt.Scaffold using the slot-property facade pattern established by AlertDialog (#6).

The Kotlin overload is stripped from the binding because floatingActionButtonPosition (FabPosition), containerColor, and contentColor (Color) are @JvmInline value class parameters, so we call it via a JNI bridge in ComposeBridges.cs. Verified the mangled name against androidx.compose.material3.material3-android 1.4.0.3 with javap — it's Scaffold-TvnljyQ (10 user params, single $changed, then $default).

New API

new Scaffold
{
    TopBar    = new Text("My App"),     // optional
    BottomBar = new NavigationBar { ... }, // optional
    SnackbarHost         = ...,         // optional
    FloatingActionButton = ...,         // optional
    Body = tabContent,                  // required
}

Sample fix

MainActivity.cs now wraps the per-tab content + overlays in a Scaffold, moving the NavigationBar from the bottom of an inline Column into the BottomBar slot so it pins to the bottom edge of the screen (above the system nav bar) instead of floating mid-screen.

Files

  • src/ComposeNet.Compose/Scaffold.cs — new facade.
  • src/ComposeNet.Compose/ComposeBridges.cs — Scaffold-TvnljyQ JNI bridge with GC.KeepAlive on every managed param.
  • src/ComposeNet.Compose/ComposeDefaults.cs — declarative [ComposeDefaults("ScaffoldDefault", ...)] attribute (10 bits, only content marked !).
  • src/ComposeNet.Sample/MainActivity.cs — uses Scaffold instead of a tail-positioned NavigationBar.

Verification

  • dotnet build src/ComposeNet.Compose ✅ (no new warnings)
  • dotnet build src/ComposeNet.Sample ✅
  • dotnet test src/ComposeNet.SourceGenerators.Tests ✅ (10/10 pass — ScaffoldDefault is generated from the declarative attribute)

Adds a Material 3 Scaffold composable using the same slot-property facade pattern as AlertDialog. The Kotlin overload is stripped from the binding because FabPosition / containerColor / contentColor are @JvmInline value class params, so we call it via JNI against Scaffold-TvnljyQ.

Updates the sample to wrap per-tab content in a Scaffold with NavigationBar moved to the BottomBar slot, so the bottom bar is pinned to the bottom of the screen instead of flowing inline.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings June 3, 2026 19:40

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 adds a C# facade for Material 3 Scaffold (following the slot-property pattern used elsewhere in ComposeNet.Compose) and updates the sample app layout to use it so the bottom navigation is pinned correctly.

Changes:

  • Introduces a new Scaffold composable facade with named slot properties (TopBar, BottomBar, SnackbarHost, FloatingActionButton, Body).
  • Adds a raw JNI bridge for the mangled Scaffold overload and a declarative $default bitmask definition.
  • Updates the sample MainActivity to wrap per-tab content in Scaffold and move the NavigationBar into the BottomBar slot.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/ComposeNet.Sample/MainActivity.cs Switches the sample layout to use Scaffold so the bottom navigation is pinned via BottomBar.
src/ComposeNet.Compose/Scaffold.cs Adds the new Scaffold facade type using the slot-property pattern and $default toggling.
src/ComposeNet.Compose/ComposeDefaults.cs Registers ScaffoldDefault via declarative ComposeDefaults for $default bitmask generation.
src/ComposeNet.Compose/ComposeBridges.cs Adds a raw JNI bridge for the stripped Scaffold overload.

Comment thread src/ComposeNet.Compose/Scaffold.cs Resolved
…een edges

Refs #20 for the long-term edge-to-edge plan.

Co-authored-by: Copilot <[email protected]>
@jonathanpeppers
jonathanpeppers merged commit 2db3060 into main Jun 3, 2026
jonathanpeppers added a commit that referenced this pull request Jun 3, 2026
Implements Phase 1 of #21.

## What

Introduces a C# `Modifier` builder that mirrors Kotlin's chained `Modifier.foo().bar()` API and threads through every public composable in the facade. With this PR users can finally style layout — starting with the padding/fill ops needed to fix the regression from #19 (tab content flush against the screen edges).

```csharp
new Column
{
    Modifier.Companion.Padding(16),       // <-- new in this PR
    new Text("Hello"),
}
```

## API

- New `ComposeNet.Modifier` type with `Companion`, `Padding(int)`, `Padding(int h, int v)`, `Padding(int l, int t, int r, int b)`, `FillMaxWidth(float = 1f)`, `FillMaxHeight(float = 1f)`, `FillMaxSize(float = 1f)`. Each op returns a new immutable `Modifier` so the chain is reusable.
- `internal IModifier? Build()` materializes the chain at `Render` time via JNI: `Modifier.Companion.$$INSTANCE` resolved via `JNIEnv.GetStaticFieldID`, then each op invokes the matching Kotlin static (`PaddingKt.padding-3ABfNKs/-VpY3zN4/-qDBjuR0`, `SizeKt.fillMaxWidth/Height/Size`).
- `ComposableNode.Modifier { get; set; }` — every composable accepts an optional modifier.

## Setting `Modifier` on containers vs. leaves

C# disallows mixing object-init assignments with collection-init items in the same `{ }`. Leaves (Text, Button, …) keep object-init syntax:

```csharp
new Text("Hi") { Modifier = Modifier.Companion.Padding(8) }
```

For containers that derive from `ComposableContainer` (Column, Card, Surface, Scaffold, …) I added an `Add(Modifier)` overload so the modifier is set inline alongside children — the canonical C# trick for this situation:

```csharp
new Column { Modifier.Companion.Padding(16), child1, child2 }
```

## Wiring

- `ComposeBridges.cs`: added `ModifierHandle` / `ModifierCompanionInstance` / `ModifierPadding{All,HV,LTRB}` / `ModifierFillMax{Width,Height,Size}` JNI helpers, and threaded an `IModifier? modifier` parameter through every existing bridge (Text, Button, IconButton, FAB, Surface, Card, TextField/OutlinedTextField, AlertDialog, ModalBottomSheet, BottomSheetScaffold, Scaffold, DatePicker(Dialog), TimePicker(Dialog), Tooltip, *Chip, NavigationBar(Item), NavigationRail(Item)).
- Each composable's `Render` now calls `BuildModifier()` and clears the `Modifier` bit in its `$default` mask when the user supplied one.
- `Column` uses the bound `ColumnKt.Column` directly (no JNI bridge), so it just passes the modifier through.

## Sample

`MainActivity.cs` adds `Modifier.Companion.Padding(16)` to the Scaffold body's root `Column`, restoring the horizontal gutter that was dropped in #19 while leaving the BottomBar flush against the edges.

## Phase 2+ (out of scope)

`Background`, `Border`, `Clip`, `Clickable`, gestures, size constraints, window-insets — to follow as separate issues / PRs.

## Verification

- `dotnet test src/ComposeNet.SourceGenerators.Tests` — 10/10 passing.
- `dotnet build src/ComposeNet.Compose` — clean.
- `dotnet build src/ComposeNet.Sample` — clean.

Closes #21 (Phase 1).

Co-authored-by: Copilot <[email protected]>
jonathanpeppers added a commit that referenced this pull request Jun 3, 2026
Closes #20.

The pre-AndroidX status-bar / action-bar shim in `ComposeActivity` had outlived its purpose: `ApplySafeAreaPadding` hand-computed pixels via `Resources.GetIdentifier("status_bar_height", "dimen", "android")` and pushed them onto the root `ComposeView`, while `ApplyLightStatusBar` toggled `WindowInsetsController` flags imperatively. That worked for bare-`Column` roots, but once #19 introduced `Scaffold` it started fighting Compose's own inset handling, and the resource trick never accounted for foldables, cutouts, or gesture nav anyway.

This PR moves to the canonical Compose edge-to-edge setup:

- `ComposeActivity.OnCreate` now calls `EdgeToEdge.Enable(this)` before `base.OnCreate`, which is the order the AndroidX API expects. System bars become transparent overlays, and Compose's `WindowInsets` propagation drives padding from there.
- `ApplySafeAreaPadding`, `ApplyLightStatusBar`, and the `ActionBarHeight` / `Dp` / `SystemBarHeight` helpers (and their calls in `SetContent`) are deleted.
- The sample's `MainActivity` switches from `Theme.Material.Light` to `Theme.Material.Light.NoActionBar`, so no framework `ActionBar` overlays the content. (No new NuGet dependency: a framework `NoActionBar` theme is enough for our purposes since `MaterialTheme` does the real Material 3 theming inside the composition.)
- Two new modifiers, `Modifier.SafeDrawingPadding()` and `Modifier.SystemBarsPadding()`, bridge to `WindowInsetsPadding_androidKt` so callers can pad bare-`Column` roots, or `Scaffold` bodies that don't have a `TopBar`. The sample applies `SafeDrawingPadding()` on the `Scaffold` body for exactly that reason — the bottom `NavigationBar` continues to handle its own gesture-bar inset via the Material 3 default.

README is updated with the new sample snippet and the "Confirmed on device" bullet describing the edge-to-edge setup.

### Notes for reviewers

- Generator unit tests still pass (`dotnet test src/ComposeNet.SourceGenerators.Tests`, 10/10).
- Sample builds and deploys (`dotnet build src/ComposeNet.Sample -t:Run`); the framework "ComposeNet.Sample" title strip is gone, status bar is transparent over the body, and `NavigationBar` sits flush with the bottom edge.
- The two new modifier bridges follow the existing JNI pattern in `ComposeBridges.cs`. They could in principle call the bound `WindowInsetsPadding_androidKt.SafeDrawingPadding(IModifier)` directly, but keeping them on raw `IntPtr` matches how the rest of the modifier op-chain already works.

Co-authored-by: Copilot <[email protected]>
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers/bind-scaffold branch June 4, 2026 16:51
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.

Bind Scaffold and use it in the sample

2 participants