I'm currently using paging items (LazyPagingItems) in LazyVerticalGrid via below extention function and it works fine.
inline fun <T : Any> LazyGridScope.items(
items: LazyPagingItems<T>,
crossinline itemContent: @Composable LazyGridItemScope.(item: T?) -> Unit
) {
items(count = items.itemCount) { index ->
itemContent(items[index])
}
}
However, i want to make use of other parameters that LazyLazyout provides like key, span etc and tried below function.
inline fun <T : Any> LazyGridScope.items(
items: LazyPagingItems<T>,
noinline key: ((item: T?) -> Any)? = null,
noinline span: (LazyGridItemSpanScope.(item: T?) -> GridItemSpan)? = null,
noinline contentType: (item: T?) -> Any? = { null },
crossinline itemContent: @Composable LazyGridItemScope.(item: T?) -> Unit
) = items(
count = items.itemCount,
key = if (key != null) { index: Int -> key(items[index]) } else null,
span = if (span != null) { { span(items[it]) } } else null,
contentType = { index: Int -> contentType(items[index]) }
) {
itemContent(items[it])
}
When i use that function with key, it shows errors that Type mismatch: inferred type is Long? but Any was expected.
items(items = products, key = { product -> product?.productId }) {
//Content
}
I guess this is due to declaration of public class LazyPagingItems<T : Any>. How do I resolve it to use all parameters with paging items ?