Skip to content

11.3.0

Latest

Choose a tag to compare

@albyrock87 albyrock87 released this 19 Sep 10:47
· 3 commits to main since this release
336ee2a

Nalu.Maui 11.3.0

This release ships a brand-new package, Nalu.Maui.LiveActivities, bringing iOS Live Activities and
Android 16 Live Updates to MAUI from a single C# content model, and Magnet 2.0: a full rewrite of the
constraint layout around a compiled constraint engine that replaces the Cassowary solver. Alongside those:
the Scaffold nav bar now renders the page's standard ToolbarItems, VirtualScroll's automatic ItemsSource
wrapping is AOT-compatible, and the iOS background HTTP handler received a round of hardening backed by a new
fault-injection harness that runs on the simulator and on a physical iPhone.

⚠️ Magnet 2.0 is a breaking change for Nalu.Maui.Layouts: XAML written for Magnet 1.x does not
compile against 2.0. The migration guide
maps every 1.x concept to its 2.0 counterpart. See the "Breaking changes" section at the end.


📣 New package: Nalu.Maui.LiveActivities

Your app's live, glanceable state on the system surfaces of both platforms from one API (#207, #211, #219, #222):

  • iOS: a real ActivityKit Live Activity (Lock Screen banner, Dynamic Island compact chip and expanded
    card), rendered by a WidgetKit extension the package builds and embeds automatically: you write no Swift and
    never open Xcode. Declare NSSupportsLiveActivities in Info.plist and you are done; forget it and the build
    fails with NALU001 telling you exactly what to add, so the mistake can never reach ActivityKit's cryptic
    runtime error. Bespoke SwiftUI is one property away (NaluLiveActivitiesWidgetProject) when the bundled
    widget is not enough.
  • Android 16 QPR1+: a Live Update, the promoted ongoing notification with the status-bar chip and the
    floating card, using the API 36.1 ProgressStyle (segments, milestone points, tracker icon). Android 8 through
    base Android 16 degrade gracefully to a plain ongoing notification with a classic progress bar and a native
    chronometer (Support == Degraded, opt-out via DisableAndroidFallback). Both notification permissions are
    merged into your manifest by the package; RequestPermissionAsync() triggers the runtime prompt.

The design principle is a semantic content model: you describe what the activity says (title, subtitle,
chip text, accent color, stepped progress, an OS-ticked timer, action buttons, a free-form Custom bag) and each
platform renders it natively in its own visual language.

builder.UseNaluLiveActivities(live => live.AddKind("delivery", "Order tracking"));

var activity = await liveActivities.StartAsync("delivery", new LiveActivityContent
{
    Title = "Pizza on the way",
    ChipText = "12 min",
    Progress = new LiveActivityProgress { Value = 0.4 },
    Timer = LiveActivityTimer.CountDown(order.Eta),
});

await activity.UpdateAsync(c => c.Progress!.Value = 0.8);
await activity.EndAsync(c => { c.Title = "Delivered"; c.Timer = null; });

API shape

  • ILiveActivityManager (Support, RequestPermissionAsync, StartAsync, Activities) resolved from DI; on
    Unavailable surfaces (iOS < 16.2, Mac Catalyst, Windows) StartAsync returns an inert handle and every call is
    a no-op, so app code is never platform-branched.
  • The ILiveActivity handle is write-mostly: every mutation is a synchronous patch lambda run on a deep-cloned
    draft under the handle's lock. A patch producing identical content is skipped entirely (both OSes budget
    updates). Updates are silent unless you pass a LiveActivityAlert. EndAsync keeps the final content visible
    by default on both platforms (Android converts it to a swipeable notification), or removes it with
    LiveActivityDismissal.Immediate.
  • The user can always take it away, and the library honours it: LiveActivityState.Dismissed plus an
    ILiveActivity.Dismissed event on both platforms. After a dismissal UpdateAsync becomes a silent no-op (so a
    progress loop keeps running unchanged) and EndAsync seals the handle without reposting what was swiped away.
  • Activities outlive your app: running activities are rehydrated into Activities after process death on
    both platforms, from ActivityKit state on iOS and from the notification extras on Android.
  • Timers: CountDown / CountUp ticked by the OS. LiveActivityContent.SubtitleOverflow sets the wording
    shown once a countdown passes its end (a plain count-up takes over); when null the overflow shows as a negative
    duration. On iOS every ticking mode renders through Text(timerInterval:) for correct Lock Screen and
    Always-On display fidelity.
  • Action and content taps on Android now reliably bring the app to the front (CLEAR_TOP | SINGLE_TOP; the
    previous NEW_TASK-only intent frequently delivered to onNewIntent without reordering the task).

