fun MainLazyColumnItemsList()

in benchmarks/multiplatform/benchmarks/src/commonMain/kotlin/benchmarks/complexlazylist/components/MainUI.kt [38:105]


fun MainLazyColumnItemsList(noImage: Boolean, useJson: Boolean) {
    val scope = rememberCoroutineScope()
    val state = rememberSwipeRefreshState(NORMAL)

    LaunchedEffect(scope) {
        scope.launch(Dispatchers.Default) {
            fetchCompositionModels(false) { list ->
                for (item in list)
                    models.add(item)
            }
        }
    }

    SwipeRefreshLayout(
        state = state,
        indicator = { modifier, s, indicatorHeight ->
            LoadingIndicatorDefault(modifier, s, indicatorHeight)
        },
        onRefresh = {
            scope.launch {
                state.loadState = REFRESHING
                delay(2000)
                fetchCompositionModels(useJson) {
                    models.clear()
                    for (item in it)
                        models.add(item)
                    state.loadState = NORMAL
                }
            }

        },
        onLoadMore = {
            scope.launch {
                state.loadState = LOADING_MORE
                delay(2000L)
                fetchCompositionModels(useJson) {
                    for (item in it)
                        models.add(item)
                    state.loadState = NORMAL
                }
            }
        }
    ) { modifier ->
        run {
            val state = rememberLazyListState()
            LaunchedEffect(Unit) {
                while (true) {
                    withFrameMillis { }
                    state.scrollBy(20f)
                }
            }
            LazyColumn(modifier, state = state) {
                itemsIndexed(
                    items = models,
                    key = { index, _ ->
                        models[index]
                    }
                ) { _, item ->
                    when (item) {
                        is ICompositionModel -> MultiCellUI(item)
                        // .. todo need more types
                        else -> throw RuntimeException("Unexpected")
                    }
                }
            }
        }
    }
}