簡體   English   中英

伴奏在 LazyColumn 內滑動刷新

[英]Accompanist SwipeRefresh Inside LazyColumn

我正在嘗試將 SwipeRefresh 布局放置在 LazyColumn 和 scope 內,以包括 2 個項目調用和一個項目調用,在項目 {LazyRow(inside LazyColumn)} 下方和另一個項目{}下方。

所以我想要實現的是:

LazyColumn(
        Modifier
            .fillMaxSize()
            .background(colorResource(id = R.color.colorBackground))
    ) {
        item {
           LazyRow(
                Modifier
                    .wrapContentHeight()
                    .fillMaxWidth()
                    .background(colorResource(id = R.color.colorBackground)),
                listState
            ) { items()}
        }
        item { }
        -- this is where I want to place the swipe Refresh --
        item {}// box for holding a drawable
        item {} // another box
        items{ } // efficiently list items here
    }

我認為我可以做的是,我可以制作一個巨大的可滾動列,而不是使用lazyList 及其 dsl,但這會導致頁面失去底部的 items{} 塊的所有性能提升。 有沒有比使用 Column 更有效的方法?

您應將LazyColumn放入SwipeRefresh可組合中。 例如:

SwipeRefresh(
        state = swipeRefreshState,
        onRefresh = onRefresh,
        indicator = { state, refreshTrigger ->
            SwipeRefreshIndicator(
                state = state,
                refreshTriggerDistance = refreshTrigger
            )
        }
    ) {
            LazyColumn(
                modifier = Modifier
                    .fillMaxSize()
                    .background(Color.White),
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                item {
                 
                        Row(
                            modifier = Modifier.fillMaxWidth(),
                            horizontalArrangement = Arrangement.SpaceEvenly
                        ) {
                            someSections.forEach { section ->
                                SomeComposable(...)
                            }
                        }
                    }
                }
            }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM