@@ -6,9 +6,11 @@ import androidx.compose.foundation.layout.Spacer
66import androidx.compose.foundation.layout.fillMaxWidth
77import androidx.compose.foundation.layout.height
88import androidx.compose.foundation.layout.padding
9- import androidx.compose.foundation.rememberScrollState
10- import androidx.compose.foundation.verticalScroll
9+ import androidx.compose.foundation.lazy.LazyColumn
10+ import androidx.compose.foundation.lazy.items
11+ import androidx.compose.foundation.lazy.rememberLazyListState
1112import androidx.compose.runtime.Composable
13+ import androidx.compose.runtime.LaunchedEffect
1214import androidx.compose.runtime.getValue
1315import androidx.compose.runtime.mutableIntStateOf
1416import androidx.compose.runtime.remember
@@ -79,20 +81,27 @@ private fun LedgerAgencySelectItems(
7981 var itemHeight by remember { mutableIntStateOf(0 ) }
8082 val itemSpace = 12 .dp
8183 val maxVisibleItemCount = 3
84+ val listState = rememberLazyListState()
8285
83- Column (
86+ LaunchedEffect (key1 = Unit ) {
87+ val currentAgencyIndex =
88+ agencyList.indexOfFirst { it.id == currentAgencyId }.coerceAtLeast(0 )
89+ listState.animateScrollToItem(index = currentAgencyIndex)
90+ }
91+
92+ LazyColumn (
8493 modifier = Modifier
8594 .height(
8695 if (itemHeight > 0 && agencyList.size > maxVisibleItemCount) {
8796 (itemHeight.pxToDp * maxVisibleItemCount) + itemSpace * (maxVisibleItemCount - 1 )
8897 } else {
8998 Dp .Unspecified
9099 }
91- )
92- .verticalScroll(rememberScrollState()) ,
100+ ),
101+ state = listState ,
93102 verticalArrangement = Arrangement .spacedBy(space = itemSpace),
94103 ) {
95- agencyList.forEach { item ->
104+ items(items = agencyList) { item ->
96105 LedgerAgencySelectItem (
97106 modifier = Modifier .onGloballyPositioned {
98107 if (itemHeight == 0 ) {
0 commit comments