From 652027c1c16d8523674becb2a53d02925ad16348 Mon Sep 17 00:00:00 2001 From: ericek111 Date: Tue, 6 Oct 2026 21:19:05 +0000 Subject: [PATCH] Keep the channel tree's scroll position while the chat replaces it Co-Authored-By: Claude Opus 5.5 --- .../app/src/main/java/com/ts3client/android/ui/ChannelTree.kt | 3 ++- .../src/main/java/com/ts3client/android/ui/ServerScreen.kt | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/ts3client/android/ui/ChannelTree.kt b/android/app/src/main/java/com/ts3client/android/ui/ChannelTree.kt index 02937e9..d488090 100644 --- a/android/app/src/main/java/com/ts3client/android/ui/ChannelTree.kt +++ b/android/app/src/main/java/com/ts3client/android/ui/ChannelTree.kt @@ -19,6 +19,7 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.KeyboardArrowDown @@ -100,9 +101,9 @@ fun ChannelTree( /** The rows the find bar matched, and the one it is on, which a reveal does not flash. */ found: Set = emptySet(), foundCurrent: TreeRef? = null, + listState: LazyListState = rememberLazyListState(), ) { val rows = remember(tree, collapsed, currentChannel) { flatten(tree, collapsed, currentChannel) } - val listState = rememberLazyListState() var flashing by remember { mutableStateOf(null) } LaunchedEffect(reveal, rows) { val ref = reveal ?: return@LaunchedEffect diff --git a/android/app/src/main/java/com/ts3client/android/ui/ServerScreen.kt b/android/app/src/main/java/com/ts3client/android/ui/ServerScreen.kt index f0b35b1..b9d8ed2 100644 --- a/android/app/src/main/java/com/ts3client/android/ui/ServerScreen.kt +++ b/android/app/src/main/java/com/ts3client/android/ui/ServerScreen.kt @@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.navigationBarsPadding import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width +import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowDropDown @@ -113,6 +114,8 @@ fun ServerScreen( val collapsed by server.collapsed.collectAsStateWithLifecycle() var showChat by rememberSaveable { mutableStateOf(false) } + // Out here, so the tree keeps its place while the chat or another screen replaces it. + val treeList = rememberLazyListState() var chatKey by rememberSaveable(stateSaver = ChatKeySaver) { mutableStateOf(ChatKey.Channel) } val conversation = chats[chatKey] ?: chats.channel var clientSheet by remember { mutableStateOf(null) } @@ -280,6 +283,7 @@ fun ServerScreen( onRevealed = { reveal = null }, found = remember(treeHits) { treeHits.mapTo(HashSet()) { TreeRef(treeFind.channels, it) } }, foundCurrent = treeAt?.takeIf { it in treeHits }?.let { TreeRef(treeFind.channels, it) }, + listState = treeList, ) } else { ChatPane(