Class

LazyLayoutPrefetchState

State for lazy items prefetching, used by lazy layouts to instruct the prefetcher.

Common
class LazyLayoutPrefetchState()

State for lazy items prefetching, used by lazy layouts to instruct the prefetcher.

Secondary Constructors

@ExperimentalFoundationApi
constructor(
    prefetchScheduler: PrefetchScheduler? = null,
    onNestedPrefetch: (NestedPrefetchScope.() -> Unit)? = null,
) : this() {
    this.prefetchScheduler = prefetchScheduler
    this.onNestedPrefetch = onNestedPrefetch
}

State for lazy items prefetching, used by lazy layouts to instruct the prefetcher.

Parameters

prefetchScheduler the PrefetchScheduler implementation to use to execute prefetch requests. If null is provided, the default PrefetchScheduler for the platform will be used.
onNestedPrefetch a callback which will be invoked when this LazyLayout is prefetched in context of a parent LazyLayout, giving a chance to recursively prefetch its own children. See NestedPrefetchScope.
@ExperimentalFoundationApi
constructor(onNestedPrefetch: (NestedPrefetchScope.() -> Unit)? = null) : this() {
    this.onNestedPrefetch = onNestedPrefetch
}

State for lazy items prefetching, used by lazy layouts to instruct the prefetcher.

Parameters

onNestedPrefetch a callback which will be invoked when this LazyLayout is prefetched in context of a parent LazyLayout, giving a chance to recursively prefetch its own children. See NestedPrefetchScope.

Functions

schedulePrecomposition

fun schedulePrecomposition(@IntRange(from = 0) index: Int): PrefetchHandle

Schedules precomposition for the new item. If you also want to premeasure the item please use schedulePrecompositionAndPremeasure instead. This function should only be called once per item. If the item has already been composed at the time this request executes, either from a previous call to this function or because the item is already visible, this request should have no meaningful effect.

Parameters

index item index to prefetch.

Returns

A PrefetchHandle which can be used to control the lifecycle of the prefetch request. Use PrefetchHandle.cancel to cancel the request or PrefetchHandle.markAsUrgent to mark the request as urgent.

schedulePrecompositionAndPremeasure

fun schedulePrecompositionAndPremeasure(
        @IntRange(from = 0) index: Int,
        constraints: Constraints,
        onItemPremeasured: (PrefetchResultScope.() -> Unit)? = null,
    ): PrefetchHandle

Schedules precomposition and premeasure for the new item. This should be used instead of schedulePrecomposition if you also want to premeasure the item. This function should only be called once per item. If the item has already been composed / measured at the time this request executes, either from a previous call to this function or because the item is already visible, this request should have no meaningful effect.

Parameters

index item index to prefetch.
constraints Constraints to use for premeasuring.
onItemPremeasured This callback is called when the item premeasuring is finished. If the request is canceled or no measuring is performed this callback won't be called. Use PrefetchResultScope.getSize to get the item's size.

Returns

A PrefetchHandle which can be used to control the lifecycle of the prefetch request. Use PrefetchHandle.cancel to cancel the request or PrefetchHandle.markAsUrgent to mark the request as urgent.