Skip to content

Commit 4989f28

Browse files
Rawaalbin-mullvad
authored andcommitted
Fix VpnSettingsScreen DPAD navigation
1 parent 5418208 commit 4989f28

File tree

6 files changed

+30
-12
lines changed

6 files changed

+30
-12
lines changed

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/ExpandableComposeCell.kt

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package net.mullvad.mullvadvpn.compose.cell
22

33
import androidx.compose.foundation.layout.Row
44
import androidx.compose.foundation.layout.padding
5-
import androidx.compose.foundation.layout.size
65
import androidx.compose.foundation.layout.wrapContentHeight
76
import androidx.compose.foundation.layout.wrapContentWidth
87
import androidx.compose.material3.Icon
@@ -13,13 +12,14 @@ import androidx.compose.runtime.Composable
1312
import androidx.compose.ui.Alignment
1413
import androidx.compose.ui.Modifier
1514
import androidx.compose.ui.draw.alpha
15+
import androidx.compose.ui.focus.focusProperties
1616
import androidx.compose.ui.res.painterResource
1717
import androidx.compose.ui.res.stringResource
1818
import androidx.compose.ui.text.font.FontWeight
1919
import androidx.compose.ui.tooling.preview.Preview
2020
import androidx.core.text.HtmlCompat
2121
import net.mullvad.mullvadvpn.R
22-
import net.mullvad.mullvadvpn.compose.component.ChevronView
22+
import net.mullvad.mullvadvpn.compose.component.ChevronButton
2323
import net.mullvad.mullvadvpn.compose.component.textResource
2424
import net.mullvad.mullvadvpn.compose.extensions.toAnnotatedString
2525
import net.mullvad.mullvadvpn.lib.theme.AppTheme
@@ -53,6 +53,7 @@ fun ExpandableComposeCell(
5353
val bodyViewModifier = Modifier
5454

5555
BaseCell(
56+
modifier = Modifier.focusProperties { canFocus = false },
5657
title = {
5758
BaseCellTitle(
5859
title = title,
@@ -64,6 +65,7 @@ fun ExpandableComposeCell(
6465
ExpandableComposeCellBody(
6566
isExpanded = isExpanded,
6667
modifier = bodyViewModifier,
68+
onExpand = onCellClicked,
6769
onInfoClicked = onInfoClicked
6870
)
6971
},
@@ -75,6 +77,7 @@ fun ExpandableComposeCell(
7577
private fun ExpandableComposeCellBody(
7678
isExpanded: Boolean,
7779
modifier: Modifier,
80+
onExpand: ((Boolean) -> Unit),
7881
onInfoClicked: (() -> Unit)? = null
7982
) {
8083
Row(
@@ -96,9 +99,9 @@ private fun ExpandableComposeCellBody(
9699
}
97100
}
98101

99-
ChevronView(
102+
ChevronButton(
100103
isExpanded = isExpanded,
101-
modifier = Modifier.size(Dimens.expandableCellChevronSize)
104+
onExpand = onExpand,
102105
)
103106
}
104107
}

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/InformationComposeCell.kt

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import androidx.compose.runtime.Composable
1111
import androidx.compose.ui.Alignment
1212
import androidx.compose.ui.Modifier
1313
import androidx.compose.ui.draw.alpha
14+
import androidx.compose.ui.focus.focusProperties
1415
import androidx.compose.ui.graphics.Color
1516
import androidx.compose.ui.res.painterResource
1617
import androidx.compose.ui.tooling.preview.Preview
@@ -45,6 +46,7 @@ fun InformationComposeCell(
4546
val bodyViewModifier = Modifier
4647

4748
BaseCell(
49+
modifier = Modifier.focusProperties { canFocus = false },
4850
title = {
4951
BaseCellTitle(
5052
title = title,

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/RelayLocationCell.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import androidx.compose.ui.graphics.compositeOver
2828
import androidx.compose.ui.res.painterResource
2929
import androidx.compose.ui.tooling.preview.Preview
3030
import net.mullvad.mullvadvpn.R
31-
import net.mullvad.mullvadvpn.compose.component.ChevronView
31+
import net.mullvad.mullvadvpn.compose.component.Chevron
3232
import net.mullvad.mullvadvpn.compose.component.VerticalDivider
3333
import net.mullvad.mullvadvpn.lib.theme.AppTheme
3434
import net.mullvad.mullvadvpn.lib.theme.Dimens
@@ -258,7 +258,7 @@ fun RelayLocationCell(
258258
color = MaterialTheme.colorScheme.background,
259259
modifier = Modifier.padding(vertical = Dimens.verticalDividerPadding)
260260
)
261-
ChevronView(
261+
Chevron(
262262
isExpanded = expanded.value,
263263
modifier =
264264
Modifier.fillMaxHeight()

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SwitchComposeCell.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.compose.material3.Text
1212
import androidx.compose.runtime.Composable
1313
import androidx.compose.ui.Alignment
1414
import androidx.compose.ui.Modifier
15+
import androidx.compose.ui.focus.focusProperties
1516
import androidx.compose.ui.graphics.Color
1617
import androidx.compose.ui.res.painterResource
1718
import androidx.compose.ui.text.font.FontWeight
@@ -118,12 +119,12 @@ private fun SwitchComposeCell(
118119
modifier: Modifier = Modifier,
119120
) {
120121
BaseCell(
121-
modifier = modifier,
122+
modifier = modifier.focusProperties { canFocus = false },
122123
title = titleView,
123124
isRowEnabled = isEnabled,
124125
bodyView = {
125126
SwitchCellView(
126-
onSwitchClicked = null,
127+
onSwitchClicked = onCellClicked,
127128
isEnabled = isEnabled,
128129
isToggled = isToggled,
129130
onInfoClicked = onInfoClicked

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Chevron.kt

+15-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.compose.animation.core.LinearEasing
44
import androidx.compose.animation.core.TweenSpec
55
import androidx.compose.animation.core.animateFloatAsState
66
import androidx.compose.material3.Icon
7+
import androidx.compose.material3.IconButton
78
import androidx.compose.material3.MaterialTheme
89
import androidx.compose.runtime.Composable
910
import androidx.compose.runtime.remember
@@ -15,12 +16,11 @@ import net.mullvad.mullvadvpn.R
1516
import net.mullvad.mullvadvpn.lib.theme.color.AlphaChevron
1617

1718
@Composable
18-
fun ChevronView(
19+
fun Chevron(
1920
modifier: Modifier = Modifier,
2021
color: Color = MaterialTheme.colorScheme.onBackground.copy(alpha = AlphaChevron),
2122
isExpanded: Boolean
2223
) {
23-
val resourceId = R.drawable.icon_chevron
2424

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

3333
Icon(
34-
painterResource(id = resourceId),
34+
painterResource(id = R.drawable.icon_chevron),
3535
contentDescription = null,
3636
tint = color,
3737
modifier = modifier.rotate(animatedRotation.value),
3838
)
3939
}
40+
41+
@Composable
42+
fun ChevronButton(
43+
modifier: Modifier = Modifier,
44+
color: Color = MaterialTheme.colorScheme.onBackground.copy(alpha = AlphaChevron),
45+
onExpand: (Boolean) -> Unit,
46+
isExpanded: Boolean
47+
) {
48+
IconButton(modifier = modifier, onClick = { onExpand(!isExpanded) }) {
49+
Chevron(isExpanded = isExpanded, color = color)
50+
}
51+
}

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/LocationInfo.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fun LocationInfo(
7171
},
7272
style = MaterialTheme.typography.labelLarge.copy(fontWeight = FontWeight.SemiBold)
7373
)
74-
ChevronView(
74+
Chevron(
7575
isExpanded = isExpanded,
7676
color =
7777
if (isExpanded) {

0 commit comments

Comments
 (0)