Skip to content

Commit e0d91d7

Browse files
authored
[PM-18067] Consolidate item name fields into ItemHeader (#4766)
2 parents 7c36b7c + e8a98dd commit e0d91d7

24 files changed

+1771
-340
lines changed

app/src/main/java/com/x8bit/bitwarden/ui/platform/components/field/BitwardenTextField.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fun BitwardenTextField(
108108
label: String?,
109109
value: String,
110110
onValueChange: (String) -> Unit,
111-
cardStyle: CardStyle,
111+
cardStyle: CardStyle?,
112112
modifier: Modifier = Modifier,
113113
tooltip: TooltipData? = null,
114114
placeholder: String? = null,
@@ -207,7 +207,7 @@ fun BitwardenTextField(
207207
value: String,
208208
onValueChange: (String) -> Unit,
209209
supportingContent: (@Composable ColumnScope.() -> Unit)?,
210-
cardStyle: CardStyle,
210+
cardStyle: CardStyle?,
211211
modifier: Modifier = Modifier,
212212
tooltip: TooltipData? = null,
213213
supportingContentPadding: PaddingValues = PaddingValues(vertical = 12.dp, horizontal = 16.dp),
@@ -378,7 +378,7 @@ fun BitwardenTextField(
378378
content = content,
379379
)
380380
}
381-
?: Spacer(modifier = Modifier.height(height = 6.dp))
381+
?: Spacer(modifier = Modifier.height(height = cardStyle?.let { 6.dp } ?: 0.dp))
382382
}
383383
val filteredAutoCompleteList = autoCompleteOptions
384384
.filter { option ->
Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.x8bit.bitwarden.ui.platform.components.header
22

3+
import androidx.compose.animation.Crossfade
4+
import androidx.compose.animation.core.AnimationConstants
35
import androidx.compose.animation.core.animateFloatAsState
6+
import androidx.compose.animation.core.tween
47
import androidx.compose.foundation.clickable
8+
import androidx.compose.foundation.layout.PaddingValues
59
import androidx.compose.foundation.layout.Row
610
import androidx.compose.foundation.layout.padding
711
import androidx.compose.material3.Icon
@@ -12,6 +16,7 @@ import androidx.compose.ui.Alignment
1216
import androidx.compose.ui.Modifier
1317
import androidx.compose.ui.draw.clip
1418
import androidx.compose.ui.draw.rotate
19+
import androidx.compose.ui.graphics.Shape
1520
import androidx.compose.ui.res.stringResource
1621
import androidx.compose.ui.semantics.semantics
1722
import androidx.compose.ui.unit.dp
@@ -21,44 +26,77 @@ import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
2126

2227
/**
2328
* Reusable header element that is clickable for expanding or collapsing content.
29+
*
30+
* @param collapsedText Text to display when the content is collapsed.
31+
* @param expandedText Text to display when the content is expanded.
32+
* @param showExpansionIndicator Whether to show an indicator to expand or collapse the content.
2433
*/
2534
@Composable
2635
fun BitwardenExpandingHeader(
2736
isExpanded: Boolean,
2837
onClick: () -> Unit,
2938
modifier: Modifier = Modifier,
30-
title: String = stringResource(id = R.string.additional_options),
39+
collapsedText: String = stringResource(id = R.string.additional_options),
40+
expandedText: String = collapsedText,
41+
showExpansionIndicator: Boolean = true,
42+
shape: Shape = BitwardenTheme.shapes.content,
43+
insets: PaddingValues = PaddingValues(top = 16.dp, bottom = 8.dp),
3144
) {
3245
Row(
3346
modifier = modifier
34-
.clip(shape = BitwardenTheme.shapes.content)
47+
.clip(shape = shape)
3548
.clickable(
3649
onClickLabel = stringResource(
3750
id = if (isExpanded) R.string.options_expanded else R.string.options_collapsed,
3851
),
3952
onClick = onClick,
4053
)
4154
.minimumInteractiveComponentSize()
42-
.padding(top = 16.dp, bottom = 8.dp)
4355
.padding(horizontal = 16.dp)
56+
.padding(paddingValues = insets)
4457
.semantics(mergeDescendants = true) {},
4558
verticalAlignment = Alignment.CenterVertically,
4659
) {
47-
Text(
48-
text = title,
49-
color = BitwardenTheme.colorScheme.text.interaction,
50-
style = BitwardenTheme.typography.labelLarge,
51-
modifier = Modifier.padding(end = 8.dp),
52-
)
53-
val iconRotationDegrees = animateFloatAsState(
54-
targetValue = if (isExpanded) 0f else 180f,
55-
label = "expanderIconRotationAnimation",
56-
)
57-
Icon(
58-
painter = rememberVectorPainter(id = R.drawable.ic_chevron_up_small),
59-
contentDescription = null,
60-
tint = BitwardenTheme.colorScheme.icon.secondary,
61-
modifier = Modifier.rotate(degrees = iconRotationDegrees.value),
62-
)
60+
Crossfade(
61+
targetState = isExpanded,
62+
label = "BitwardenExpandingHeaderTitle_animation",
63+
// Make the animation shorter when the text is the same to avoid crossfading the same
64+
// text.
65+
animationSpec = tween(
66+
durationMillis = if (expandedText != collapsedText) {
67+
AnimationConstants.DefaultDurationMillis
68+
} else {
69+
0
70+
},
71+
),
72+
) { expanded ->
73+
if (expanded) {
74+
Text(
75+
text = expandedText,
76+
color = BitwardenTheme.colorScheme.text.interaction,
77+
style = BitwardenTheme.typography.labelLarge,
78+
modifier = Modifier.padding(end = 8.dp),
79+
)
80+
} else {
81+
Text(
82+
text = collapsedText,
83+
color = BitwardenTheme.colorScheme.text.interaction,
84+
style = BitwardenTheme.typography.labelLarge,
85+
modifier = Modifier.padding(end = 8.dp),
86+
)
87+
}
88+
}
89+
if (showExpansionIndicator) {
90+
val iconRotationDegrees = animateFloatAsState(
91+
targetValue = if (isExpanded) 0f else 180f,
92+
label = "expanderIconRotationAnimation",
93+
)
94+
Icon(
95+
painter = rememberVectorPainter(id = R.drawable.ic_chevron_up_small),
96+
contentDescription = null,
97+
tint = BitwardenTheme.colorScheme.icon.secondary,
98+
modifier = Modifier.rotate(degrees = iconRotationDegrees.value),
99+
)
100+
}
63101
}
64102
}

app/src/main/java/com/x8bit/bitwarden/ui/platform/theme/color/BitwardenColorScheme.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ data class BitwardenColorScheme(
1717
val toggleButton: ToggleButtonColors,
1818
val sliderButton: SliderButtonColors,
1919
val status: StatusColors,
20+
val illustration: IllustrationColors,
2021
) {
2122
/**
2223
* Defines all the text colors for the app.
@@ -124,4 +125,13 @@ data class BitwardenColorScheme(
124125
val weak2: Color,
125126
val error: Color,
126127
)
128+
129+
/**
130+
* Defines all the illustration colors for the app.
131+
*/
132+
@Immutable
133+
data class IllustrationColors(
134+
val outline: Color,
135+
val backgroundPrimary: Color,
136+
)
127137
}

app/src/main/java/com/x8bit/bitwarden/ui/platform/theme/color/ColorScheme.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ val darkBitwardenColorScheme: BitwardenColorScheme = BitwardenColorScheme(
6969
weak2 = PrimitiveColors.yellow200,
7070
error = PrimitiveColors.red200,
7171
),
72+
illustration = BitwardenColorScheme.IllustrationColors(
73+
outline = PrimitiveColors.blue500,
74+
backgroundPrimary = PrimitiveColors.blue200,
75+
),
7276
)
7377

7478
/**
@@ -137,6 +141,10 @@ val lightBitwardenColorScheme: BitwardenColorScheme = BitwardenColorScheme(
137141
weak2 = PrimitiveColors.yellow300,
138142
error = PrimitiveColors.red300,
139143
),
144+
illustration = BitwardenColorScheme.IllustrationColors(
145+
outline = PrimitiveColors.blue700,
146+
backgroundPrimary = PrimitiveColors.blue100,
147+
),
140148
)
141149

142150
/**
@@ -211,6 +219,10 @@ fun dynamicBitwardenColorScheme(
211219
weak2 = defaultTheme.status.weak2,
212220
error = defaultTheme.status.error,
213221
),
222+
illustration = BitwardenColorScheme.IllustrationColors(
223+
outline = materialColorScheme.tertiaryContainer,
224+
backgroundPrimary = materialColorScheme.onTertiaryContainer,
225+
),
214226
)
215227
}
216228

app/src/main/java/com/x8bit/bitwarden/ui/platform/theme/shape/BitwardenShapes.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ data class BitwardenShapes(
2222
val progressIndicator: CornerBasedShape,
2323
val segmentedControl: CornerBasedShape,
2424
val snackbar: CornerBasedShape,
25+
val favicon: CornerBasedShape,
2526
)

app/src/main/java/com/x8bit/bitwarden/ui/platform/theme/shape/Shapes.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ val bitwardenShapes: BitwardenShapes = BitwardenShapes(
2222
progressIndicator = CircleShape,
2323
segmentedControl = CircleShape,
2424
snackbar = RoundedCornerShape(size = 8.dp),
25+
favicon = CircleShape,
2526
)

0 commit comments

Comments
 (0)