androidx.tv.foundation.lazy.grid

Interfaces

TvGridCells

This interface is deprecated. Use `GridCells` instead.

TvLazyGridItemInfo

This interface is deprecated. Use `LazyGridItemInfo` instead.

TvLazyGridItemScope

This interface is deprecated. Use `LazyGridItemScope` instead.

TvLazyGridItemSpanScope

This interface is deprecated. Use `LazyGridItemSpanScope` instead.

TvLazyGridLayoutInfo

This interface is deprecated. Use `LazyGridLayoutInfo` instead.

TvLazyGridScope

This interface is deprecated. Use LazyGridScope instead.

Classes

TvGridCells.Adaptive

This class is deprecated. Use GridCells from compose foundation.

TvGridCells.Fixed

This class is deprecated. Use GridCells.Fixed from compose foundation.

TvGridCells.FixedSize

This class is deprecated. Use GridCells from compose foundation.

TvGridItemSpan

This class is deprecated. Use `GridItemSpan` instead.

TvLazyGridState

This class is deprecated. Use `LazyGridState` instead.

Annotations

TvLazyGridScopeMarker

This annotation is deprecated. No longer needed as TvLazyHorizontalGrid and TvLazyVerticalGrid are deprecated.

Top-level functions summary

TvGridItemSpan
TvGridItemSpan(currentLineSpan: Int)

This function is deprecated. Use `GridItemSpan` instead.

Unit
@Composable
TvLazyHorizontalGrid(
    rows: TvGridCells,
    modifier: Modifier,
    state: TvLazyGridState,
    contentPadding: PaddingValues,
    reverseLayout: Boolean,
    horizontalArrangement: Arrangement.Horizontal,
    verticalArrangement: Arrangement.Vertical,
    userScrollEnabled: Boolean,
    pivotOffsets: PivotOffsets,
    content: TvLazyGridScope.() -> Unit
)

This function is deprecated. LazyHorizontalGrid will, by default, set the position of focused item while scrolling on a Tv.

Unit
@Composable
TvLazyVerticalGrid(
    columns: TvGridCells,
    modifier: Modifier,
    state: TvLazyGridState,
    contentPadding: PaddingValues,
    reverseLayout: Boolean,
    verticalArrangement: Arrangement.Vertical,
    horizontalArrangement: Arrangement.Horizontal,
    userScrollEnabled: Boolean,
    pivotOffsets: PivotOffsets,
    content: TvLazyGridScope.() -> Unit
)

This function is deprecated. LazyVerticalGrid will, by default, set the position of focused item while scrolling on a Tv.

TvLazyGridState
@Composable
rememberTvLazyGridState(
    initialFirstVisibleItemIndex: Int,
    initialFirstVisibleItemScrollOffset: Int
)

This function is deprecated. Use `rememberLazyGridState` instead.

Extension functions summary

inline Unit
<T : Any?> TvLazyGridScope.items(
    items: Array<T>,
    noinline key: ((item) -> Any)?,
    noinline span: (TvLazyGridItemSpanScope.(item) -> TvGridItemSpan)?,
    noinline contentType: (item) -> Any?,
    crossinline itemContent: @Composable TvLazyGridItemScope.(item) -> Unit
)

This function is deprecated. Use `LazyGridScope.items` instead.

inline Unit
<T : Any?> TvLazyGridScope.items(
    items: List<T>,
    noinline key: ((item) -> Any)?,
    noinline span: (TvLazyGridItemSpanScope.(item) -> TvGridItemSpan)?,
    noinline contentType: (item) -> Any?,
    crossinline itemContent: @Composable TvLazyGridItemScope.(item) -> Unit
)

This function is deprecated. Use `LazyGridScope.items` instead

inline Unit
<T : Any?> TvLazyGridScope.itemsIndexed(
    items: Array<T>,
    noinline key: ((index: Int, item) -> Any)?,
    noinline span: (TvLazyGridItemSpanScope.(index: Int, item) -> TvGridItemSpan)?,
    crossinline contentType: (index: Int, item) -> Any?,
    crossinline itemContent: @Composable TvLazyGridItemScope.(index: Int, item) -> Unit
)

This function is deprecated. Use `LazyGridScope.itemsIndexed` instead.

inline Unit
<T : Any?> TvLazyGridScope.itemsIndexed(
    items: List<T>,
    noinline key: ((index: Int, item) -> Any)?,
    noinline span: (TvLazyGridItemSpanScope.(index: Int, item) -> TvGridItemSpan)?,
    crossinline contentType: (index: Int, item) -> Any?,
    crossinline itemContent: @Composable TvLazyGridItemScope.(index: Int, item) -> Unit
)

