From 021760f210de7b7590c1b96baa942f1c728575a1 Mon Sep 17 00:00:00 2001 From: Sasikanth Date: Mon, 14 Oct 2024 15:35:28 +0530 Subject: [PATCH] Wrap `OrgUnitSelectorItem` in a `key` (#315) This acts same as item key in lazy views. Prevents the composable from recomposing unnecessarily when the key didn't change in the control flows. Like in this `forLoop` for example. --- .../ui/designsystem/component/OrgBottomSheet.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/OrgBottomSheet.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/OrgBottomSheet.kt index d1631a881..74fd87cd0 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/OrgBottomSheet.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/OrgBottomSheet.kt @@ -24,6 +24,7 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue +import androidx.compose.runtime.key import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue @@ -199,13 +200,15 @@ private fun OrgTreeList( horizontalAlignment = Alignment.Start, ) { orgTreeItems.forEach { item -> - OrgUnitSelectorItem( - orgTreeItem = item, - higherLevel = orgTreeItems.minBy { it.level }.level, - searchQuery = searchQuery, - onItemClick = onItemClick, - onItemSelected = onItemSelected, - ) + key(item.uid) { + OrgUnitSelectorItem( + orgTreeItem = item, + higherLevel = orgTreeItems.minBy { it.level }.level, + searchQuery = searchQuery, + onItemClick = onItemClick, + onItemSelected = onItemSelected, + ) + } } } }