Skip to content
Snippets Groups Projects
Commit 8ca4e9a8 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Make the SettingsCard clickable

Default behavior not changed, which not clickable.

Bug: 305856149
Test: manual - with gallery
Test: unit test
Change-Id: I0c301913e9643a02ee8bc7a78a70cb77fcd89f9a
parent ee646bd8
No related branches found
No related tags found
No related merge requests found
......@@ -88,11 +88,13 @@ object CardPageProvider : SettingsPageProvider {
@Composable
private fun SettingsCardWithoutIcon() {
val sampleTitle = stringResource(R.string.sample_title)
var title by remember { mutableStateOf(sampleTitle) }
SettingsCard(
CardModel(
title = stringResource(R.string.sample_title),
title = title,
text = stringResource(R.string.sample_text),
)
) { title = "Clicked" }
)
}
......
......@@ -45,4 +45,6 @@ data class CardModel(
/** If specified, this color will be used to tint the icon and the buttons. */
val containerColor: Color = Color.Unspecified,
val onClick: (() -> Unit)? = null,
)
......@@ -17,6 +17,7 @@
package com.android.settingslib.spa.widget.card
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
......@@ -102,10 +103,11 @@ internal fun SettingsCardImpl(model: CardModel) {
AnimatedVisibility(visible = model.isVisible()) {
SettingsCardContent(containerColor = model.containerColor) {
Column(
modifier = Modifier.padding(
horizontal = SettingsDimension.dialogItemPaddingHorizontal,
vertical = SettingsDimension.itemPaddingAround,
),
modifier = (model.onClick?.let { Modifier.clickable(onClick = it) } ?: Modifier)
.padding(
horizontal = SettingsDimension.dialogItemPaddingHorizontal,
vertical = SettingsDimension.itemPaddingAround,
),
verticalArrangement = Arrangement.spacedBy(SettingsDimension.itemPaddingAround)
) {
CardHeader(model.imageVector, model.tintColor, model.onDismiss)
......
......@@ -141,6 +141,23 @@ class SettingsCardTest {
composeTestRule.onNodeWithText(TEXT).isNotDisplayed()
}
@Test
fun settingsCard_clickable() {
var clicked by mutableStateOf(false)
composeTestRule.setContent {
SettingsCard(
CardModel(
title = TITLE,
text = "",
) { clicked = true }
)
}
composeTestRule.onNodeWithText(TITLE).performClick()
assertThat(clicked).isTrue()
}
private companion object {
const val TITLE = "Title"
const val TEXT = "Text"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment