From 57238fa5ca9a88c65106555fb4cf37c26bf5dd90 Mon Sep 17 00:00:00 2001 From: Noah Bond Date: Mon, 28 Mar 2022 15:07:29 -0700 Subject: [PATCH] For #24467 - Enable Contile setting telemetry --- .../compose/list/ExpandableListHeader.kt | 110 +++++++++++++----- 1 file changed, 84 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/compose/list/ExpandableListHeader.kt b/app/src/main/java/org/mozilla/fenix/compose/list/ExpandableListHeader.kt index a34e3d5da..dae89f85b 100644 --- a/app/src/main/java/org/mozilla/fenix/compose/list/ExpandableListHeader.kt +++ b/app/src/main/java/org/mozilla/fenix/compose/list/ExpandableListHeader.kt @@ -36,7 +36,9 @@ import org.mozilla.fenix.theme.FirefoxTheme * @param expandActionContentDescription The content description for expanding the section. * @param collapseActionContentDescription The content description for collapsing the section. * @param onClick Optional lambda for handling header clicks. + * @param actions Optional Composable for adding UI to the end of the header. */ +@Suppress("LongParameterList") @Composable fun ExpandableListHeader( headerText: String, @@ -44,37 +46,44 @@ fun ExpandableListHeader( expandActionContentDescription: String? = null, collapseActionContentDescription: String? = null, onClick: () -> Unit = {}, + actions: @Composable () -> Unit = {}, ) { Row( - modifier = Modifier - .fillMaxWidth() - .clickable(onClick = onClick) - .padding(horizontal = 16.dp, vertical = 8.dp), - verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.fillMaxWidth(), ) { - PrimaryText( - text = headerText, - fontSize = 14.sp, - fontFamily = FontFamily(Font(R.font.metropolis_semibold)), - maxLines = 1, - ) - - expanded?.let { - Spacer(modifier = Modifier.width(8.dp)) - - Icon( - painter = painterResource( - if (expanded) R.drawable.ic_chevron_down else R.drawable.ic_chevron_up - ), - contentDescription = if (expanded) { - collapseActionContentDescription - } else { - expandActionContentDescription - }, - modifier = Modifier.size(20.dp), - tint = FirefoxTheme.colors.iconPrimary, + Row( + modifier = Modifier + .weight(1f) + .clickable(onClick = onClick) + .padding(horizontal = 16.dp, vertical = 8.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + PrimaryText( + text = headerText, + fontSize = 14.sp, + fontFamily = FontFamily(Font(R.font.metropolis_semibold)), + maxLines = 1, ) + + expanded?.let { + Spacer(modifier = Modifier.width(8.dp)) + + Icon( + painter = painterResource( + if (expanded) R.drawable.ic_chevron_down else R.drawable.ic_chevron_up + ), + contentDescription = if (expanded) { + collapseActionContentDescription + } else { + expandActionContentDescription + }, + modifier = Modifier.size(20.dp), + tint = FirefoxTheme.colors.iconPrimary, + ) + } } + + actions() } } @@ -103,3 +112,52 @@ private fun CollapsibleHeaderPreview() { } } } + +@Composable +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) +private fun HeaderWithClickableIconPreview() { + FirefoxTheme { + Box(Modifier.background(FirefoxTheme.colors.layer1)) { + ExpandableListHeader(headerText = "Section title") { + Box( + modifier = Modifier + .clickable(onClick = { println("delete clicked") }) + .padding(horizontal = 16.dp, vertical = 8.dp), + ) { + Icon( + painter = painterResource(R.drawable.ic_delete), + contentDescription = "click me", + modifier = Modifier.size(20.dp), + tint = FirefoxTheme.colors.iconPrimary, + ) + } + } + } + } +} + +@Composable +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) +private fun CollapsibleHeaderWithClickableIconPreview() { + FirefoxTheme { + Box(Modifier.background(FirefoxTheme.colors.layer1)) { + ExpandableListHeader( + headerText = "Section title", + expanded = true, + ) { + Box( + modifier = Modifier + .clickable(onClick = { println("delete clicked") }) + .padding(horizontal = 16.dp, vertical = 8.dp), + ) { + Icon( + painter = painterResource(R.drawable.ic_delete), + contentDescription = "click me", + modifier = Modifier.size(20.dp), + tint = FirefoxTheme.colors.iconPrimary, + ) + } + } + } + } +}