|
15 | 15 | */ |
16 | 16 | package org.greenstand.android.TreeTracker.treeheight |
17 | 17 |
|
| 18 | +import androidx.compose.animation.core.animateDpAsState |
| 19 | +import androidx.compose.animation.core.tween |
18 | 20 | import androidx.compose.foundation.layout.Arrangement |
19 | 21 | import androidx.compose.foundation.layout.Box |
20 | 22 | import androidx.compose.foundation.layout.PaddingValues |
@@ -85,22 +87,32 @@ fun TreeHeightScreen() { |
85 | 87 | }, |
86 | 88 | ) |
87 | 89 | } |
88 | | - ) { |
| 90 | + ) { padding -> |
89 | 91 | LazyColumn( |
90 | | - modifier = Modifier.fillMaxWidth(), |
| 92 | + modifier = Modifier.padding(padding).fillMaxWidth(), |
91 | 93 | horizontalAlignment = Alignment.CenterHorizontally, |
92 | 94 | verticalArrangement = Arrangement.spacedBy(20.dp), |
93 | 95 | contentPadding = PaddingValues(start = 8.dp, end = 8.dp, top = 30.dp) |
94 | 96 | ) { |
95 | 97 | 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 | + |
96 | 108 | TreeTrackerButton( |
97 | 109 | colors = color, |
98 | | - isSelected = color == state.selectedColor, |
| 110 | + isSelected = isSelected, |
99 | 111 | 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 | + ) |
104 | 116 | ) {} |
105 | 117 | } |
106 | 118 | } |
|
0 commit comments