Measured on device, so you don't have to

  • A StaleAt already in the past makes ActivityKit create the activity directly in the stale state, and a stale
    activity is never presented. The package drops such a date instead of forwarding it, which the documented
    appointment pattern would otherwise hit the moment the countdown end goes by.
  • iOS ends any Live Activity after about 8 hours, and the Dynamic Island needs an iPhone 14 Pro or later
    (notch devices only show the Lock Screen banner). Both are documented, with the reproduction that chased a
    "does not show up for timers longer than 24h" report to those two causes.

Docs: Live Activities,
Timers,
Examples.

🧲 Magnet 2.0 (Nalu.Maui.Layouts)

A full rewrite of the constraint layout (#209, #210, #212, #213, #214, #215, #216, #217, #220, #221). The
Cassowary solver and the 1.x element model are gone.

Engine

  • A pure compiler (id table, per-axis dependency graphs, cycle detection with readable error paths, a
    topologically sorted instruction tape) and an allocation-free executor that resolves the content hug in
    closed form: no solver iterations, zero allocations per measure/arrange.
  • Compiled tapes are pure and shared through a process-wide LRU cache keyed by the structure of the definition,
    so template-instantiated cells compile once (Magnet.CompilationCacheCapacity, default 64).
  • Steady-state work was then trimmed further: fused chain runtime ops (a Gap on a chain went from +22% to
    +3.5%), child measures deferred to arrange when only the child needs them, and a delta arrange that replays
    the measure's affine solution at the arrange size instead of re-executing the tape.
  • Every arrange in the unit suite is cross-checked against an unconditional full re-solve by a differential
    verification harness (885/885), plus dedicated tests for the arrange-vs-measure boundaries.

Public API

  • MagnetDefinition with MagnetView, MagnetBarrier, MagnetGuideline and MagnetChain nodes, all in the
    Nalu namespace, every node identified by a mandatory MagnetId.
  • Constraints are written directly on the child view through attached properties
    (nalu:Magnet.LeftTo="avatar.Right,12", nalu:Magnet.TopTo="parent.Top"), with MagnetAnchor carrying the
    per-anchor margin and GONE margin ("a.Right,12,gone:0"), WidthSizing/HeightSizing ("48", "*",
    "50%", {nalu:MagnetSizing 1.5, Unit=Ratio}, Min/Max), biases, and the After/Below/Align*/
    Within/Fill* shortcuts. A fluent C# builder covers the same surface. MagnetId propagates to
    AutomationId (opt-out).
  • Explicit chains (Spread/SpreadInside/Packed, weights, gap modes, measured members shrink to leave room),
    barriers, guidelines, StagePercent/Ratio/Measured sizing with bounded cross-axis feedback for ratios.
    Nodes/Weights accept comma-separated attributes (Nodes="a,b") as well as element content.
  • Transitions: TransitionToAsync animates value changes (input-interpolated) and structural changes
    (frame-interpolated), with retargeting when a new transition lands mid-flight.
  • Scenes: MagnetView.ApplyVisibility (None/Show/Hide) declares a one-shot visibility action stamped
    onto the bound view's IsVisible when the definition is applied. Inside a transition a Hide freezes the view
    in place and fades it out while siblings animate to the collapsed layout; Show fades in. Scenes have no
    layout impact: definitions differing only in visibility actions share the same compiled tape, and a scene can
    be toggled on a single definition without swapping it.
  • Shareable definitions: a MagnetDefinition is a pure declaration that any number of Magnet layouts can
    attach to (an app-wide resource, a template shared by every cell). All per-layout state lives in the layout;
    mutating a shared definition reaches every subscriber. Sharing one definition across cells trims per-cell
    inflation allocations by 15%.
  • Nodes and the definition are plain INotifyPropertyChanged objects, no longer BindableObjects:
    −69% bytes per inflation on a typical 7-node graph, and node property access is plain field access. They stay
    valid binding sources; they were never reachable binding targets since they live outside the visual tree.

Performance (from the docs)

Managed algorithm only, Apple M-series: a full relayout costs 1.2–1.3× a trivial nested Grid with 3–4.7× fewer
allocations, and the flat Magnet card inflates faster than the three nested layouts it replaces. On device the
flat hierarchy wins every scenario, because every layout Magnet flattens away is a native view MAUI no longer
has to create, map and traverse:

200 cards, warm run iPhone simulator Android emulator (arm64)
Inflate → settled Grid 1600 ms · Magnet 1352 ms (−16%) Grid 1999 ms · Magnet 1219 ms (−39%)
Text change on every card → settled Grid 253 ms · Magnet 185 ms (−27%) Grid 390 ms · Magnet 102 ms (−74%)

Docs: the Magnet page is rewritten, the 1.x → 2.0 migration guide
maps every concept, and Magnet by example
walks through twelve everyday layouts (login form, list rows, toolbars, barriers, chains, weights, ratio,
guidelines, visibility, packed + measured, vertical centering, gap modes under collapse) with screenshots
rendered by the real library on the iOS simulator.

🏛️ Scaffold

Toolbar items in the default nav bar (#225, closes #224)

The default bar now renders the page's standard MAUI ToolbarItems: nothing to migrate, nothing to bind.

<ContentPage.ToolbarItems>
    <ToolbarItem Text="Save" Command="{Binding SaveCommand}" />
    <ToolbarItem Text="Share" Priority="1" IconImageSource="{FontImageSource FontFamily=Material, Glyph=&#xe80d;}" />
    <ToolbarItem Text="Settings" Order="Secondary" Clicked="OnSettingsClicked" />
</ContentPage.ToolbarItems>
  • Native toolbar semantics, identical on iOS and Android: primary items become buttons in the trailing slot by
    Priority, as many as fit, the rest and the secondary items fold behind a ⋮ overflow menu.
  • The title folds items before it truncates: the bar reserves the title's natural width (never less than
    MinimumTitleWidth, 96 by default) and offers the items what is left. Set KeepTitleWhole="False" on
    ScaffoldNavBarView to prefer the items instead. A TitleView is treated the same way, by its natural width.
  • The collection is live: items added, removed, reordered or re-prioritized after the page is shown are
    reflected at once (MAUI's native toolbars ignore such changes). A tap runs Command and raises Clicked;
    disabled items (or a command whose CanExecute is false) are dimmed and inert.
  • Font icons declared without a Color are tinted with the effective NavBarForeground, so they recolor with
    the bar over a photo header, through a scroll-driven ramp and across themes. The overflow menu is a floating
    panel and follows the app theme instead unless styled.
  • New public, styleable primitives: ScaffoldToolbarItemsView, ScaffoldToolbarItemButton,
    ScaffoldToolbarOverflowButton, ScaffoldToolbarOverflowView; ScaffoldNavBarContext.ToolbarItems exposes
    the items to fully custom bars. An item's AutomationId lands on the button or menu row rendered for it.

Fixes

  • Reopening a start-edge flyout while its previous presentation still owned the content view crashed on iOS with
    UIViewControllerHierarchyInconsistency. Overlays are now torn down before the owner callbacks run
    (open-state properties, closed events), on both platforms, so a reopen issued from those callbacks, or a
    callback that throws, can no longer tie a native view to a retired controller.
  • Presenter disposal (handler disconnection) now discards every open overlay without animation and runs each
    owner cleanup: a drawer open at disconnect time is no longer left "open" forever, and pending popup / bottom
    sheet handles complete.

📜 VirtualScroll

  • AOT-compatible ItemsSource auto-wrapping. Automatic adapter creation no longer relies on
    MakeGenericType / Activator.CreateInstance, so the NotSupportedException under AOT is gone and JIT and
    AOT share one code path. Any mutable IList implementing INotifyCollectionChanged now coerces to a
    reorderable adapter; read-only lists such as ReadOnlyObservableCollection<T> get a change-tracking one.
    Drag-and-drop over an auto-wrapped list is a binding away, and the Adapter property now raises
    PropertyChanged when ItemsSource changes, so the binding follows collection replacement:

    <vs:VirtualScroll ItemsSource="{Binding Items}"
                      DragHandler="{Binding Adapter, Source={RelativeSource Self}, x:DataType=vs:VirtualScroll}" />

    A drag reorder uses ObservableCollection<T>.Move when available (other subscribers see a single Move
    notification) and falls back to RemoveAt + Insert for other lists.

  • Fix (iOS): a burst of inserts right after the page appeared, before UICollectionView had loaded its
    initial content, died in UIKit's invalid-batch-updates assertion. Incremental updates issued before the first
    laid-out data load, or after a data source swap, now go through a full reload instead.

  • Fix (Android): a potential crash with a drag handler attached: the ItemTouchHelper is now detached before
    its callback is disposed (detaching fires clearView on a still-recovering dragged item), and swapping the
    drag handler no longer leaves the previous helper attached.

  • Trimming: the reflective Move lookup is suppressed for both the net9 (IL2070) and net10 (IL2075)
    analyzers; it already had a RemoveAt + Insert fallback when trimming removed the method.

🌐 Core: iOS background HTTP (NSUrlBackgroundSessionHttpMessageHandler)

  • Fix: crashes at startup on background launches. A managed exception escaping an Objective-C delegate
    callback aborts the process (SIGABRT) and orphans every queued background-session event; seen in the field
    when session callbacks arrive before the DI container is built. Every delegate callback is now guarded, and a
    failure faults the pending request instead of the process.
  • Duplicate identifiers attach. A second SendAsync carrying an X-NSUrlRequest-Identifier already in
    flight no longer orphans the first awaiter forever: it attaches to the pending transfer and returns its
    response, and its CancellationToken cancels only its own wait. Once the request completes the identifier is
    free again.
  • DefaultTimeout is now actually enforced. iOS ignores the per-request native timeout on background
    sessions (verified on device: a 3 s value against a stalled server never fires), so the timeout is enforced
    managed-side and surfaces as a TaskCanceledException wrapping a TimeoutException, the HttpClient.Timeout
    convention. It ticks only while the app is alive; a transfer surviving a process kill is governed by the
    session's resource timeout.
  • Orphaned .nsrequest / .nsresponse / .nsdownload files left by a previous process (a kill during the
    acknowledge window) are swept at delegate init; a staged download no longer leaks when deferred processing
    throws; the request body file name is sanitized like the response path.
  • NSURLError codes map to HttpRequestException.HttpRequestError, matching SocketsHttpHandler.
  • All of this is backed by a new fault-injection harness: a raw-socket chaos server (truncation, RST,
    garbage, stalls, drips, redirect loops), callback-injection scenarios that drive every delegate branch with
    fake tasks, and app-lifecycle tests (backgrounding, SIGKILL + relaunch, mid-flight kills), green on the
    simulator and on a physical iPhone. The semantics it proved are now documented: background sessions silently
    retry connection faults until the resource timeout, garbage bytes surface as an HTTP/0.9 200, only redirect
    loops fail fast, and uploads killed mid-body still complete.

🏗️ Build, CI and docs

  • CI is restructured into per-platform builds (Android on Linux, iOS + Mac Catalyst on macOS, Windows on
    Windows) whose partial packages are merged at the package level; the unit suite runs first on Linux with no
    MAUI workloads and the docs site is published only on release (#206).
  • Every library single-targets to plain net10.0 on Linux (-p:AllTargetFrameworks=net10.0), which is how the
    unit suite runs in agent containers.
  • Docs: three new Live Activities pages; the Magnet rewrite with examples gallery, migration guide and
    regenerated performance tables; a "Toolbar items" section on the Scaffold nav bar page; VirtualScroll pages no
    longer carry the AOT caveat; the Core page documents the identifier-attach semantics.

⚠️ Breaking changes

Magnet 2.0 (Nalu.Maui.Layouts): XAML and C# written for Magnet 1.x do not compile. The
migration guide has the full table; in short:

  • Nalu.MagnetLayout.* types are gone: MagnetStage → MagnetDefinition (Magnet.Stage → Magnet.Definition),
    HorizontalBarrier/VerticalBarrier → MagnetBarrier, HorizontalGuideline/VerticalGuideline →
    MagnetGuideline, implicit chains → an explicit MagnetChain node.
  • Magnet.StageId → Magnet.MagnetId (mandatory, unique, no auto-generated ids); the "Stage" id → "parent".
  • HorizontalPullTarget/VerticalPullTarget → MagnetAnchor; no ! traction; Margin/CollapsedMargin on
    the element → per-anchor margin and gone: margin.
  • Width/Height (SizeValue) → WidthSizing/HeightSizing (MagnetSizing): a bare number is now a
    fixed size (1.x: a measured coefficient) and "50%" is now 50% of the span between the view's anchors
    (1.x: of the stage); use Unit=Measured / Unit=StagePercent for the old meanings.
  • Collapsed is gone: visibility is read from the bound view's IsVisible.
  • Nodes are no longer BindableObjects: the *Property statics are gone and Style/Setter/Trigger/
    SetBinding on nodes are no longer possible.
  • Semantics changed on purpose: measure hugs the content, a collapsed view drops its own margins, barriers ignore
    collapsed members, guideline Position adds to Percent, and a Ratio width fed by a */% height resolves
    with a single cross-axis feedback iteration.

NSUrlBackgroundSessionHttpMessageHandler.DefaultTimeout (Nalu.Maui.Core, iOS): previously forwarded to
a native timeout that background sessions ignore, so it never fired. It now fires, as a TaskCanceledException
wrapping a TimeoutException. Raise it, or clear it, for transfers that legitimately outlive the default.

👨🏼‍💻 Contributors

@albyrock87 and @claude