Skip to content

Commit

Permalink
ANDROID-14792 Update. Compose UI version and migrate errors from upda…
Browse files Browse the repository at this point in the history
…ting
  • Loading branch information
haynlo committed Dec 17, 2024
1 parent e2b6fa1 commit 730a646
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 47 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
ext {
min_sdk_version = 24
target_sdk_version = 34
compose_ui_version = "1.5.4"
compose_ui_version = "1.7.6"
compose_compiler_version = '1.5.7'
kotlin_version = "1.9.21"
androidx_appcompat_version = "1.6.0"
Expand Down
1 change: 1 addition & 0 deletions catalog/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dependencies {
implementation 'androidx.activity:activity-compose:1.4.0'
implementation "androidx.navigation:navigation-compose:2.5.3"
implementation "androidx.compose.material:material:$compose_ui_version"
implementation("androidx.compose.material:material-icons-extended:$compose_ui_version")
implementation "androidx.compose.ui:ui:$compose_ui_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"

Expand Down
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ dependencies {
implementation "androidx.constraintlayout:constraintlayout-compose:$constraintComposeVersion"

implementation "androidx.compose.material:material:$compose_ui_version"
implementation("androidx.compose.material:material-icons-extended:$compose_ui_version")
implementation "androidx.compose.ui:ui:$compose_ui_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.ContentAlpha
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.LocalContentAlpha
import androidx.compose.material.LocalRippleConfiguration
import androidx.compose.material.Text
import androidx.compose.material.ripple.LocalRippleTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -55,6 +56,7 @@ private val iconSpacing = 10.dp
private val easing = CubicBezierEasing(0.77f, 0f, 0.175f, 1f)
private const val CHEVRON_ASPECT_RATIO = 8f / 20f

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun Button(
modifier: Modifier = Modifier,
Expand All @@ -78,7 +80,7 @@ fun Button(

var originalWidth: Dp? by remember { mutableStateOf(null) }

CompositionLocalProvider(LocalRippleTheme provides style.rippleTheme) {
CompositionLocalProvider(LocalRippleConfiguration provides style.rippleConfiguration) {
androidx.compose.material.Button(
modifier = modifier
.defaultMinSize(size.minWidth, size.height)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
@file:OptIn(ExperimentalMaterialApi::class) // Required for RippleConfiguration usage

package com.telefonica.mistica.compose.button

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.ButtonColors
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.RippleConfiguration
import androidx.compose.material.RippleDefaults
import androidx.compose.material.ripple.RippleAlpha
import androidx.compose.material.ripple.RippleTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.dimensionResource
Expand All @@ -18,21 +22,12 @@ internal class ButtonStyleConfig(
val disabledTextColor: Color = textColor,
val border: BorderStroke? = null,
val disabledBorder: BorderStroke? = null,
val rippleTheme: MisticaRippleTheme
val rippleConfiguration: RippleConfiguration,
)

class MisticaRippleTheme(
private val color: Color,
private val alpha: RippleAlpha? = null
) : RippleTheme {

@Composable
override fun defaultColor(): Color = color

@Composable
override fun rippleAlpha(): RippleAlpha = alpha ?: RippleTheme.defaultRippleAlpha(color, !isSystemInDarkTheme())

}
@Composable
private fun getMisticaRippleConfiguration(color: Color, alpha: RippleAlpha? = null) =
RippleConfiguration(color, alpha ?: RippleDefaults.rippleAlpha(color, !isSystemInDarkTheme()))

@Composable
@Suppress("CyclomaticComplexMethod")
Expand Down Expand Up @@ -65,12 +60,12 @@ private fun primary(
),
textColor: Color = MisticaTheme.colors.textButtonPrimary,
disabledTextColor: Color = textColor.disabled(),
rippleTheme: MisticaRippleTheme = MisticaRippleTheme(MisticaTheme.colors.buttonPrimaryBackgroundPressed),
rippleConfiguration: RippleConfiguration = getMisticaRippleConfiguration(MisticaTheme.colors.buttonPrimaryBackgroundPressed),
) = ButtonStyleConfig(
buttonColors = buttonColors,
textColor = textColor,
disabledTextColor = disabledTextColor,
rippleTheme = rippleTheme
rippleConfiguration = rippleConfiguration,
)

@Composable
Expand All @@ -81,14 +76,14 @@ private fun primaryInverse() = primary(
),
textColor = MisticaTheme.colors.textButtonPrimaryInversePressed,
disabledTextColor = MisticaTheme.colors.textButtonPrimaryInverse,
rippleTheme = MisticaRippleTheme(MisticaTheme.colors.buttonPrimaryBackgroundInversePressed),
rippleConfiguration = getMisticaRippleConfiguration(MisticaTheme.colors.buttonPrimaryBackgroundInversePressed),
)

@Composable
private fun secondary(
textColor: Color = MisticaTheme.colors.textButtonSecondary,
strokeColor: Color = MisticaTheme.colors.buttonSecondaryBorder,
rippleTheme: MisticaRippleTheme = MisticaRippleTheme(MisticaTheme.colors.buttonSecondaryBackgroundPressed)
rippleConfiguration: RippleConfiguration = getMisticaRippleConfiguration(MisticaTheme.colors.buttonSecondaryBackgroundPressed)
) = ButtonStyleConfig(
buttonColors = ButtonDefaults.outlinedButtonColors(
backgroundColor = Color.Transparent,
Expand All @@ -105,15 +100,16 @@ private fun secondary(
dimensionResource(R.dimen.button_outline_stroke_width),
strokeColor.disabled()
),
rippleTheme = rippleTheme
rippleConfiguration = rippleConfiguration
)


@Composable
private fun secondaryInverseConfig() =
secondary(
textColor = MisticaTheme.colors.textButtonSecondaryInverse,
strokeColor = MisticaTheme.colors.buttonSecondaryBorderInverse,
rippleTheme = MisticaRippleTheme(MisticaTheme.colors.buttonSecondaryBackgroundInversePressed)
rippleConfiguration = getMisticaRippleConfiguration(MisticaTheme.colors.buttonSecondaryBackgroundInversePressed)
)

@Composable
Expand All @@ -122,7 +118,7 @@ private fun danger() = primary(
backgroundColor = MisticaTheme.colors.buttonDangerBackground,
disabledBackgroundColor = MisticaTheme.colors.buttonDangerBackground.disabled()
),
rippleTheme = MisticaRippleTheme(MisticaTheme.colors.buttonDangerBackgroundPressed)
rippleConfiguration = getMisticaRippleConfiguration(MisticaTheme.colors.buttonDangerBackgroundPressed)
)

@Composable
Expand All @@ -135,7 +131,7 @@ private fun link(
),
textColor = textColor,
disabledTextColor = textColor.disabled(),
rippleTheme = MisticaRippleTheme(MisticaTheme.colors.buttonLinkBackgroundPressed),
rippleConfiguration = getMisticaRippleConfiguration(MisticaTheme.colors.buttonLinkBackgroundPressed),
)

@Composable
Expand All @@ -156,7 +152,7 @@ private fun dangerLink(
),
textColor = textColor,
disabledTextColor = textColor.disabled(),
rippleTheme = MisticaRippleTheme(selectedBackgroundColor),
rippleConfiguration = getMisticaRippleConfiguration(selectedBackgroundColor),
)

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ fun HighLightedCard(
onClick = onCloseButton
) {
Icon(
imageVector = Icons.Default.Close,
imageVector = Icons.Filled.Close,
contentDescription = null,
tint = MisticaTheme.colors.neutralHigh
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.width
import androidx.compose.material.Checkbox
import androidx.compose.material.CheckboxDefaults
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.LocalMinimumInteractiveComponentEnforcement
import androidx.compose.material.LocalMinimumTouchTargetEnforcement
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.telefonica.mistica.compose.theme.MisticaTheme
import com.telefonica.mistica.compose.ui.alpha

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun CheckBoxInput(
text: String,
Expand All @@ -33,22 +28,20 @@ fun CheckBoxInput(
modifier = modifier.alpha(enabled)
) {
Row {
CompositionLocalProvider(LocalMinimumInteractiveComponentEnforcement provides false) {
Checkbox(
checked = checked,
onCheckedChange = onCheckedChange,
enabled = enabled,
colors = CheckboxDefaults.colors(
checkedColor = MisticaTheme.colors.controlActivated,
uncheckedColor = MisticaTheme.colors.control,
disabledColor = if (checked) {
MisticaTheme.colors.controlActivated
} else {
MisticaTheme.colors.control
}
)
Checkbox(
checked = checked,
onCheckedChange = onCheckedChange,
enabled = enabled,
colors = CheckboxDefaults.colors(
checkedColor = MisticaTheme.colors.controlActivated,
uncheckedColor = MisticaTheme.colors.control,
disabledColor = if (checked) {
MisticaTheme.colors.controlActivated
} else {
MisticaTheme.colors.control
}
)
}
)
Spacer(modifier = Modifier.width(8.dp))
TextWithLinks(text, links)
}
Expand Down

0 comments on commit 730a646

Please sign in to comment.