{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

LazyGridScope

@LazyGridScopeMarker
public sealed interface LazyGridScope


Receiver scope which is used by LazyVerticalGrid.

Summary

Public methods

abstract void
item(
    Object key,
    @ExtensionFunctionType Function1<@NonNull LazyGridItemSpanScope, @NonNull GridItemSpan> span,
    Object contentType,
    @Composable @ExtensionFunctionType @NonNull Function1<@NonNull LazyGridItemScopeUnit> content
)

Adds a single item to the scope.

abstract void
items(
    int count,
    Function1<@NonNull Integer, @NonNull Object> key,
    @ExtensionFunctionType Function2<@NonNull LazyGridItemSpanScope, @NonNull Integer, @NonNull GridItemSpan> span,
    @NonNull Function1<@NonNull IntegerObject> contentType,
    @Composable @ExtensionFunctionType @NonNull Function2<@NonNull LazyGridItemScope, @NonNull IntegerUnit> itemContent
)

Adds a count of items.

Extension functions

default final void
<T extends Object> LazyGridDslKt.items(
    @NonNull LazyGridScope receiver,
    @NonNull T[] items,
    Function1<@NonNull item, @NonNull Object> key,
    @ExtensionFunctionType Function2<@NonNull LazyGridItemSpanScope, @NonNull item, @NonNull GridItemSpan> span,
    @NonNull Function1<@NonNull item, Object> contentType,
    @Composable @ExtensionFunctionType @NonNull Function2<@NonNull LazyGridItemScope, @NonNull item, Unit> itemContent
)

Adds an array of items.

default final void
<T extends Object> LazyGridDslKt.items(
    @NonNull LazyGridScope receiver,
    @NonNull List<@NonNull T> items,
    Function1<@NonNull item, @NonNull Object> key,
    @ExtensionFunctionType Function2<@NonNull LazyGridItemSpanScope, @NonNull item, @NonNull GridItemSpan> span,
    @NonNull Function1<@NonNull item, Object> contentType,
    @Composable @ExtensionFunctionType @NonNull Function2<@NonNull LazyGridItemScope, @NonNull item, Unit> itemContent
)

Adds a list of items.

default final void
<T extends Object> LazyGridDslKt.itemsIndexed(
    @NonNull LazyGridScope receiver,
    @NonNull T[] items,
    Function2<@NonNull Integer, @NonNull item, @NonNull Object> key,
    @ExtensionFunctionType Function3<@NonNull LazyGridItemSpanScope, @NonNull Integer, @NonNull item, @NonNull GridItemSpan> span,
    @NonNull Function2<@NonNull Integer, @NonNull item, Object> contentType,
    @Composable @ExtensionFunctionType @NonNull Function3<@NonNull LazyGridItemScope, @NonNull Integer, @NonNull item, Unit> itemContent
)

Adds an array of items where the content of an item is aware of its index.

default final void
<T extends Object> LazyGridDslKt.itemsIndexed(
    @NonNull LazyGridScope receiver,
    @NonNull List<@NonNull T> items,
    Function2<@NonNull Integer, @NonNull item, @NonNull Object> key,
    @ExtensionFunctionType Function3<@NonNull LazyGridItemSpanScope, @NonNull Integer, @NonNull item, @NonNull GridItemSpan> span,
    @NonNull Function2<@NonNull Integer, @NonNull item, Object> contentType,
    @Composable @ExtensionFunctionType @NonNull Function3<@NonNull LazyGridItemScope, @NonNull Integer, @NonNull item, Unit> itemContent
)

Adds a list of items where the content of an item is aware of its index.

Public methods

item

abstract void item(
    Object key,
    @ExtensionFunctionType Function1<@NonNull LazyGridItemSpanScope, @NonNull GridItemSpan> span,
    Object contentType,
    @Composable @ExtensionFunctionType @NonNull Function1<@NonNull LazyGridItemScopeUnit> content
)

Adds a single item to the scope.

Parameters
Object key

a stable and unique key representing the item. Using the same key for multiple items in the grid is not allowed. Type of the key should be saveable via Bundle on Android. If null is passed the position in the grid will represent the key. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one.

@ExtensionFunctionType Function1<@NonNull LazyGridItemSpanScope, @NonNull GridItemSpan> span

the span of the item. Default is 1x1. It is good practice to leave it null when this matches the intended behavior, as providing a custom implementation impacts performance

Object contentType

the type of the content of this item. The item compositions of the same type could be reused more efficiently. Note that null is a valid type and items of such type will be considered compatible.

@Composable @ExtensionFunctionType @NonNull Function1<@NonNull LazyGridItemScopeUnit> content

the content of the item

items

abstract void items(
    int count,
    Function1<@NonNull Integer, @NonNull Object> key,
    @ExtensionFunctionType Function2<@NonNull LazyGridItemSpanScope, @NonNull Integer, @NonNull GridItemSpan> span,
    @NonNull Function1<@NonNull IntegerObject> contentType,
    @Composable @ExtensionFunctionType @NonNull Function2<@NonNull LazyGridItemScope, @NonNull IntegerUnit> itemContent
)

Adds a count of items.

Parameters
int count

the items count

Function1<@NonNull Integer, @NonNull Object> key

a factory of stable and unique keys representing the item. Using the same key for multiple items in the grid is not allowed. Type of the key should be saveable via Bundle on Android. If null is passed the position in the grid will represent the key. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one.

@ExtensionFunctionType Function2<@NonNull LazyGridItemSpanScope, @NonNull Integer, @NonNull GridItemSpan> span

define custom spans for the items. Default is 1x1. It is good practice to leave it null when this matches the intended behavior, as providing a custom implementation impacts performance

@NonNull Function1<@NonNull IntegerObject> contentType

a factory of the content types for the item. The item compositions of the same type could be reused more efficiently. Note that null is a valid type and items of such type will be considered compatible.

@Composable @ExtensionFunctionType @NonNull Function2<@NonNull LazyGridItemScope, @NonNull IntegerUnit> itemContent

the content displayed by a single item

Extension functions

LazyGridDslKt.items

default final void <T extends Object> LazyGridDslKt.items(
    @NonNull LazyGridScope receiver,
    @NonNull T[] items,
    Function1<@NonNull item, @NonNull Object> key,
    @ExtensionFunctionType Function2<@NonNull LazyGridItemSpanScope, @NonNull item, @NonNull GridItemSpan> span,
    @NonNull Function1<@NonNull item, Object> contentType,
    @Composable @ExtensionFunctionType @NonNull Function2<@NonNull LazyGridItemScope, @NonNull item, Unit> itemContent
)

Adds an array of items.

Parameters
@NonNull T[] items

the data array

Function1<@NonNull item, @NonNull Object> key

a factory of stable and unique keys representing the item. Using the same key for multiple items in the grid is not allowed. Type of the key should be saveable via Bundle on Android. If null is passed the position in the grid will represent the key. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one.

@ExtensionFunctionType Function2<@NonNull LazyGridItemSpanScope, @NonNull item, @NonNull GridItemSpan> span

define custom spans for the items. Default is 1x1. It is good practice to leave it null when this matches the intended behavior, as providing a custom implementation impacts performance

@NonNull Function1<@NonNull item, Object> contentType

a factory of the content types for the item. The item compositions of the same type could be reused more efficiently. Note that null is a valid type and items of such type will be considered compatible.

@Composable @ExtensionFunctionType @NonNull Function2<@NonNull LazyGridItemScope, @NonNull item, Unit> itemContent

the content displayed by a single item

LazyGridDslKt.items

default final void <T extends Object> LazyGridDslKt.items(
    @NonNull LazyGridScope receiver,
    @NonNull List<@NonNull T> items,
    Function1<@NonNull item, @NonNull Object> key,
    @ExtensionFunctionType Function2<@NonNull LazyGridItemSpanScope, @NonNull item, @NonNull GridItemSpan> span,
    @NonNull Function1<@NonNull item, Object> contentType,
    @Composable @ExtensionFunctionType @NonNull Function2<@NonNull LazyGridItemScope, @NonNull item, Unit> itemContent
)

Adds a list of items.

Parameters
@NonNull List<@NonNull T> items

the data list

Function1<@NonNull item, @NonNull Object> key

a factory of stable and unique keys representing the item. Using the same key for multiple items in the grid is not allowed. Type of the key should be saveable via Bundle on Android. If null is passed the position in the grid will represent the key. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one.

@ExtensionFunctionType Function2<@NonNull LazyGridItemSpanScope, @NonNull item, @NonNull GridItemSpan> span

define custom spans for the items. Default is 1x1. It is good practice to leave it null when this matches the intended behavior, as providing a custom implementation impacts performance

@NonNull Function1<@NonNull item, Object> contentType

a factory of the content types for the item. The item compositions of the same type could be reused more efficiently. Note that null is a valid type and items of such type will be considered compatible.

@Composable @ExtensionFunctionType @NonNull Function2<@NonNull LazyGridItemScope, @NonNull item, Unit> itemContent

the content displayed by a single item

LazyGridDslKt.itemsIndexed

default final void <T extends Object> LazyGridDslKt.itemsIndexed(
    @NonNull LazyGridScope receiver,
    @NonNull T[] items,
    Function2<@NonNull Integer, @NonNull item, @NonNull Object> key,
    @ExtensionFunctionType Function3<@NonNull LazyGridItemSpanScope, @NonNull Integer, @NonNull item, @NonNull GridItemSpan> span,
    @NonNull Function2<@NonNull Integer, @NonNull item, Object> contentType,
    @Composable @ExtensionFunctionType @NonNull Function3<@NonNull LazyGridItemScope, @NonNull Integer, @NonNull item, Unit> itemContent
)

Adds an array of items where the content of an item is aware of its index.

Parameters
@NonNull T[] items

the data array

Function2<@NonNull Integer, @NonNull item, @NonNull Object> key

a factory of stable and unique keys representing the item. Using the same key for multiple items in the grid is not allowed. Type of the key should be saveable via Bundle on Android. If null is passed the position in the grid will represent the key. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one.

@ExtensionFunctionType Function3<@NonNull LazyGridItemSpanScope, @NonNull Integer, @NonNull item, @NonNull GridItemSpan> span

define custom spans for the items. Default is 1x1. It is good practice to leave it null when this matches the intended behavior, as providing a custom implementation impacts performance

@NonNull Function2<@NonNull Integer, @NonNull item, Object> contentType

a factory of the content types for the item. The item compositions of the same type could be reused more efficiently. Note that null is a valid type and items of such type will be considered compatible.

@Composable @ExtensionFunctionType @NonNull Function3<@NonNull LazyGridItemScope, @NonNull Integer, @NonNull item, Unit> itemContent

the content displayed by a single item

LazyGridDslKt.itemsIndexed

default final void <T extends Object> LazyGridDslKt.itemsIndexed(
    @NonNull LazyGridScope receiver,
    @NonNull List<@NonNull T> items,
    Function2<@NonNull Integer, @NonNull item, @NonNull Object> key,
    @ExtensionFunctionType Function3<@NonNull LazyGridItemSpanScope, @NonNull Integer, @NonNull item, @NonNull GridItemSpan> span,
    @NonNull Function2<@NonNull Integer, @NonNull item, Object> contentType,
    @Composable @ExtensionFunctionType @NonNull Function3<@NonNull LazyGridItemScope, @NonNull Integer, @NonNull item, Unit> itemContent
)

Adds a list of items where the content of an item is aware of its index.

Parameters
@NonNull List<@NonNull T> items

the data list

Function2<@NonNull Integer, @NonNull item, @NonNull Object> key

a factory of stable and unique keys representing the item. Using the same key for multiple items in the grid is not allowed. Type of the key should be saveable via Bundle on Android. If null is passed the position in the grid will represent the key. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one.

@ExtensionFunctionType Function3<@NonNull LazyGridItemSpanScope, @NonNull Integer, @NonNull item, @NonNull GridItemSpan> span

define custom spans for the items. Default is 1x1. It is good practice to leave it null when this matches the intended behavior, as providing a custom implementation impacts performance

@NonNull Function2<@NonNull Integer, @NonNull item, Object> contentType

a factory of the content types for the item. The item compositions of the same type could be reused more efficiently. Note that null is a valid type and items of such type will be considered compatible.

@Composable @ExtensionFunctionType @NonNull Function3<@NonNull LazyGridItemScope, @NonNull Integer, @NonNull item, Unit> itemContent

the content displayed by a single item