Skip to content

Commit

Permalink
Refactor ItemHeader to use LazyColumn and Crossfade for smoothe…
Browse files Browse the repository at this point in the history
…r transitions

- Migrates `ItemHeader` to `LazyColumn` to improve performance.
- Introduces `Crossfade` for animating title changes in `BitwardenExpandingHeader`.
- Adjusts icon sizing in `ItemHeaderIcon`.
- Removes unnecessary column scope and animated visibility from `ExpandingItemLocationContent`.
- Refactors to use `LazyItemScope` and adds `animateItem()` to `ItemLocationListItem`.
- Adds conditional handling for expanding the item locations list.
  • Loading branch information
SaintPatrck committed Feb 25, 2025
1 parent e44738f commit 18c9815
Show file tree
Hide file tree
Showing 7 changed files with 1,154 additions and 1,190 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.x8bit.bitwarden.ui.platform.components.header

import androidx.compose.animation.Crossfade
import androidx.compose.animation.core.AnimationConstants
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -50,23 +53,46 @@ fun BitwardenExpandingHeader(
.semantics(mergeDescendants = true) {},
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = if (isExpanded) expandedText else collapsedText,
color = BitwardenTheme.colorScheme.text.interaction,
style = BitwardenTheme.typography.labelLarge,
modifier = Modifier.padding(end = 8.dp),
)
if (showExpansionIndicator) {
val iconRotationDegrees = animateFloatAsState(
targetValue = if (isExpanded) 0f else 180f,
label = "expanderIconRotationAnimation",
)
Icon(
painter = rememberVectorPainter(id = R.drawable.ic_chevron_up_small),
contentDescription = null,
tint = BitwardenTheme.colorScheme.icon.secondary,
modifier = Modifier.rotate(degrees = iconRotationDegrees.value),
)
Crossfade(
targetState = isExpanded,
label = "BitwardenExpandingHeaderTitle_animation",
// Make the animation shorter when the text is the same to avoid crossfading the same
// text.
animationSpec = tween(
durationMillis = if (expandedText != collapsedText) {
AnimationConstants.DefaultDurationMillis
} else {
0
},
),
) { expanded ->
if (expanded) {
Text(
text = expandedText,
color = BitwardenTheme.colorScheme.text.interaction,
style = BitwardenTheme.typography.labelLarge,
modifier = Modifier.padding(end = 8.dp),
)
} else {
Text(
text = collapsedText,
color = BitwardenTheme.colorScheme.text.interaction,
style = BitwardenTheme.typography.labelLarge,
modifier = Modifier.padding(end = 8.dp),
)
}
if (showExpansionIndicator) {
val iconRotationDegrees = animateFloatAsState(
targetValue = if (isExpanded) 0f else 180f,
label = "expanderIconRotationAnimation",
)
Icon(
painter = rememberVectorPainter(id = R.drawable.ic_chevron_up_small),
contentDescription = null,
tint = BitwardenTheme.colorScheme.icon.secondary,
modifier = Modifier.rotate(degrees = iconRotationDegrees.value),
)
}
}
}
}
Loading

0 comments on commit 18c9815

Please sign in to comment.