LazyLayoutPrefetchState


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

Note: this class is a part of LazyLayout harness that allows for building custom lazy layouts. LazyLayout and all corresponding APIs are still under development and are subject to change.

Summary

Nested types

A scope for schedulePrefetch callbacks.

Public constructors

LazyLayoutPrefetchState(
    prefetchScheduler: PrefetchScheduler?,
    onNestedPrefetch: (NestedPrefetchScope.() -> Unit)?
)
Cmn

Public functions

LazyLayoutPrefetchState.PrefetchHandle

Schedules precomposition for the new item.

Cmn
LazyLayoutPrefetchState.PrefetchHandle
schedulePrecompositionAndPremeasure(
    index: Int,
    constraints: Constraints,
    onItemPremeasured: (LazyLayoutPrefetchState.LazyLayoutPrefetchResultScope.() -> Unit)?
)

Schedules precomposition and premeasure for the new item.

Cmn
LazyLayoutPrefetchState.PrefetchHandle

This function is deprecated. Please use schedulePrecomposition(index) instead

Cmn
LazyLayoutPrefetchState.PrefetchHandle
schedulePrefetch(index: Int, constraints: Constraints)

This function is deprecated. Please use schedulePremeasure(index, constraints) instead

Cmn

Public constructors

LazyLayoutPrefetchState

LazyLayoutPrefetchState(
    prefetchScheduler: PrefetchScheduler? = null,
    onNestedPrefetch: (NestedPrefetchScope.() -> Unit)? = null
)
Parameters
prefetchScheduler: PrefetchScheduler? = null

the PrefetchScheduler implementation to use to execute prefetch requests. If null is provided, the default PrefetchScheduler for the platform will be used.

onNestedPrefetch: (NestedPrefetchScope.() -> Unit)? = null

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.

Public functions

schedulePrecomposition

fun schedulePrecomposition(index: Int): LazyLayoutPrefetchState.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: Int

item index to prefetch.

schedulePrecompositionAndPremeasure

fun schedulePrecompositionAndPremeasure(
    index: Int,
    constraints: Constraints,
    onItemPremeasured: (LazyLayoutPrefetchState.LazyLayoutPrefetchResultScope.() -> Unit)? = null
): LazyLayoutPrefetchState.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: Int

item index to prefetch.

constraints: Constraints

Constraints to use for premeasuring.

onItemPremeasured: (LazyLayoutPrefetchState.LazyLayoutPrefetchResultScope.() -> Unit)? = null

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 LazyLayoutPrefetchResultScope.getSize to get the item's size.

schedulePrefetch

fun schedulePrefetch(index: Int): LazyLayoutPrefetchState.PrefetchHandle

Schedules precomposition for the new item. If you also want to premeasure the item please use a second overload accepting a Constraints param.

Parameters
index: Int

item index to prefetch.

schedulePrefetch

fun schedulePrefetch(index: Int, constraints: Constraints): LazyLayoutPrefetchState.PrefetchHandle

Schedules precomposition and premeasure for the new item.

Parameters
index: Int

item index to prefetch.

constraints: Constraints

Constraints to use for premeasuring.