Skip to content

Commit

Permalink
wip 2
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX committed Oct 16, 2024
1 parent f86afeb commit e5c61c8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.infomaniak.swisstransfer.ui.components

import android.content.res.Configuration
import androidx.annotation.StringRes
import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
Expand All @@ -44,8 +45,9 @@ fun LargeButton(
enabled: () -> Boolean = { true },
onClick: () -> Unit,
imageVector: ImageVector? = null,
animatedEnabling: Boolean = false,
) {
CoreButton(titleRes, modifier, ButtonSize.LARGE, style, enabled, onClick, imageVector)
CoreButton(titleRes, modifier, ButtonSize.LARGE, style, enabled, onClick, imageVector, animatedEnabling)
}

@Composable
Expand All @@ -57,7 +59,7 @@ fun SmallButton(
onClick: () -> Unit,
imageVector: ImageVector? = null,
) {
CoreButton(titleRes, modifier, ButtonSize.SMALL, style, enabled, onClick, imageVector)
CoreButton(titleRes, modifier, ButtonSize.SMALL, style, enabled, onClick, imageVector, false)
}

@Composable
Expand All @@ -69,12 +71,30 @@ private fun CoreButton(
enabled: () -> Boolean,
onClick: () -> Unit,
imageVector: ImageVector?,
animatedEnabling: Boolean,
) {
val isEnabled = enabled()
val animatedColor = animateColorAsState(if (isEnabled) Color.Green else Color.Red )

val buttonColors = if (animatedEnabling) {

val defaultColors = style.buttonColors()
val (container, content) = if (isEnabled) defaultColors.containerColor to defaultColors.contentColor else defaultColors.disabledContainerColor to defaultColors.disabledContentColor
ButtonDefaults.buttonColors(
containerColor = container,
contentColor = content,
disabledContainerColor = container,
disabledContentColor = content,
)
} else {
style.buttonColors()
}

Button(
modifier = modifier.height(buttonSize.height),
colors = style.buttonColors(),
colors = buttonColors,
shape = Shapes.medium,
enabled = enabled(),
enabled = isEnabled,
onClick = onClick,
) {
imageVector?.let {
Expand Down Expand Up @@ -126,7 +146,7 @@ private fun LargeButtonPreview() {
Column {
ButtonType.entries.forEach {
Row {
LargeButton(titleRes = R.string.appName, style = it, imageVector = AppIcons.Add, onClick = {})
LargeButton(titleRes = R.string.appName, style = it, onClick = {}, imageVector = AppIcons.Add)
Spacer(modifier = Modifier.width(Margin.Small))
SmallButton(titleRes = R.string.appName, style = it, imageVector = AppIcons.Add, onClick = {})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ private fun BottomSheetDefaultsPreview() {
},
topButton = {
LargeButton(
modifier = it,
titleRes = R.string.appName,
modifier = it,
style = ButtonType.ERROR,
onClick = {},
)
},
bottomButton = {
LargeButton(
modifier = it,
titleRes = R.string.appName,
modifier = it,
style = ButtonType.TERTIARY,
onClick = {},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ private fun ImportFilesScreen(
titleRes = R.string.transferSendButton,
style = ButtonType.PRIMARY,
enabled = { isSendButtonEnabled },
animatedEnabling = true,
onClick = { /*TODO*/ },
)
},
Expand Down

0 comments on commit e5c61c8

Please sign in to comment.