Skip to content

Migrate ComposeActivity to edge-to-edge / NoActionBar - #25

Merged
jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers/edge-to-edge-material3
Jun 3, 2026
Merged

jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers/edge-to-edge-material3

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Owner

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.

Replace the manual ApplySafeAreaPadding/ApplyLightStatusBar shims in ComposeActivity with EdgeToEdge.Enable(this) and a NoActionBar framework theme on the sample. The pre-AndroidX status_bar_height resource trick, the View.SetPadding hack, and the WindowInsetsController light-bars toggle all go away — Compose's WindowInsets propagation now drives inset handling end-to-end.

Add Modifier.SafeDrawingPadding() and Modifier.SystemBarsPadding() to the facade (bridges to WindowInsetsPadding_androidKt) so callers can pad bare Column / Scaffold-body roots for the safe area. The sample applies SafeDrawingPadding to the Scaffold body since there's no TopBar consuming the status bar inset.

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

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

Migrates the sample and shared ComposeActivity base class to an edge-to-edge window setup, removing the legacy framework-side inset/status-bar shims and relying on Compose WindowInsets + modifier-based padding instead.

Changes:

  • Enable edge-to-edge in ComposeActivity via EdgeToEdge.Enable(this) and delete the old manual padding + light-status-bar helpers.
  • Add Modifier.SafeDrawingPadding() and Modifier.SystemBarsPadding() bridges for inset-aware root/body padding under edge-to-edge.
  • Update the sample activity theme to Theme.Material.Light.NoActionBar and apply SafeDrawingPadding() to the Scaffold body content; refresh README guidance/snippets accordingly.

Reviewed changes

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

Show a summary per file
File Description
src/ComposeNet.Compose/ComposeActivity.cs Enables edge-to-edge in OnCreate and removes manual safe-area/status-bar handling; documents the new inset strategy.
src/ComposeNet.Compose/Modifier.cs Adds SafeDrawingPadding() and SystemBarsPadding() fluent modifier ops for consumer use.
src/ComposeNet.Compose/ComposeBridges.cs Introduces JNI bridges to WindowInsetsPadding_androidKt modifier functions.
src/ComposeNet.Sample/MainActivity.cs Switches to a NoActionBar theme and applies SafeDrawingPadding() within the Scaffold body.
README.md Updates “Confirmed on device” notes and sample code to reflect edge-to-edge + modifier-based inset padding.

@jonathanpeppers
jonathanpeppers merged commit b62894d into main Jun 3, 2026
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers/edge-to-edge-material3 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.

Move ComposeActivity to edge-to-edge / Material 3 and delete ApplySafeAreaPadding

2 participants