Skip to content
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

Fix title overflow and replace switch #5310

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
Expand All @@ -20,6 +21,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import net.mullvad.mullvadvpn.compose.component.SpacedColumn
Expand Down Expand Up @@ -54,9 +56,9 @@ private fun PreviewBaseCell() {
@Composable
internal fun BaseCell(
modifier: Modifier = Modifier,
iconView: @Composable () -> Unit = {},
title: @Composable () -> Unit,
bodyView: @Composable () -> Unit = {},
iconView: @Composable RowScope.() -> Unit = {},
title: @Composable RowScope.() -> Unit,
bodyView: @Composable ColumnScope.() -> Unit = {},
isRowEnabled: Boolean = true,
onCellClicked: () -> Unit = {},
background: Color = MaterialTheme.colorScheme.primary,
Expand All @@ -82,8 +84,6 @@ internal fun BaseCell(

title()

Spacer(modifier = Modifier.weight(1.0f))

Column(modifier = Modifier.wrapContentWidth().wrapContentHeight()) { bodyView() }
}
}
Expand All @@ -93,14 +93,16 @@ internal fun BaseCellTitle(
title: String,
style: TextStyle,
modifier: Modifier = Modifier,
textAlign: TextAlign = TextAlign.Center
textAlign: TextAlign = TextAlign.Start
) {
Text(
text = title,
textAlign = textAlign,
style = style,
color = MaterialTheme.colorScheme.onPrimary,
modifier = modifier.wrapContentWidth(align = Alignment.End).wrapContentHeight()
overflow = TextOverflow.Ellipsis,
maxLines = 1,
modifier = modifier
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fun ExpandableComposeCell(
BaseCellTitle(
title = title,
style = MaterialTheme.typography.titleMedium,
modifier = titleModifier
modifier = titleModifier.weight(1f, fill = true)
)
},
bodyView = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fun InformationComposeCell(
BaseCellTitle(
title = title,
style = MaterialTheme.typography.titleMedium,
modifier = titleModifier
modifier = titleModifier.weight(1f, true)
)
},
background = background,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import androidx.compose.foundation.layout.wrapContentWidth as wrapContentWidth1
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.constant.MTU_MAX_VALUE
Expand All @@ -30,7 +28,7 @@ fun MtuComposeCell(
val titleModifier = Modifier

BaseCell(
title = { MtuTitle(modifier = titleModifier) },
title = { MtuTitle(modifier = titleModifier.weight(1f, true)) },
bodyView = { MtuBodyView(mtuValue = mtuValue, modifier = titleModifier) },
onCellClicked = { onEditMtu.invoke() }
)
Expand All @@ -40,10 +38,9 @@ fun MtuComposeCell(
private fun MtuTitle(modifier: Modifier) {
Text(
text = stringResource(R.string.wireguard_mtu),
textAlign = TextAlign.Center,
style = MaterialTheme.typography.titleMedium,
color = MaterialTheme.colorScheme.onPrimary,
modifier = modifier.wrapContentWidth1(align = Alignment.End).wrapContentHeight()
modifier = modifier
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,46 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.Dimens

@Preview
@Composable
private fun PreviewNavigationCell() {
NavigationComposeCell(
title = "Navigation sample",
bodyView = {
NavigationCellBody(
contentBodyDescription = "",
content = "content body",
contentColor = MaterialTheme.colorScheme.error,
)
},
onClick = {},
showWarning = true
)
AppTheme {
NavigationComposeCell(
title = "Navigation sample",
bodyView = {
NavigationCellBody(
contentBodyDescription = "",
content = "content body",
contentColor = MaterialTheme.colorScheme.error,
)
},
onClick = {},
showWarning = true
)
}
}

@Preview
@Composable
private fun PreviewExternalLinkComposeCell() {
NavigationComposeCell(
title = "External link sample",
bodyView = {
NavigationCellBody(
contentBodyDescription = "content body",
content = "content body",
contentColor = MaterialTheme.colorScheme.onSecondary,
isExternalLink = true
)
},
onClick = {},
showWarning = false
)
AppTheme {
NavigationComposeCell(
title = "External link sample",
bodyView = {
NavigationCellBody(
contentBodyDescription = "content body",
content = "content body",
contentColor = MaterialTheme.colorScheme.onSecondary,
isExternalLink = true
)
},
onClick = {},
showWarning = false
)
}
}

@Composable
Expand All @@ -66,7 +71,11 @@ fun NavigationComposeCell(
BaseCell(
onCellClicked = onClick,
title = {
NavigationTitleView(title = title, modifier = modifier, showWarning = showWarning)
NavigationTitleView(
title = title,
modifier = modifier.weight(1f, true),
showWarning = showWarning
)
},
bodyView = { bodyView() },
isRowEnabled = isRowEnabled
Expand All @@ -89,7 +98,8 @@ internal fun NavigationTitleView(
Text(
text = title,
style = MaterialTheme.typography.titleMedium,
color = MaterialTheme.colorScheme.onPrimary
color = MaterialTheme.colorScheme.onPrimary,
modifier = modifier
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.mullvad.mullvadvpn.compose.cell

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
Expand Down Expand Up @@ -36,7 +37,7 @@ fun SelectableCell(
title: String,
isSelected: Boolean,
iconContentDescription: String? = null,
selectedIcon: @Composable () -> Unit = {
selectedIcon: @Composable RowScope.() -> Unit = {
Icon(
painter = painterResource(id = R.drawable.icon_tick),
contentDescription = iconContentDescription,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.compose.cell

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentWidth
Expand All @@ -20,7 +21,7 @@ import androidx.compose.ui.unit.dp
import androidx.core.text.HtmlCompat
import androidx.core.text.HtmlCompat.FROM_HTML_MODE_COMPACT
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.component.CellSwitch
import net.mullvad.mullvadvpn.compose.component.MullvadSwitch
import net.mullvad.mullvadvpn.compose.component.SpacedColumn
import net.mullvad.mullvadvpn.compose.component.textResource
import net.mullvad.mullvadvpn.compose.extensions.toAnnotatedString
Expand Down Expand Up @@ -61,7 +62,13 @@ fun NormalSwitchComposeCell(
onInfoClicked: (() -> Unit)? = null
) {
SwitchComposeCell(
titleView = { BaseCellTitle(title = title, style = MaterialTheme.typography.labelLarge) },
titleView = {
BaseCellTitle(
title = title,
style = MaterialTheme.typography.labelLarge,
modifier = Modifier.weight(1f, true)
)
},
isToggled = isToggled,
startPadding = startPadding,
isEnabled = isEnabled,
Expand All @@ -83,7 +90,13 @@ fun HeaderSwitchComposeCell(
onInfoClicked: (() -> Unit)? = null,
) {
SwitchComposeCell(
titleView = { BaseCellTitle(title = title, style = MaterialTheme.typography.titleMedium) },
titleView = {
BaseCellTitle(
title = title,
style = MaterialTheme.typography.titleMedium,
modifier = Modifier.weight(1f, fill = true)
)
},
isToggled = isToggled,
startPadding = startPadding,
isEnabled = isEnabled,
Expand All @@ -96,7 +109,7 @@ fun HeaderSwitchComposeCell(

@Composable
private fun SwitchComposeCell(
titleView: @Composable () -> Unit,
titleView: @Composable RowScope.() -> Unit,
isToggled: Boolean,
startPadding: Dp,
isEnabled: Boolean,
Expand Down Expand Up @@ -154,7 +167,7 @@ fun SwitchCellView(
)
}

CellSwitch(isChecked = isToggled, isEnabled = isEnabled, onCheckedChange = onSwitchClicked)
MullvadSwitch(checked = isToggled, enabled = isEnabled, onCheckedChange = onSwitchClicked)
}
}

Expand Down
Loading
Loading