Created
February 18, 2023 09:17
-
-
Save BraveEvidence/dd5e20838faf56c6f21ad4b7c3d3e2cb to your computer and use it in GitHub Desktop.
Jetpack compose re-rendering issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compose code | |
Image( | |
painter = if (expandedList.any { it.isSelected }) painterResource(id = R.drawable.drop_down_expand) else painterResource( | |
id = R.drawable.drop_down_collapse | |
), | |
contentDescription = text, modifier = Modifier.clickable { | |
manageCredentialViewModel.toggleList(text) | |
} | |
) | |
//View model code | |
private val _expandedList = MutableStateFlow( | |
mutableListOf( | |
VCItem( | |
item = "Claim requested credentials", | |
isSelected = false | |
), | |
VCItem( | |
item = "Claim received credentials", | |
isSelected = false | |
), | |
VCItem( | |
item = "Pending Requests", | |
isSelected = false | |
) | |
) | |
) | |
fun toggleList(value: String) { | |
val item = _expandedList.value.find { it.item == value } | |
val index = _expandedList.value.indexOfFirst { it.item == value } | |
if(item != null){ | |
val isSelected = item.isSelected | |
_expandedList.value[index] = item.copy(isSelected = !isSelected) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for posting this, I'm encountering the same problem!