Skip to content

Add Modifier support (Phase 1: Padding + FillMax*) - #23

Merged
jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers/modifier-support
Jun 3, 2026
Merged

jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers/modifier-support

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Owner

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).

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:

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:

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).

Copilot AI review requested due to automatic review settings June 3, 2026 20:33

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

Adds first-phase support for Jetpack Compose Modifier to the C# facade by introducing a fluent, immutable ComposeNet.Modifier chain and threading an optional modifier through the facade composables and their JNI bridges. This unblocks basic layout styling (padding and fillMax*) and updates the sample to restore the content gutter regression introduced in #19.

Changes:

  • Introduces ComposeNet.Modifier (Padding + FillMax*) and runtime materialization via JNI at render time.
  • Plumbs an optional Modifier through ComposableNode and most public composables/bridges, including $default bitmask handling when a modifier is provided.
  • Updates the sample to apply Modifier.Companion.Padding(16) to the Scaffold body root Column.

Reviewed changes

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

Show a summary per file
File Description
src/ComposeNet.Sample/MainActivity.cs Applies padding modifier to restore sample UI gutter in Scaffold body.
src/ComposeNet.Compose/Tooltip.cs Builds/passes modifier and updates default-bitmask handling for TooltipBox.
src/ComposeNet.Compose/TimePickerDialog.cs Builds/passes modifier and clears modifier bit in defaults when present.
src/ComposeNet.Compose/TimePicker.cs Adds modifier support to TimePicker bridge invocation and defaults mask.
src/ComposeNet.Compose/TextField.cs Passes built modifier through to the TextField JNI bridge.
src/ComposeNet.Compose/Text.cs Passes built modifier through to the Text JNI bridge.
src/ComposeNet.Compose/Surface.cs Passes built modifier through to the Surface JNI bridge.
src/ComposeNet.Compose/SuggestionChip.cs Adds modifier parameter/default-bit handling for SuggestionChip.
src/ComposeNet.Compose/Scaffold.cs Adds modifier support and defaults-bit handling for Scaffold.
src/ComposeNet.Compose/OutlinedTextField.cs Passes built modifier through to the OutlinedTextField JNI bridge.
src/ComposeNet.Compose/NavigationRailItem.cs Adds modifier parameter/default-bit handling for NavigationRailItem.
src/ComposeNet.Compose/NavigationRail.cs Passes built modifier through to the NavigationRail JNI bridge.
src/ComposeNet.Compose/NavigationBarItem.cs Adds modifier parameter/default-bit handling for NavigationBarItem.
src/ComposeNet.Compose/NavigationBar.cs Passes built modifier through to the NavigationBar JNI bridge.
src/ComposeNet.Compose/Modifier.cs New fluent modifier chain type + render-time JNI materialization.
src/ComposeNet.Compose/ModalBottomSheet.cs Adds modifier support and defaults-bit handling for ModalBottomSheet.
src/ComposeNet.Compose/InputChip.cs Adds modifier parameter/default-bit handling for InputChip.
src/ComposeNet.Compose/IconButton.cs Passes built modifier through to the IconButton JNI bridge.
src/ComposeNet.Compose/FloatingActionButton.cs Passes built modifier through to the FAB JNI bridge.
src/ComposeNet.Compose/FilterChip.cs Adds modifier parameter/default-bit handling for FilterChip.
src/ComposeNet.Compose/DatePickerDialog.cs Adds modifier support and defaults-bit handling for DatePickerDialog.
src/ComposeNet.Compose/DatePicker.cs Adds modifier support for DatePicker bridge invocation and defaults mask.
src/ComposeNet.Compose/ComposeBridges.cs Adds modifier building helpers + threads IModifier? through many JNI bridges and updates $default masks accordingly.
src/ComposeNet.Compose/ComposableNode.cs Adds Modifier property and BuildModifier() helper for render-time materialization.
src/ComposeNet.Compose/ComposableContainer.cs Adds Add(Modifier) overload to allow setting modifier in collection initializers.
src/ComposeNet.Compose/Column.cs Passes modifier through to bound ColumnKt.Column and updates default-bitmask handling.
src/ComposeNet.Compose/Card.cs Passes built modifier through to the Card JNI bridge.
src/ComposeNet.Compose/Button.cs Passes built modifier through to the Button JNI bridge.
src/ComposeNet.Compose/BottomSheetScaffold.cs Adds modifier support and defaults-bit handling for BottomSheetScaffold.
src/ComposeNet.Compose/AssistChip.cs Adds modifier parameter/default-bit handling for AssistChip.
src/ComposeNet.Compose/AlertDialog.cs Adds modifier support and defaults-bit handling for AlertDialog.

Comment thread src/ComposeNet.Compose/Modifier.cs Resolved
Comment thread src/ComposeNet.Compose/Modifier.cs Resolved
jonathanpeppers and others added 2 commits June 3, 2026 15:54
Implements issue #21 Phase 1: a Modifier C# builder mirroring Kotlin's chained Modifier.foo().bar() API, threaded through every public composable.

Co-authored-by: Copilot <[email protected]>
@jonathanpeppers
jonathanpeppers force-pushed the jonathanpeppers/modifier-support branch from 5b73c48 to 44e06db Compare June 3, 2026 20:55
@jonathanpeppers
jonathanpeppers merged commit d934a41 into main Jun 3, 2026
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers/modifier-support 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.

Add Modifier support to the C# facade (Padding, FillMax*, Size, Background, …)

2 participants