Skip to content

Commit ddbb5ce

Browse files
committed
feat: automatically scroll to latest calculator result
1 parent 7b62dac commit ddbb5ce

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

app/src/main/java/net/youapps/calcyou/ui/components/CalculatorDisplay.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import androidx.compose.foundation.layout.fillMaxWidth
1111
import androidx.compose.foundation.layout.padding
1212
import androidx.compose.foundation.lazy.LazyColumn
1313
import androidx.compose.foundation.lazy.items
14+
import androidx.compose.foundation.lazy.rememberLazyListState
1415
import androidx.compose.foundation.shape.RoundedCornerShape
1516
import androidx.compose.foundation.text.BasicTextField
1617
import androidx.compose.material3.MaterialTheme
1718
import androidx.compose.material3.Text
1819
import androidx.compose.material3.surfaceColorAtElevation
1920
import androidx.compose.runtime.Composable
2021
import androidx.compose.runtime.CompositionLocalProvider
22+
import androidx.compose.runtime.LaunchedEffect
2123
import androidx.compose.ui.Alignment
2224
import androidx.compose.ui.Modifier
2325
import androidx.compose.ui.draw.clip
@@ -41,11 +43,18 @@ fun ColumnScope.CalculatorDisplay(
4143
.clip(RoundedCornerShape(24.dp))
4244
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(10.dp))
4345
) {
46+
val listState = rememberLazyListState()
47+
48+
LaunchedEffect(calculatorViewModel.history.toList()) {
49+
if (calculatorViewModel.history.isNotEmpty())
50+
listState.animateScrollToItem(calculatorViewModel.history.size - 1);
51+
}
4452
LazyColumn(
4553
Modifier
4654
.fillMaxWidth()
4755
.padding(horizontal = 16.dp, vertical = 8.dp)
4856
.weight(1f),
57+
state = listState,
4958
horizontalAlignment = Alignment.End,
5059
verticalArrangement = Arrangement.spacedBy(8.dp, alignment = Alignment.Bottom)
5160
) {

0 commit comments

Comments
 (0)