collectAsViewComposePagingItems

fun <T : Any> Flow<PagingData<T>>.collectAsViewComposePagingItems(lifecyclePolicy: PagingLifecyclePolicy = PagingLifecyclePolicy.Visible, context: CoroutineContext = EmptyCoroutineContext): ViewComposePagingItems<T>(source)

Collects this AndroidX Paging stream into a remembered ViewCompose presentation owner.

Collection starts only after a successful composition commit. lifecyclePolicy controls Android lifecycle gating and retains the last coherent snapshot while inactive. Flow identity creates a new ViewComposePagingItems; changing only the policy or context serially restarts collection on the existing owner. Latest PagingData wins through collectLatest cancellation.

context may add a dispatcher, name, or other contextual element but cannot contain a Job. The composition owns cancellation. Upstream Flow exceptions follow the render session's coroutine failure route, while Paging load failures remain represented by CombinedLoadStates.

Receiver

Paging generations owned and cached by the application

Return

one observable owner remembered for this Flow identity

Parameters

lifecyclePolicy

collection threshold and inactive-retention policy

context

additional non-Job coroutine context used for upstream collection

Type Parameters

T

non-null item type emitted by Paging

Throws

when context contains a Job or a lifecycle-gated policy has no nearest AndroidX lifecycle owner

Samples

    val pagingItems = pages.collectAsViewComposePagingItems(
        lifecyclePolicy = PagingLifecyclePolicy.Composition,
    )
    // DOCS_REGION_START(paging-module-placeholders)
PagingLazyColumn(
    items = pagingItems,
    key = PagingSampleRow::id,
    contentType = { "paging-row" },
    contentRevision = PagingSampleRow::version,
    placeholderContentRevision = "paging-placeholder-v1",
    placeholderContent = { index -> Text("Loading row $index") },
) { row ->
    Text(row.label)
}
    // DOCS_REGION_END(paging-module-placeholders)