SwingRecomposer

What a composition is driven by: a single Recomposer, the frame clock it recomposes on, and the CoroutineScope they run on. Every content composition nested into one of these recomposes on one recomposer and one frame clock.

Frame-driven work is cadenced to the display the component this was created for is on, and follows that component across displays: a component reports every java.awt.GraphicsConfiguration change, including the ones an ancestor propagates down to it.

Content is mounted on it by passing its compositionContext as the parent of a content composition.

It holds a live coroutine scope and a Swing timer, so it has to be disposed. A caller handed one by create owns it and decides when it ends; the one a window is given is this library's own and ends itself once nothing composes under it any more.

A failure ends it too. The runtime records the first throw and recomposes nothing after it - from a recomposition pass, from content's first composition, or from an effect the content launched - so this is disposed when it happens. A pass or an effect that throws is reported through the thread's uncaught-exception handler once, except a cancellation, which ends this unreported; a first composition's throw reaches whoever composed it. That throw shuts this down before it reaches them, and this is disposed on a later turn of its dispatcher, once the effects running under it have finished cancelling. In between, content that names this as its parent is refused, and content a window sets under it composes once and is torn down with the rest. The shutdown cancels the effects under this as Recomposer.cancel does, so a completion handler on a job under this runs inside the call that composed.

While the Compose runtime's hot reload is enabled, an error in composing content or in applying its changes does not end this and is reported to nobody. A later reload recovers it: a composition error on the next reload of the code, any other apply error only on a reload that saves state. A failing effect and an error the runtime raises for its own broken invariants end this as they do without hot reload.

Marked InternalSwingUiApi; it may change without notice in any release.

Types

Link copied to clipboard
object Companion

Creates what a component's composition is driven by.

Properties

Link copied to clipboard
val compositionContext: CompositionContext

The context to pass as the parent of a content composition this recomposer drives.

Functions

Link copied to clipboard
fun dispose()

Disposes the content compositions registered as composing under this recomposer, then cancels the recomposer, disposes the clock - which is what withdraws it from EventDispatchHook - and cancels the scope they run on. Every step is attempted even when an earlier one throws; the first failure propagates, with the later ones suppressed on it. Idempotent.