From 1126b5f4254d73652a57ef68a22521e8a13510fd Mon Sep 17 00:00:00 2001 From: LooKeR Date: Thu, 10 Mar 2022 00:12:19 +0530 Subject: [PATCH] Update Compose Version and Create Chip Row in Compose --- build.gradle | 16 +++---- .../looker/droidify/ui/compose/utils/Card.kt | 8 ++-- .../looker/droidify/ui/compose/utils/Chip.kt | 48 +++++++++++++++++++ 3 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 src/main/kotlin/com/looker/droidify/ui/compose/utils/Chip.kt diff --git a/build.gradle b/build.gradle index 861d9059..b86cd406 100644 --- a/build.gradle +++ b/build.gradle @@ -49,7 +49,7 @@ android { } composeOptions { - kotlinCompilerExtensionVersion "1.2.0-alpha01" + kotlinCompilerExtensionVersion "1.2.0-alpha05" } buildTypes { @@ -167,13 +167,13 @@ dependencies { kapt 'androidx.room:room-compiler:2.4.2' // Compose - implementation "androidx.compose.runtime:runtime:1.2.0-alpha04" - implementation "androidx.compose.ui:ui:1.2.0-alpha04" - implementation "androidx.compose.ui:ui-tooling:1.2.0-alpha04" - implementation "androidx.compose.foundation:foundation:1.2.0-alpha04" - implementation "androidx.compose.runtime:runtime-livedata:1.2.0-alpha04" - implementation "androidx.compose.material3:material3:1.0.0-alpha06" - implementation "androidx.compose.material:material:1.2.0-alpha04" + implementation "androidx.compose.runtime:runtime:1.2.0-alpha05" + implementation "androidx.compose.ui:ui:1.2.0-alpha05" + implementation "androidx.compose.ui:ui-tooling:1.2.0-alpha05" + implementation "androidx.compose.foundation:foundation:1.2.0-alpha05" + implementation "androidx.compose.runtime:runtime-livedata:1.2.0-alpha05" + implementation "androidx.compose.material3:material3:1.0.0-alpha07" + implementation "androidx.compose.material:material:1.2.0-alpha05" implementation "com.google.android.material:compose-theme-adapter:1.1.5" } diff --git a/src/main/kotlin/com/looker/droidify/ui/compose/utils/Card.kt b/src/main/kotlin/com/looker/droidify/ui/compose/utils/Card.kt index 3a325876..09265413 100644 --- a/src/main/kotlin/com/looker/droidify/ui/compose/utils/Card.kt +++ b/src/main/kotlin/com/looker/droidify/ui/compose/utils/Card.kt @@ -1,7 +1,6 @@ package com.looker.droidify.ui.compose.utils import androidx.compose.animation.* -import androidx.compose.animation.core.animateDpAsState import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Box @@ -19,7 +18,6 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color -import androidx.compose.ui.unit.dp import com.looker.droidify.ui.compose.theme.LocalShapes @OptIn(ExperimentalFoundationApi::class) @@ -34,8 +32,9 @@ fun ExpandableCard( mainContent: @Composable () -> Unit ) { var expanded by rememberSaveable { mutableStateOf(preExpanded) } - val cardElevation by animateDpAsState(targetValue = if (expanded) 12.dp else 0.dp) - val background by animateColorAsState(targetValue = backgroundColor) + val background by animateColorAsState( + targetValue = if (expanded) MaterialTheme.colorScheme.surfaceVariant else backgroundColor + ) Surface( modifier = Modifier @@ -45,7 +44,6 @@ fun ExpandableCard( onClick = onClick, onLongClick = { expanded = !expanded } ), - tonalElevation = cardElevation, color = background ) { Box(modifier = modifier, contentAlignment = Alignment.CenterStart) { diff --git a/src/main/kotlin/com/looker/droidify/ui/compose/utils/Chip.kt b/src/main/kotlin/com/looker/droidify/ui/compose/utils/Chip.kt new file mode 100644 index 00000000..bf2bd3ba --- /dev/null +++ b/src/main/kotlin/com/looker/droidify/ui/compose/utils/Chip.kt @@ -0,0 +1,48 @@ +package com.looker.droidify.ui.compose.utils + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.lazy.LazyRow +import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.Chip +import androidx.compose.material.ChipColors +import androidx.compose.material.ChipDefaults +import androidx.compose.material.ExperimentalMaterialApi +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Shape +import androidx.compose.ui.unit.dp + +@OptIn(ExperimentalMaterialApi::class) +@Composable +fun ChipRow( + modifier: Modifier = Modifier, + list: List, + chipColors: ChipColors = ChipDefaults.chipColors( + backgroundColor = MaterialTheme.colorScheme.surface, + contentColor = MaterialTheme.colorScheme.primary.copy(alpha = ChipDefaults.ContentOpacity), + ), + shapes: Shape = RoundedCornerShape(50), + onClick: (String) -> Unit +) { + LazyRow( + modifier = modifier, + horizontalArrangement = Arrangement.spacedBy(8.dp) + ) { + items(list) { + Chip( + shape = shapes, + colors = chipColors, + onClick = { onClick(it) } + ) { + Text( + text = it, + style = MaterialTheme.typography.labelLarge, + color = MaterialTheme.colorScheme.primary.copy(alpha = ChipDefaults.ContentOpacity) + ) + } + } + } +} \ No newline at end of file