captureRemoteDocument
public fun captureRemoteDocument(
context: Context,
creationDisplayInfo: RemoteCreationDisplayInfo,
remoteDensity: RemoteDensity =
RemoteDensity(
creationDisplayInfo.density.density.rf,
creationDisplayInfo.density.fontScale.rf,
),
layoutDirection: LayoutDirection? = null,
writerEvents: WriterEvents = WriterEvents(),
clock: RemoteClock = RemoteClock.SYSTEM,
profile: Profile = RcPlatformProfiles.ANDROIDX,
coroutineContext: CoroutineContext = Dispatchers.Default,
content: @Composable @RemoteComposable () -> Unit,
): Flow<ByteArray>
Capture a stream of RemoteCompose documents by rendering the specified content Composable in a virtual display and emitting the resulting byte arrays whenever recomposition occurs and the layout visually changes.
This API allows capturing dynamic Compose content (e.g., containing animations, transitions, or state updates) as a Flow of serialized document byte arrays.
Crucially, recomposition is handled cleanly, and duplicate documents (where nothing visually changed in the layout tree) are automatically filtered out, so new byte arrays are only emitted when the document actually changes.
Remote documents are expected to change rarely; animate with remote expressions rather than recomposition. Content that updates faster than a few documents in quick succession followed by about one per second is throttled, and a warning is logged. The latest state is still emitted once the throttle allows.
Parameters
| context | The Android Context to use. |
| creationDisplayInfo | Details about the virtual display to capture for (size, density, etc.). |
| remoteDensity | The logical screen density and font scale to use for unit conversions. Defaults to density derived from creationDisplayInfo. Note: If passing custom values, they should typically match the density and font scale specified in creationDisplayInfo to avoid layout scaling discrepancies. |
| layoutDirection | The layout direction (LTR or RTL) to use. Defaults to the layout direction of context's configuration when null. |
| writerEvents | Callback to handle non-serializable events (e.g. pending intents). |
| clock | The clock used for the recomposer timeline. Defaults to RemoteClock.SYSTEM. |
| profile | The writing profile that determines supported operations. Defaults to RcPlatformProfiles.ANDROIDX. |
| coroutineContext | The CoroutineContext to run recomposition and rendering on. Defaults to Dispatchers.Default. |
| content | The Composable content to render and capture. |
Return
A Flow of ByteArrays containing the serialized RemoteCompose documents.