Skip to content

Commit 3cf7301

Browse files
authored
Merge pull request #56 from MONEYMONG/feature/ID-21
[ID-21] 장부 선택 바텀시트 선택된 장부가 항상 보이도록 수정
2 parents 293cb5a + ca3f43f commit 3cf7301

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

feature/ledger/src/main/java/com/moneymong/moneymong/ledger/view/LedgerSelectBottomSheet.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import androidx.compose.foundation.layout.Spacer
66
import androidx.compose.foundation.layout.fillMaxWidth
77
import androidx.compose.foundation.layout.height
88
import 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
1112
import androidx.compose.runtime.Composable
13+
import androidx.compose.runtime.LaunchedEffect
1214
import androidx.compose.runtime.getValue
1315
import androidx.compose.runtime.mutableIntStateOf
1416
import 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

Comments
 (0)