Thread
#compose
    Hatice Sarp

    Hatice Sarp

    1 year ago
    Hi! I have datas with lazypagingItems in a composable. I am accessing this composable through a fragment. The screen should refresh when one of the paginated data shown in the UI is deleted. But I can't do pagination refresh. What do you think is the problem?
    Code:
    @Composable
    private fun RequestComposable(
        modifier: Modifier= Modifier,
        paginatedRequests: LazyPagingItems<RequestItem>,
        deleteRequest: (String, (Boolean) -> Unit) -> Unit,
    ) {
        LazyColumn(modifier = modifier.fillMaxSize()) {
            if (paginatedRequests.loadState.refresh == LoadState.Loading) {
                item {
                    Column(
                        modifier = Modifier.fillMaxSize(),
                        verticalArrangement = Arrangement.Center,
                        horizontalAlignment = Alignment.CenterHorizontally
                    ) {
                        CircularProgressIndicator()
                    }
                }
            }
    
            itemsIndexed(paginatedRequests) { index, item ->
                if (item != null) {
                    ListItem(
                        item = item,
                        userName = item.name,
                        endImage = {
                            Image(
                                ImageVector.vectorResource(id = R.drawable.ic_icons_call_end_call),
                                contentDescription = "endCallIcon"
                            )
                        },
                        endImageClick = {
                            deleteRequest(item.id){
                                if (it) {
                                    paginatedRequests.refresh()
                                }
                            }
    
                           }
                    )
                }
            }
    
            if (paginatedRequests.loadState.append == LoadState.Loading) {
                item {
                    CircularProgressIndicator(
                        modifier = Modifier
                            .fillMaxWidth()
                            .wrapContentWidth(Alignment.CenterHorizontally)
                    )
                }
            }
        }
    }
    @AndroidEntryPoint
    class FriendsFragment: ComposableFragment() {
        private val friendsViewModel: FriendsViewModel by activityViewModels()
    
        @Composable
        override fun ScreenContent() {
            RequestUIModel(
                RequestComposableComponent(
                    declineFriendRequest = {  userId, listener ->  friendsViewModel.declineFriendRequest(userId, listener)},
                )
            ).getComponents().forEach {
                it.createComposableViews().render()
            }
        }
    }
    fun declineFriendRequest(userId: String, listener: (Boolean) -> Unit) {
        viewModelScope.launch {
            declineFriendRequestUsecase.invoke(userId).collect {
                if (it is Result.Success) {
                    listener.invoke(true)
                }
            }
        }
    }