Hi there Can any one help me how we can implement...
# compose
h
Hi there Can any one help me how we can implement pull/swipe to refresh
n
you can check out the official documentation for the pull/refresh functionality in compose https://developer.android.com/reference/kotlin/androidx/compose/material/pullrefresh/package-summary
h
Thank you
n
you're welcome, if you need any help just ask here 👍🏻
K 1
h
I have gone through the page which you shared but I am not able get proper dependency of this Can you share any sample example with the same that will be the helpful
n
Sorry for the late response. Here's a small example that shows how to use the pullRefresh composable
Copy code
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun PullRefreshExample(
    onUpdate: () -> Unit,
    isRefreshing: Boolean
) {
    val pullToRefreshState = rememberPullToRefreshState()

    if (pullToRefreshState.isRefreshing) {
        LaunchedEffect(key1 = true) {
            onUpdate()
            pullToRefreshState.endRefresh()
        }
    }

    Box(
        modifier = Modifier
            .nestedScroll(pullToRefreshState.nestedScrollConnection)
            .clipToBounds()
    ) {
        Crossfade(targetState = isRefreshing, label = "PlaceholderTransition") {
            if (it) {
                PlaceholderList()
            } else {
                LazyColumn(
                    modifier = Modifier.fillMaxSize()
                ) {
                    items(
                        items = items,
                    ) {
                        // items
                    }
                }

                PullToRefreshContainer(
                    state = pullToRefreshState,
                    modifier = Modifier.align(Alignment.TopCenter)
                )
            }
        }
    }
}
as you can see, you have to place your content and the PullToRefreshContainer inside a Box, with the PullToRefreshContainer composable placed as the last (topmost) item in the box. The box has to use this modifier
Copy code
Modifier.nestedScroll(pullToRefreshState.nestedScrollConnection)
            .clipToBounds()
In my case, triggering the refresh calls the onUpdate function and changes the refresh state of the PullToRefreshState
h
Noted Niks Thanks a lot 🙏🏼
n
you're welcome 😁
h
I have solved my problem when I was created the variable as remeberPullToRefreshState() at that time I not able get it's important due to that I am getting
n
sorry, I'm pretty confused, have you been able to solve your issue or is it still present?
h
Now it's solved
n
awesome 😁
👍 1