Skip to content

Commit

Permalink
Fix VpnSettingsScreen DPAD navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa authored and albin-mullvad committed Mar 5, 2024
1 parent 5418208 commit 4989f28
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package net.mullvad.mullvadvpn.compose.cell

import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material3.Icon
Expand All @@ -13,13 +12,14 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.core.text.HtmlCompat
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.component.ChevronView
import net.mullvad.mullvadvpn.compose.component.ChevronButton
import net.mullvad.mullvadvpn.compose.component.textResource
import net.mullvad.mullvadvpn.compose.extensions.toAnnotatedString
import net.mullvad.mullvadvpn.lib.theme.AppTheme
Expand Down Expand Up @@ -53,6 +53,7 @@ fun ExpandableComposeCell(
val bodyViewModifier = Modifier

BaseCell(
modifier = Modifier.focusProperties { canFocus = false },
title = {
BaseCellTitle(
title = title,
Expand All @@ -64,6 +65,7 @@ fun ExpandableComposeCell(
ExpandableComposeCellBody(
isExpanded = isExpanded,
modifier = bodyViewModifier,
onExpand = onCellClicked,
onInfoClicked = onInfoClicked
)
},
Expand All @@ -75,6 +77,7 @@ fun ExpandableComposeCell(
private fun ExpandableComposeCellBody(
isExpanded: Boolean,
modifier: Modifier,
onExpand: ((Boolean) -> Unit),
onInfoClicked: (() -> Unit)? = null
) {
Row(
Expand All @@ -96,9 +99,9 @@ private fun ExpandableComposeCellBody(
}
}

ChevronView(
ChevronButton(
isExpanded = isExpanded,
modifier = Modifier.size(Dimens.expandableCellChevronSize)
onExpand = onExpand,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -45,6 +46,7 @@ fun InformationComposeCell(
val bodyViewModifier = Modifier

BaseCell(
modifier = Modifier.focusProperties { canFocus = false },
title = {
BaseCellTitle(
title = title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.component.ChevronView
import net.mullvad.mullvadvpn.compose.component.Chevron
import net.mullvad.mullvadvpn.compose.component.VerticalDivider
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.Dimens
Expand Down Expand Up @@ -258,7 +258,7 @@ fun RelayLocationCell(
color = MaterialTheme.colorScheme.background,
modifier = Modifier.padding(vertical = Dimens.verticalDividerPadding)
)
ChevronView(
Chevron(
isExpanded = expanded.value,
modifier =
Modifier.fillMaxHeight()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
Expand Down Expand Up @@ -118,12 +119,12 @@ private fun SwitchComposeCell(
modifier: Modifier = Modifier,
) {
BaseCell(
modifier = modifier,
modifier = modifier.focusProperties { canFocus = false },
title = titleView,
isRowEnabled = isEnabled,
bodyView = {
SwitchCellView(
onSwitchClicked = null,
onSwitchClicked = onCellClicked,
isEnabled = isEnabled,
isToggled = isToggled,
onInfoClicked = onInfoClicked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.TweenSpec
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
Expand All @@ -15,12 +16,11 @@ import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.lib.theme.color.AlphaChevron

@Composable
fun ChevronView(
fun Chevron(
modifier: Modifier = Modifier,
color: Color = MaterialTheme.colorScheme.onBackground.copy(alpha = AlphaChevron),
isExpanded: Boolean
) {
val resourceId = R.drawable.icon_chevron

val degree = remember(isExpanded) { if (isExpanded) 270f else 90f }
val animatedRotation =
Expand All @@ -31,9 +31,21 @@ fun ChevronView(
)

Icon(
painterResource(id = resourceId),
painterResource(id = R.drawable.icon_chevron),
contentDescription = null,
tint = color,
modifier = modifier.rotate(animatedRotation.value),
)
}

@Composable
fun ChevronButton(
modifier: Modifier = Modifier,
color: Color = MaterialTheme.colorScheme.onBackground.copy(alpha = AlphaChevron),
onExpand: (Boolean) -> Unit,
isExpanded: Boolean
) {
IconButton(modifier = modifier, onClick = { onExpand(!isExpanded) }) {
Chevron(isExpanded = isExpanded, color = color)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fun LocationInfo(
},
style = MaterialTheme.typography.labelLarge.copy(fontWeight = FontWeight.SemiBold)
)
ChevronView(
Chevron(
isExpanded = isExpanded,
color =
if (isExpanded) {
Expand Down

0 comments on commit 4989f28

Please sign in to comment.