tgyuuAn / BaekyoungE

자연어 처리 기반 진로 상담 chat bot 어플리케이션
5 stars 0 forks source link

[FEATURE]: 마지막 채팅으로 자동으로 스크롤 되게 구현 #15

Closed tgyuuAn closed 2 months ago

tgyuuAn commented 5 months ago

작업 사항

Todo

기타사항

참고 자료

tgyuuAn commented 2 months ago

방법

1 이전 채팅의 텍스트 사이즈를 저장해둠

2. 새로운 채팅이 들어왔을 때, 현재 사이즈와 다를경우, 마지막 아이템의 인덱스로 스크롤 함.

    val listState = rememberLazyListState()
    var previousChatSize by remember { mutableStateOf(1) }
    val coroutineScope = rememberCoroutineScope()




    LaunchedEffect(chatLog) {
        if (previousChatSize != chatLog.size) {
            coroutineScope.launch {
                listState.animateScrollToItem(chatLog.size - 1)
            }

            previousChatSize = chatLog.size
        }
    }




LazyColumn(
                state = listState,
                verticalArrangement = Arrangement.spacedBy(20.dp),
                contentPadding = PaddingValues(horizontal = 25.dp),
                modifier = Modifier
                    .fillMaxSize()
                    .padding(top = topBarHeight, bottom = textFieldHeight),
            ) {