From 1f68473f395ab21b5c92bab5e3e18521af525675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20G=C3=B6ransson?= Date: Mon, 11 Sep 2023 15:28:48 +0200 Subject: [PATCH] Fix row animations --- .../net/mullvad/mullvadvpn/compose/cell/BaseCell.kt | 11 +++-------- .../mullvadvpn/compose/cell/SwitchComposeCell.kt | 10 +++++++--- .../mullvadvpn/compose/screen/SplitTunnelingScreen.kt | 9 +++++++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/BaseCell.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/BaseCell.kt index c3c3b4ddef45..262d46e31ca1 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/BaseCell.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/BaseCell.kt @@ -65,17 +65,12 @@ internal fun BaseCell( minHeight: Dp = Dimens.cellHeight, testTag: String = "" ) { - val rowModifier = - Modifier.let { - if (isRowEnabled) { - it.clickable { onCellClicked() } - } else it - } Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Start, modifier = - rowModifier + modifier + .clickable(isRowEnabled, onClick = onCellClicked) .wrapContentHeight() .defaultMinSize(minHeight = minHeight) .fillMaxWidth() @@ -89,7 +84,7 @@ internal fun BaseCell( Spacer(modifier = Modifier.weight(1.0f)) - Column(modifier = modifier.wrapContentWidth().wrapContentHeight()) { bodyView() } + Column(modifier = Modifier.wrapContentWidth().wrapContentHeight()) { bodyView() } } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SwitchComposeCell.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SwitchComposeCell.kt index ccd6a541ef00..02546e37d3b7 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SwitchComposeCell.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SwitchComposeCell.kt @@ -75,11 +75,12 @@ fun NormalSwitchComposeCell( fun HeaderSwitchComposeCell( title: String, isToggled: Boolean, + modifier: Modifier = Modifier, startPadding: Dp = Dimens.cellStartPadding, isEnabled: Boolean = true, background: Color = MaterialTheme.colorScheme.primary, onCellClicked: (Boolean) -> Unit = {}, - onInfoClicked: (() -> Unit)? = null + onInfoClicked: (() -> Unit)? = null, ) { SwitchComposeCell( titleView = { BaseCellTitle(title = title, style = MaterialTheme.typography.titleMedium) }, @@ -88,7 +89,8 @@ fun HeaderSwitchComposeCell( isEnabled = isEnabled, background = background, onCellClicked = onCellClicked, - onInfoClicked = onInfoClicked + onInfoClicked = onInfoClicked, + modifier, ) } @@ -100,9 +102,11 @@ private fun SwitchComposeCell( isEnabled: Boolean, background: Color, onCellClicked: (Boolean) -> Unit, - onInfoClicked: (() -> Unit)? + onInfoClicked: (() -> Unit)?, + modifier: Modifier = Modifier, ) { BaseCell( + modifier = modifier, title = titleView, isRowEnabled = isEnabled, bodyView = { diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreen.kt index ac101b48ab2f..5170ef0845fa 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreen.kt @@ -183,7 +183,10 @@ fun SplitTunnelingScreen( } } item(key = CommonContentKey.SPACER, contentType = ContentType.SPACER) { - Spacer(modifier = Modifier.height(Dimens.mediumPadding)) + Spacer( + modifier = + Modifier.animateItemPlacement().height(Dimens.mediumPadding) + ) } } @@ -194,7 +197,8 @@ fun SplitTunnelingScreen( HeaderSwitchComposeCell( title = stringResource(id = R.string.show_system_apps), isToggled = uiState.showSystemApps, - onCellClicked = { newValue -> onShowSystemAppsClick(newValue) } + onCellClicked = { newValue -> onShowSystemAppsClick(newValue) }, + modifier = Modifier.animateItemPlacement() ) } itemWithDivider( @@ -202,6 +206,7 @@ fun SplitTunnelingScreen( contentType = ContentType.HEADER ) { BaseCell( + modifier = Modifier.animateItemPlacement(), title = { Text( text = stringResource(id = R.string.all_applications),