Skip to content

Commit

Permalink
fix: [ANDROAPP-5394] responsive home (#296)
Browse files Browse the repository at this point in the history
* fix: [ANDROAPP-5394] responsive home

* snapshot test
  • Loading branch information
mmmateos authored Sep 9, 2024
1 parent d53ddd9 commit 33912d2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.compose.material.icons.outlined.SyncDisabled
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import org.hisp.dhis.common.screens.previews.lorem_medium
import org.hisp.dhis.common.screens.previews.lorem
import org.hisp.dhis.mobile.ui.designsystem.component.AdditionalInfoItem
import org.hisp.dhis.mobile.ui.designsystem.component.Avatar
import org.hisp.dhis.mobile.ui.designsystem.component.AvatarStyleData
Expand Down Expand Up @@ -51,8 +51,9 @@ fun ExpandableListCardScreen() {
}
add(
AdditionalInfoItem(
value = lorem_medium,
value = lorem,
color = TextColor.OnSurfaceLight,
truncate = false,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ fun BaseCard(
fun <T> ExpandableItemColumn(
modifier: Modifier = Modifier,
itemList: List<T>,
itemSpacing: Dp = 16.dp,
itemSpacing: Dp = Spacing16,
contentPadding: Dp = Spacing16,
itemLayout: @Composable (T, itemVerticalPadding: Dp, onSizeChanged: (IntSize) -> Unit) -> Unit,
) {
val density = LocalDensity.current
Expand All @@ -123,8 +124,11 @@ fun <T> ExpandableItemColumn(
val itemVerticalPadding by remember(childrenSize) {
derivedStateOf {
val value = if (childrenSize.size == itemCount) {
var availableHeight =
parentSize - childrenSize.values.sum() - with(density) { itemSpacing.toPx() * (itemCount - 1) }
var availableHeight = parentSize -
childrenSize.values.sum() -
with(density) {
itemSpacing.toPx() * (itemCount - 1) + contentPadding.toPx() * 2
}
if (itemCount == 1) availableHeight /= 4
with(density) { (availableHeight / (2 * itemCount)).toDp() }.takeIf { it >= 16.dp }
?: 16.dp
Expand All @@ -143,7 +147,7 @@ fun <T> ExpandableItemColumn(
}
},
verticalArrangement = spacedBy(itemSpacing),
contentPadding = PaddingValues(Spacing16),
contentPadding = PaddingValues(contentPadding),
) {
itemList.forEachIndexed { index, item ->
item {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ fun ListCard(
)
listCardState.lastUpdateBasedOnLoading()?.let { ListCardLastUpdated(it) }
}
listCardState.descriptionBasedOnLoading()?.let { ListCardDescription(it, Modifier) }
listCardState.descriptionBasedOnLoading()?.let {
ListCardDescription(it, Modifier.padding(bottom = Spacing.Spacing8))
}

AdditionalInfoColumn(
additionalInfoColumnState = listCardState.additionalInfoColumnState,
Expand Down Expand Up @@ -256,15 +258,15 @@ fun VerticalInfoListCard(
Column(
modifier = Modifier.wrapContentHeight(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = spacedBy(Spacing.Spacing4),
verticalArrangement = spacedBy(Spacing4),
) {
ListCardTitle(
title = listCardState.title,
Modifier
.padding(bottom = if (listCardState.description?.text != null) Spacing.Spacing0 else Spacing4),
)
listCardState.descriptionBasedOnLoading()?.let {
ListCardDescription(it, Modifier)
ListCardDescription(it)
}
listCardState.lastUpdateBasedOnLoading()?.let {
ListCardLastUpdated(it)
Expand Down Expand Up @@ -673,8 +675,14 @@ fun ProvideKeyValueItem(
text = finalAnnotatedString,
textAlign = TextAlign.Start,
style = MaterialTheme.typography.bodyMedium,
overflow = TextOverflow.Ellipsis,
maxLines = 2,
overflow = when {
additionalInfoItem.truncate -> TextOverflow.Ellipsis
else -> TextOverflow.Clip
},
maxLines = when {
additionalInfoItem.truncate -> 2
else -> Int.MAX_VALUE
},
modifier = Modifier,

)
Expand Down Expand Up @@ -811,6 +819,7 @@ data class AdditionalInfoItem(
val value: String,
val isConstantItem: Boolean = false,
val color: Color? = null,
val truncate: Boolean = true,
val action: (() -> Unit)? = null,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ internal fun ListCardDescription(
description.text,
color = description.color ?: TextColor.OnSurface,
style = description.style ?: MaterialTheme.typography.bodyMedium,
modifier = modifier.padding(bottom = Spacing.Spacing8),
modifier = modifier,
)
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 33912d2

Please sign in to comment.