This function is deprecated. Use `LazyGridScope.itemsIndexed` instead.

Top-level functions

TvGridItemSpan

fun TvGridItemSpan(currentLineSpan: Int): TvGridItemSpan

Creates a TvGridItemSpan with a specified currentLineSpan. This will be the horizontal span for an item of a TvLazyVerticalGrid.

TvLazyHorizontalGrid

@Composable
fun TvLazyHorizontalGrid(
    rows: TvGridCells,
    modifier: Modifier = Modifier,
    state: TvLazyGridState = rememberTvLazyGridState(),
    contentPadding: PaddingValues = PaddingValues(0.dp),
    reverseLayout: Boolean = false,
    horizontalArrangement: Arrangement.Horizontal = if (!reverseLayout) Arrangement.Start else Arrangement.End,
    verticalArrangement: Arrangement.Vertical = Arrangement.Top,
    userScrollEnabled: Boolean = true,
    pivotOffsets: PivotOffsets = PivotOffsets(),
    content: TvLazyGridScope.() -> Unit
): Unit

A lazy horizontal grid layout. It composes only visible columns of the grid.

Parameters
rows: TvGridCells

a class describing how cells form rows, see TvGridCells doc for more information

modifier: Modifier = Modifier

the modifier to apply to this layout

state: TvLazyGridState = rememberTvLazyGridState()

the state object to be used to control or observe the list's state

contentPadding: PaddingValues = PaddingValues(0.dp)

specify a padding around the whole content

reverseLayout: Boolean = false

reverse the direction of scrolling and layout, when true items will be composed from the end to the start and TvLazyGridState.firstVisibleItemIndex == 0 will mean the first item is located at the end.

horizontalArrangement: Arrangement.Horizontal = if (!reverseLayout) Arrangement.Start else Arrangement.End

The horizontal arrangement of the layout's children

verticalArrangement: Arrangement.Vertical = Arrangement.Top

The vertical arrangement of the layout's children

userScrollEnabled: Boolean = true

whether the scrolling via the user gestures or accessibility actions is allowed. You can still scroll programmatically using the state even when it is disabled.

pivotOffsets: PivotOffsets = PivotOffsets()

offsets that are used when implementing Scrolling with Offset

pivotOffsets: PivotOffsets = PivotOffsets()

offsets of child element within the parent and starting edge of the child from the pivot defined by the parentOffset.

content: TvLazyGridScope.() -> Unit

the TvLazyGridScope which describes the content

TvLazyVerticalGrid

@Composable
fun TvLazyVerticalGrid(
    columns: TvGridCells,
    modifier: Modifier = Modifier,
    state: TvLazyGridState = rememberTvLazyGridState(),
    contentPadding: PaddingValues = PaddingValues(0.dp),
    reverseLayout: Boolean = false,
    verticalArrangement: Arrangement.Vertical = if (!reverseLayout) Arrangement.Top else Arrangement.Bottom,
    horizontalArrangement: Arrangement.Horizontal = Arrangement.Start,
    userScrollEnabled: Boolean = true,
    pivotOffsets: PivotOffsets = PivotOffsets(),
    content: TvLazyGridScope.() -> Unit
): Unit

A lazy vertical grid layout. It composes only visible rows of the grid.

Parameters
columns: TvGridCells

describes the count and the size of the grid's columns, see TvGridCells doc for more information

modifier: Modifier = Modifier

the modifier to apply to this layout

state: TvLazyGridState = rememberTvLazyGridState()

the state object to be used to control or observe the list's state

contentPadding: PaddingValues = PaddingValues(0.dp)

specify a padding around the whole content

reverseLayout: Boolean = false

reverse the direction of scrolling and layout. When true, items will be laid out in the reverse order and TvLazyGridState.firstVisibleItemIndex == 0 means that grid is scrolled to the bottom. Note that reverseLayout does not change the behavior of verticalArrangement, e.g. with Arrangement.Top (top) 123### (bottom) becomes (top) 321### (bottom).

verticalArrangement: Arrangement.Vertical = if (!reverseLayout) Arrangement.Top else Arrangement.Bottom

The vertical arrangement of the layout's children

horizontalArrangement: Arrangement.Horizontal = Arrangement.Start

The horizontal arrangement of the layout's children

userScrollEnabled: Boolean = true

whether the scrolling via the user gestures or accessibility actions is allowed. You can still scroll programmatically using the state even when it is disabled.

