Improve PreferenceText rendering, in particular center the test on the right vertically, add padding in add more previews.

This commit is contained in:
Benoit Marty 2023-06-20 12:46:24 +02:00 committed by Benoit Marty
parent a2615a6408
commit ee033a2aa4

View file

@ -17,6 +17,7 @@
package io.element.android.libraries.designsystem.components.preferences package io.element.android.libraries.designsystem.components.preferences
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@ -26,7 +27,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.progressSemantics import androidx.compose.foundation.progressSemantics
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.BugReport import androidx.compose.material.icons.filled.BugReport
@ -69,7 +69,8 @@ fun PreferenceText(
.padding(vertical = preferencePaddingVertical) .padding(vertical = preferencePaddingVertical)
) { ) {
PreferenceIcon(icon = icon, tintColor = tintColor) PreferenceIcon(icon = icon, tintColor = tintColor)
Column(modifier = Modifier Column(
modifier = Modifier
.weight(1f) .weight(1f)
.align(Alignment.CenterVertically) .align(Alignment.CenterVertically)
) { ) {
@ -92,15 +93,24 @@ fun PreferenceText(
} }
} }
if (currentValue != null) { if (currentValue != null) {
Text(currentValue, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.secondary) Text(
Spacer(Modifier.width(16.dp)) modifier = Modifier
.align(Alignment.CenterVertically)
.padding(horizontal = 16.dp),
text = currentValue,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.secondary,
)
} else if (loadingCurrentValue) { } else if (loadingCurrentValue) {
CircularProgressIndicator(modifier = Modifier CircularProgressIndicator(
modifier = Modifier
.progressSemantics() .progressSemantics()
.size(20.dp), strokeWidth = 2.dp) .padding(horizontal = 16.dp)
Spacer(Modifier.width(16.dp)) .size(20.dp)
.align(Alignment.CenterVertically),
strokeWidth = 2.dp
)
} }
} }
} }
} }
@ -111,9 +121,39 @@ internal fun PreferenceTextPreview() = ElementThemedPreview { ContentToPreview()
@Composable @Composable
private fun ContentToPreview() { private fun ContentToPreview() {
Column(
verticalArrangement = Arrangement.spacedBy(2.dp)
) {
PreferenceText(
title = "Title",
icon = Icons.Default.BugReport,
)
PreferenceText( PreferenceText(
title = "Title", title = "Title",
subtitle = "Some content", subtitle = "Some content",
icon = Icons.Default.BugReport, icon = Icons.Default.BugReport,
) )
PreferenceText(
title = "Title",
subtitle = "Some content",
icon = Icons.Default.BugReport,
currentValue = "123",
)
PreferenceText(
title = "Title",
subtitle = "Some content",
icon = Icons.Default.BugReport,
loadingCurrentValue = true,
)
PreferenceText(
title = "Title",
icon = Icons.Default.BugReport,
currentValue = "123",
)
PreferenceText(
title = "Title",
icon = Icons.Default.BugReport,
loadingCurrentValue = true,
)
}
} }