Skip to content

Commit 0604b5e

Browse files
authored
Animate tree height selection buttons (#1168)
1 parent 699db1a commit 0604b5e

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

app/src/main/java/org/greenstand/android/TreeTracker/treeheight/TreeHeightColourSelection.kt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.greenstand.android.TreeTracker.treeheight
1717

18+
import androidx.compose.animation.core.animateDpAsState
19+
import androidx.compose.animation.core.tween
1820
import androidx.compose.foundation.layout.Arrangement
1921
import androidx.compose.foundation.layout.Box
2022
import androidx.compose.foundation.layout.PaddingValues
@@ -85,22 +87,32 @@ fun TreeHeightScreen() {
8587
},
8688
)
8789
}
88-
) {
90+
) { padding ->
8991
LazyColumn(
90-
modifier = Modifier.fillMaxWidth(),
92+
modifier = Modifier.padding(padding).fillMaxWidth(),
9193
horizontalAlignment = Alignment.CenterHorizontally,
9294
verticalArrangement = Arrangement.spacedBy(20.dp),
9395
contentPadding = PaddingValues(start = 8.dp, end = 8.dp, top = 30.dp)
9496
) {
9597
items(state.colors) { color ->
98+
val isSelected = color == state.selectedColor
99+
val animatedWidth by animateDpAsState(
100+
targetValue = if (isSelected) 350.dp else 200.dp,
101+
animationSpec = tween(durationMillis = 300),
102+
)
103+
val animatedHeight by animateDpAsState(
104+
targetValue = if (isSelected) 85.dp else 62.dp,
105+
animationSpec = tween(durationMillis = 300),
106+
)
107+
96108
TreeTrackerButton(
97109
colors = color,
98-
isSelected = color == state.selectedColor,
110+
isSelected = isSelected,
99111
onClick = { viewModel.selectColor(color) },
100-
modifier = if (color == state.selectedColor) Modifier.size(
101-
width = 350.dp,
102-
height = 85.dp
103-
) else Modifier.size(width = 200.dp, height = 62.dp)
112+
modifier = Modifier.size(
113+
width = animatedWidth,
114+
height = animatedHeight
115+
)
104116
) {}
105117
}
106118
}

0 commit comments

Comments
 (0)