pivotOffsets: PivotOffsets = PivotOffsets()

offsets that are used when implementing Scrolling with Offset

pivotOffsets: PivotOffsets = PivotOffsets()

offsets of child element within the parent and starting edge of the child from the pivot defined by the parentOffset.

content: TvLazyGridScope.() -> Unit

the TvLazyGridScope which describes the content

rememberTvLazyGridState

@Composable
fun rememberTvLazyGridState(
    initialFirstVisibleItemIndex: Int = 0,
    initialFirstVisibleItemScrollOffset: Int = 0
): TvLazyGridState

Creates a TvLazyGridState that is remembered across compositions.

Changes to the provided initial values will not result in the state being recreated or changed in any way if it has already been created.

Parameters
initialFirstVisibleItemIndex: Int = 0

the initial value for TvLazyGridState.firstVisibleItemIndex

initialFirstVisibleItemScrollOffset: Int = 0

the initial value for TvLazyGridState.firstVisibleItemScrollOffset

Extension functions

items

inline fun <T : Any?> TvLazyGridScope.items(
    items: Array<T>,
    noinline key: ((item) -> Any)? = null,
    noinline span: (TvLazyGridItemSpanScope.(item) -> TvGridItemSpan)? = null,
    noinline contentType: (item) -> Any? = { null },
    crossinline itemContent: @Composable TvLazyGridItemScope.(item) -> Unit
): Unit

Adds an array of items.

Parameters
items: Array<T>

the data array

noinline key: ((item) -> Any)? = null

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.

noinline span: (TvLazyGridItemSpanScope.(item) -> TvGridItemSpan)? = null

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

noinline contentType: (item) -> Any? = { null }

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.

crossinline itemContent: @Composable TvLazyGridItemScope.(item) -> Unit

the content displayed by a single item

inline fun <T : Any?> TvLazyGridScope.items(
    items: List<T>,
    noinline key: ((item) -> Any)? = null,
    noinline span: (TvLazyGridItemSpanScope.(item) -> TvGridItemSpan)? = null,
    noinline contentType: (item) -> Any? = { null },
    crossinline itemContent: @Composable TvLazyGridItemScope.(item) -> Unit
): Unit

Adds a list of items.

Parameters
items: List<T>

the data list

noinline key: ((item) -> Any)? = null

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.

noinline span: (TvLazyGridItemSpanScope.(item) -> TvGridItemSpan)? = null

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

noinline contentType: (item) -> Any? = { null }

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.

crossinline itemContent: @Composable TvLazyGridItemScope.(item) -> Unit

the content displayed by a single item

itemsIndexed

inline fun <T : Any?> TvLazyGridScope.itemsIndexed(
    items: Array<T>,
    noinline key: ((index: Int, item) -> Any)? = null,
    noinline span: (TvLazyGridItemSpanScope.(index: Int, item) -> TvGridItemSpan)? = null,
    crossinline contentType: (index: Int, item) -> Any? = { _, _ -> null },
    crossinline itemContent: @Composable TvLazyGridItemScope.(index: Int, item) -> Unit
): Unit

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

Parameters
items: Array<T>

the data array

noinline key: ((index: Int, item) -> Any)? = null

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.

noinline span: (TvLazyGridItemSpanScope.(index: Int, item) -> TvGridItemSpan)? = null

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

crossinline contentType: (index: Int, item) -> Any? = { _, _ -> null }

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.

crossinline itemContent: @Composable TvLazyGridItemScope.(index: Int, item) -> Unit

the content displayed by a single item

itemsIndexed

inline fun <T : Any?> TvLazyGridScope.itemsIndexed(
    items: List<T>,
    noinline key: ((index: Int, item) -> Any)? = null,
    noinline span: (TvLazyGridItemSpanScope.(index: Int, item) -> TvGridItemSpan)? = null,
    crossinline contentType: (index: Int, item) -> Any? = { _, _ -> null },
    crossinline itemContent: @Composable TvLazyGridItemScope.(index: Int, item) -> Unit
): Unit

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

Parameters
items: List<T>

the data list

noinline key: ((index: Int, item) -> Any)? = null

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.

noinline span: (TvLazyGridItemSpanScope.(index: Int, item) -> TvGridItemSpan)? = null

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

crossinline contentType: (index: Int, item) -> Any? = { _, _ -> null }

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.

crossinline itemContent: @Composable TvLazyGridItemScope.(index: Int, item) -> Unit

the content displayed by a single item