kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
refactor: improve `LazyColumn` auto-scroll behavior
rodzic
b850805ce3
commit
4fe49a45dc
|
@ -20,7 +20,9 @@ import androidx.compose.material.Surface
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.derivedStateOf
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.res.colorResource
|
import androidx.compose.ui.res.colorResource
|
||||||
|
@ -79,9 +81,12 @@ class DebugFragment : Fragment() {
|
||||||
val listState = rememberLazyListState()
|
val listState = rememberLazyListState()
|
||||||
val logs by model.meshLog.collectAsStateWithLifecycle()
|
val logs by model.meshLog.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
LaunchedEffect(logs) {
|
val shouldAutoScroll by remember { derivedStateOf { listState.firstVisibleItemIndex < 3 } }
|
||||||
if (listState.firstVisibleItemIndex < 3 && !listState.isScrollInProgress) {
|
if (shouldAutoScroll) {
|
||||||
listState.scrollToItem(0)
|
LaunchedEffect(logs) {
|
||||||
|
if (!listState.isScrollInProgress) {
|
||||||
|
listState.scrollToItem(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue