Skip to content

Commit

Permalink
Add Horizontal scroll to org bottom sheet item selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Agarwal committed Jun 3, 2024
1 parent cda4041 commit e2714ab
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package org.hisp.dhis.mobile.ui.designsystem.component

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredHeightIn
import androidx.compose.foundation.layout.requiredWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.ClearAll
Expand Down Expand Up @@ -172,6 +175,7 @@ private fun OrgTreeList(
onItemClick: (orgUnitUid: String) -> Unit,
onItemSelected: (orgUnitUid: String, checked: Boolean) -> Unit,
) {
val scrollState = rememberScrollState()
val hasSearchQuery by derivedStateOf { searchQuery.isNotBlank() }
if (orgTreeItems.isEmpty() && hasSearchQuery) {
Text(
Expand All @@ -188,7 +192,8 @@ private fun OrgTreeList(
} else {
LazyColumn(
modifier = modifier
.testTag("ORG_TREE_LIST"),
.testTag("ORG_TREE_LIST")
.horizontalScroll(scrollState),
state = state,
horizontalAlignment = Alignment.Start,
) {
Expand Down Expand Up @@ -247,12 +252,24 @@ fun OrgUnitSelectorItem(
contentDescription = "",
)

if (orgTreeItem.canBeSelected) {
Checkbox(
modifier = Modifier.testTag("$ITEM_CHECK_TEST_TAG${orgTreeItem.label}"),
checked = orgTreeItem.selected,
onCheckedChange = { isChecked ->
onItemSelected(orgTreeItem.uid, isChecked)
},
)
} else {
Spacer(modifier = Modifier.size(Spacing.Spacing16))
}

Text(
modifier = Modifier.weight(1f),
text = orgTreeItemLabel(
orgTreeItem = orgTreeItem,
searchQuery = searchQuery,
),
maxLines = 1,
style = DHIS2SCustomTextStyles.bodyLargeBold.copy(
fontWeight = if (orgTreeItem.selectedChildrenCount > 0 || orgTreeItem.selected) {
FontWeight.Bold
Expand All @@ -261,16 +278,6 @@ fun OrgUnitSelectorItem(
},
),
)

if (orgTreeItem.canBeSelected) {
Checkbox(
modifier = Modifier.testTag("$ITEM_CHECK_TEST_TAG${orgTreeItem.label}"),
checked = orgTreeItem.selected,
onCheckedChange = { isChecked ->
onItemSelected(orgTreeItem.uid, isChecked)
},
)
}
}
}

Expand Down

0 comments on commit e2714ab

Please sign in to comment.