diff options
| author | 2024-08-27 01:16:31 +0000 | |
|---|---|---|
| committer | 2024-08-27 01:16:31 +0000 | |
| commit | 13d424b6d906edd0ee76dfd5c835829f6a5d1cb9 (patch) | |
| tree | 480526a647146e98c2d0a467c602e2b69747d6f9 | |
| parent | 59d8e60dc2fc6eb6c5197926ff20715f4a66cb8e (diff) | |
| parent | d6888b31a6f32ffe248265893d6d0a566bf43610 (diff) | |
Merge "Don't scroll to live content on initial content load" into main
2 files changed, 22 insertions, 10 deletions
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt index 6f415ea334af..b0590e06d3bd 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt @@ -545,18 +545,35 @@ private fun ScrollOnUpdatedLiveContentEffect( ) { val coroutineScope = rememberCoroutineScope() val liveContentKeys = remember { mutableListOf<String>() } + var communalContentPending by remember { mutableStateOf(true) } LaunchedEffect(communalContent) { + // Do nothing until any communal content comes in + if (communalContentPending && communalContent.isEmpty()) { + return@LaunchedEffect + } + val prevLiveContentKeys = liveContentKeys.toList() + val newLiveContentKeys = communalContent.filter { it.isLiveContent() }.map { it.key } liveContentKeys.clear() - liveContentKeys.addAll(communalContent.filter { it.isLiveContent() }.map { it.key }) + liveContentKeys.addAll(newLiveContentKeys) - // Find the first updated content + // Do nothing on first communal content since we don't have a delta + if (communalContentPending) { + communalContentPending = false + return@LaunchedEffect + } + + // Do nothing if there is no new live content val indexOfFirstUpdatedContent = - liveContentKeys.indexOfFirst { !prevLiveContentKeys.contains(it) } + newLiveContentKeys.indexOfFirst { !prevLiveContentKeys.contains(it) } + if (indexOfFirstUpdatedContent < 0) { + return@LaunchedEffect + } - // Scroll if current position is behind the first updated content - if (indexOfFirstUpdatedContent in 0 until gridState.firstVisibleItemIndex) { + // Scroll if the live content is not visible + val lastVisibleItemIndex = gridState.layoutInfo.visibleItemsInfo.lastOrNull()?.index + if (lastVisibleItemIndex != null && indexOfFirstUpdatedContent > lastVisibleItemIndex) { // Launching with a scope to prevent the job from being canceled in the case of a // recomposition during scrolling coroutineScope.launch { gridState.animateScrollToItem(indexOfFirstUpdatedContent) } diff --git a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt index 2ae514f17990..98abbebd1951 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt @@ -614,11 +614,6 @@ constructor( _firstVisibleItemOffset = firstVisibleItemOffset } - fun resetScrollPosition() { - _firstVisibleItemIndex = 0 - _firstVisibleItemOffset = 0 - } - val firstVisibleItemIndex: Int get() = _firstVisibleItemIndex |