-
Notifications
You must be signed in to change notification settings - Fork 5
ANDROID-17239 Compose MediaCard imagePosition left/right #481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
3661174
65c9549
c4a307d
11e66ac
0f7ee08
21c9364
cedc726
f9483b5
034a54f
fd38e57
4ad3813
1dbece7
687c1f5
9dbd2d4
b1540bf
3abaa55
4df2ff4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,6 @@ import androidx.compose.foundation.layout.Box | |
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.IntrinsicSize | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.offset | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.width | ||
| import androidx.compose.foundation.layout.widthIn | ||
|
|
@@ -21,11 +20,13 @@ import com.telefonica.mistica.compose.button.Button | |
| import com.telefonica.mistica.compose.button.ButtonStyle | ||
| import com.telefonica.mistica.compose.tag.Tag | ||
| import com.telefonica.mistica.compose.theme.MisticaTheme | ||
| import com.telefonica.mistica.util.applyLinkTextFix | ||
|
|
||
| @Composable | ||
| fun Card( | ||
| public fun Card( | ||
| modifier: Modifier = Modifier, | ||
| header: @Composable () -> Unit = {}, | ||
| invalidatePaddings: Boolean = false, | ||
| content: @Composable () -> Unit = {}, | ||
| ) { | ||
|
|
||
|
|
@@ -41,12 +42,16 @@ fun Card( | |
| Column { | ||
| header() | ||
| Column( | ||
| modifier = Modifier.padding( | ||
| start = 16.dp, | ||
| top = 16.dp, | ||
| end = 16.dp, | ||
| bottom = 24.dp, | ||
| ), | ||
| modifier = if (!invalidatePaddings) | ||
| Modifier.padding( | ||
| start = 16.dp, | ||
| top = 16.dp, | ||
| end = 16.dp, | ||
| bottom = 24.dp, | ||
| ) | ||
| else { | ||
| Modifier | ||
| }, | ||
| ) { | ||
| content() | ||
| } | ||
|
|
@@ -55,30 +60,32 @@ fun Card( | |
| } | ||
|
|
||
| @Composable | ||
| internal fun CardActions(primaryButton: Action?, linkButton: Action?) { | ||
| internal fun CardActions( | ||
| primaryButton: Action?, | ||
| linkButton: Action?, | ||
| orientation: CardActionsOrientation = CardActionsOrientation.Horizontal, | ||
| ) { | ||
| if (primaryButton != null || linkButton != null) { | ||
| Row( | ||
| modifier = Modifier | ||
| .padding(top = 16.dp) | ||
| .width(IntrinsicSize.Max), | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| horizontalArrangement = Arrangement.Start, | ||
|
|
||
| ) { | ||
| primaryButton?.let { | ||
| Button( | ||
| text = it.text, | ||
| onClickListener = it.onTapped, | ||
| buttonStyle = ButtonStyle.PRIMARY_SMALL, | ||
| ) | ||
| when (orientation) { | ||
| CardActionsOrientation.Horizontal -> { | ||
| Row( | ||
| modifier = Modifier | ||
| .padding(top = 16.dp) | ||
| .width(IntrinsicSize.Max), | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| horizontalArrangement = Arrangement.Start, | ||
| ) { | ||
| CardActionButtons(primaryButton, linkButton, orientation) | ||
| } | ||
| } | ||
| linkButton?.let { | ||
| Button( | ||
| modifier = if (primaryButton == null) Modifier.offset(x = (-8).dp) else Modifier, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now we can use invalidatePaddings and invalidateMinWidth so the |
||
| text = it.text, | ||
| onClickListener = it.onTapped, | ||
| buttonStyle = ButtonStyle.LINK, | ||
| ) | ||
| CardActionsOrientation.Vertical -> { | ||
| Column( | ||
| modifier = Modifier.padding(top = 16.dp), | ||
| verticalArrangement = Arrangement.spacedBy(8.dp), | ||
| horizontalAlignment = Alignment.Start, | ||
| ) { | ||
| CardActionButtons(primaryButton, linkButton, orientation) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -135,7 +142,42 @@ internal fun CardContent( | |
| } | ||
| } | ||
|
|
||
| data class Action( | ||
| @Composable | ||
| private fun CardActionButtons( | ||
| primaryButton: Action?, | ||
| linkButton: Action?, | ||
| orientation: CardActionsOrientation, | ||
| ) { | ||
| primaryButton?.let { | ||
| Button( | ||
| text = it.text, | ||
| onClickListener = it.onTapped, | ||
| buttonStyle = ButtonStyle.PRIMARY_SMALL, | ||
| ) | ||
| } | ||
| linkButton?.let { | ||
| Button( | ||
| modifier = if (primaryButton != null && orientation == CardActionsOrientation.Horizontal) { | ||
| Modifier.padding(start = 16.dp) | ||
| } else { | ||
| Modifier | ||
| }, | ||
| text = it.text.applyLinkTextFix(), | ||
| onClickListener = it.onTapped, | ||
| buttonStyle = ButtonStyle.LINK, | ||
| invalidatePaddings = true, | ||
| invalidateMinWidth = true, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| public enum class CardActionsOrientation { | ||
| Horizontal, | ||
| Vertical, | ||
| } | ||
|
|
||
| public data class Action( | ||
| val text: String, | ||
| val onTapped: () -> Unit, | ||
| ) | ||
jeprubio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ import com.telefonica.mistica.compose.button.Button | |
| import com.telefonica.mistica.compose.button.ButtonStyle | ||
| import com.telefonica.mistica.compose.theme.MisticaTheme | ||
| import androidx.compose.ui.platform.LocalResources | ||
| import com.telefonica.mistica.util.applyLinkTextFix | ||
|
|
||
| @Composable | ||
| fun HighLightedCard( | ||
|
|
@@ -229,7 +230,7 @@ private fun HighLightCardButton( | |
| val isLink = buttonStyle == ButtonStyle.LINK || buttonStyle == ButtonStyle.LINK_INVERSE | ||
| Button( | ||
| modifier = modifier, | ||
| text = if (isLink) applyLinkTextFix(buttonConfig.buttonText) else buttonConfig.buttonText, | ||
| text = if (isLink) buttonConfig.buttonText.applyLinkTextFix() else buttonConfig.buttonText, | ||
| buttonStyle = buttonStyle, | ||
| invalidatePaddings = isLink, | ||
| invalidateMinWidth = isLink, | ||
|
|
@@ -241,9 +242,6 @@ private fun HighLightCardButton( | |
| } | ||
| } | ||
|
|
||
| private fun applyLinkTextFix(text: String): String { | ||
| return text.padEnd(18, ' ') | ||
| } | ||
|
Comment on lines
-244
to
-246
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to an extension and reused in the MediaCard |
||
|
|
||
| enum class HighLightCardImageConfig { | ||
| FIT, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.