mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
refactor: improve LazyColumn auto-scroll behavior
This commit is contained in:
parent
b850805ce3
commit
4fe49a45dc
1 changed files with 8 additions and 3 deletions
|
|
@ -20,7 +20,9 @@ import androidx.compose.material.Surface
|
|||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.colorResource
|
||||
|
|
@ -79,9 +81,12 @@ class DebugFragment : Fragment() {
|
|||
val listState = rememberLazyListState()
|
||||
val logs by model.meshLog.collectAsStateWithLifecycle()
|
||||
|
||||
LaunchedEffect(logs) {
|
||||
if (listState.firstVisibleItemIndex < 3 && !listState.isScrollInProgress) {
|
||||
listState.scrollToItem(0)
|
||||
val shouldAutoScroll by remember { derivedStateOf { listState.firstVisibleItemIndex < 3 } }
|
||||
if (shouldAutoScroll) {
|
||||
LaunchedEffect(logs) {
|
||||
if (!listState.isScrollInProgress) {
|
||||
listState.scrollToItem(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue