-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify chevron animation and fix alpha
- Loading branch information
Showing
6 changed files
with
58 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 16 additions & 15 deletions
31
android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Chevron.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,39 @@ | ||
package net.mullvad.mullvadvpn.compose.component | ||
|
||
import androidx.compose.animation.core.Animatable | ||
import androidx.compose.animation.core.LinearEasing | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.foundation.Image | ||
import androidx.compose.animation.core.TweenSpec | ||
import androidx.compose.animation.core.animateFloatAsState | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.rotate | ||
import androidx.compose.ui.graphics.ColorFilter | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.painterResource | ||
import net.mullvad.mullvadvpn.R | ||
import net.mullvad.mullvadvpn.lib.theme.color.AlphaChevron | ||
|
||
@Composable | ||
fun ChevronView( | ||
modifier: Modifier = Modifier, | ||
colorFilter: ColorFilter? = null, | ||
color: Color = MaterialTheme.colorScheme.onBackground.copy(alpha = AlphaChevron), | ||
isExpanded: Boolean | ||
) { | ||
val resourceId = R.drawable.icon_chevron | ||
val rotation = remember { Animatable(90f + if (isExpanded) 180f else 0f) } | ||
|
||
LaunchedEffect(isExpanded) { | ||
rotation.animateTo( | ||
targetValue = 90f + if (isExpanded) 180f else 0f, | ||
animationSpec = tween(100, easing = LinearEasing) | ||
val degree = remember(isExpanded) { if (isExpanded) 270f else 90f } | ||
val animatedRotation = | ||
animateFloatAsState( | ||
targetValue = degree, | ||
label = "", | ||
animationSpec = TweenSpec(100, easing = LinearEasing) | ||
) | ||
} | ||
|
||
Image( | ||
Icon( | ||
painterResource(id = resourceId), | ||
contentDescription = null, | ||
colorFilter = colorFilter, | ||
modifier = modifier.rotate(rotation.value), | ||
tint = color, | ||
modifier = modifier.rotate(animatedRotation.value), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/VerticalDivider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package net.mullvad.mullvadvpn.compose.component | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.material3.DividerDefaults | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
fun VerticalDivider( | ||
modifier: Modifier = Modifier, | ||
thickness: Dp = DividerDefaults.Thickness, | ||
color: Color = DividerDefaults.color, | ||
) { | ||
val targetThickness = | ||
if (thickness == Dp.Hairline) { | ||
(1f / LocalDensity.current.density).dp | ||
} else { | ||
thickness | ||
} | ||
Box(modifier.fillMaxHeight().width(targetThickness).background(color = color)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters