Skip to content

Commit

Permalink
Added configurations for the spacer and empty list text in the list v…
Browse files Browse the repository at this point in the history
…iew (#3591)

* Added the configs for the spacer in list view

* Empty list text styling

---------

Co-authored-by: Peter Lubell-Doughtie <[email protected]>
  • Loading branch information
Aleem92 and pld authored Nov 16, 2024
1 parent 22a080b commit 9676866
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ import org.smartregister.fhircore.engine.configuration.navigation.NavigationMenu
data class NoResultsConfig(
val title: String = "",
val message: String = "",
val textColor: String? = null,
val actionButton: NavigationMenuConfig? = null,
) : Parcelable, java.io.Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ data class ListProperties(
val emptyList: NoResultsConfig? = null,
val orientation: ListOrientation = ListOrientation.VERTICAL,
val resources: List<ListResourceConfig> = emptyList(),
val spacerHeight: Int = 6,
val enableTopBottomSpacing: Boolean = true,
) : ViewProperties(), Parcelable {
override fun interpolate(computedValuesMap: Map<String, Any>): ListProperties {
return this.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material.Divider
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -74,11 +73,14 @@ fun List(
val currentListResourceData = resourceData.listResourceDataMap?.get(viewProperties.id)
if (currentListResourceData.isNullOrEmpty()) {
if (!viewProperties.emptyList?.message.isNullOrEmpty()) {
Box(contentAlignment = Alignment.Center, modifier = modifier.wrapContentSize()) {
Box(contentAlignment = Alignment.Center, modifier = modifier.fillMaxWidth()) {
Text(
text = viewProperties.emptyList?.message!!,
modifier = modifier.padding(8.dp).align(Alignment.Center),
color = DefaultColor,
modifier =
modifier
.conditional(viewProperties.enableTopBottomSpacing, { padding(8.dp) })
.align(Alignment.Center),
color = viewProperties.emptyList?.textColor?.parseColor() ?: DefaultColor,
fontStyle = FontStyle.Italic,
)
}
Expand Down Expand Up @@ -116,7 +118,11 @@ fun List(
viewProperty.visible.toBooleanStrict()
}
if (areChildViewsVisible) {
Spacer(modifier = modifier.height(6.dp))
// Add spacing before each item, except for first item when enableTopBottomSpacing
// is false
if (index != 0 || viewProperties.enableTopBottomSpacing) {
Spacer(modifier = modifier.height(viewProperties.spacerHeight.dp))
}
Column(
modifier =
Modifier.padding(
Expand All @@ -143,7 +149,13 @@ fun List(
)
}
}
Spacer(modifier = modifier.height(6.dp))
// Add spacer after each item except last one when enableTopBottomSpacing is false
if (
index != currentListResourceData.lastIndex ||
viewProperties.enableTopBottomSpacing
) {
Spacer(modifier = modifier.height(viewProperties.spacerHeight.dp))
}
// viewProperties in this case belongs to the List, setting the showDivider will
// apply to all child items under the List
if (index < currentListResourceData.lastIndex && viewProperties.showDivider) {
Expand Down

0 comments on commit 9676866

Please sign in to comment.