Loading packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +22 −5 Original line number Diff line number Diff line Loading @@ -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) } Loading packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt +0 −5 Original line number Diff line number Diff line Loading @@ -614,11 +614,6 @@ constructor( _firstVisibleItemOffset = firstVisibleItemOffset } fun resetScrollPosition() { _firstVisibleItemIndex = 0 _firstVisibleItemOffset = 0 } val firstVisibleItemIndex: Int get() = _firstVisibleItemIndex Loading Loading
packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +22 −5 Original line number Diff line number Diff line Loading @@ -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) } Loading
packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt +0 −5 Original line number Diff line number Diff line Loading @@ -614,11 +614,6 @@ constructor( _firstVisibleItemOffset = firstVisibleItemOffset } fun resetScrollPosition() { _firstVisibleItemIndex = 0 _firstVisibleItemOffset = 0 } val firstVisibleItemIndex: Int get() = _firstVisibleItemIndex Loading