Hey i tried to use the new <SwipeRefresh>. My Lazy...
# compose
a
Hey i tried to use the new SwipeRefresh. My LazyColumn uses SwipeToDismisswithin the rows. To show the dismiss animation, my viewModel hold a list of deleted items. Within the LazyColum i check, if my item is within the deletedItems list, than i will skip it in the LazyColumn. If i remove the item directly from the list or delete it in the db, the ui will be triggered from collectAsState on the itemsFlow. The deleted item is not in the list anymore... as a result, the item will instantly be invisible, no fadeOut, shrinkHorizontally... My current problem is, that SwipeRefresh won't let me "swipe" down anymore, if the first item is "deleted". Any ideas?
🤔 1
Copy code
class DemoViewModel: ViewModel() {

    private val deletedItems: MutableStateFlow<List<String>> = MutableStateFlow(listOf())

    val items = flow<List<String>> {
        listOf("Item1", "Item2")
    }.combine(deletedItems) { items: List<String>, deletedItems: List<String> ->
        items.filter { item ->
            val isVisible = deletedItems.firstOrNull { it == item } == null
            isVisible
        }
    }.stateIn(
        viewModelScope,
        SharingStarted.WhileSubscribed(),
        listOf()
    )

    fun isVisible(item: String): Boolean {
        return deletedItems.value.firstOrNull { it == item } == null
    }

    fun refresh(onSyncFinish: () -> Unit) {
        viewModelScope.launch {
            //Sync repos
            onSyncFinish()
        }
    }
}

@Composable
fun Demo(
    viewModel: DemoViewModel
) {
    val items by viewModel.items.collectAsState()
    var isRefreshing by remember { mutableStateOf(false) }

    SwipeRefresh(
        state = rememberSwipeRefreshState(isRefreshing = isRefreshing),
        onRefresh = {
            isRefreshing = true
            viewModel.refresh {
                isRefreshing = false
            }
        }
    ) {
        LazyColumn {
            items(items) { item ->
                if (viewModel.isVisible(item)) {

                    // This Item is swipeToDismiss.
                    // swipeToDismiss adds it to viewModel.deletedItems
                    Text(text = item)
                    
                }
            }
        }
    }
}
Above i added a simple demo. I haven't tried it, but it should describe how i try to combine SwipeToDimiss and SwipeRefresh. My problem is, that i don't get both together. At that moment, the first item is in the deletedItems List, the SwipeRefresh won't work anymore