Loading packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +32 −0 Original line number Diff line number Diff line Loading @@ -66,6 +66,7 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedButton import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.State import androidx.compose.runtime.collectAsState import androidx.compose.runtime.derivedStateOf Loading @@ -74,6 +75,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Alignment import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier Loading Loading @@ -150,6 +152,8 @@ fun CommunalHub( val contentPadding = gridContentPadding(viewModel.isEditMode, toolbarSize) val contentOffset = beforeContentPadding(contentPadding).toOffset() ScrollOnNewSmartspaceEffect(viewModel, gridState) Box( modifier = modifier Loading Loading @@ -266,6 +270,34 @@ fun CommunalHub( } } @Composable private fun ScrollOnNewSmartspaceEffect( viewModel: BaseCommunalViewModel, gridState: LazyGridState ) { val communalContent by viewModel.communalContent.collectAsState(initial = emptyList()) var smartspaceCount by remember { mutableStateOf(0) } LaunchedEffect(communalContent) { snapshotFlow { gridState.firstVisibleItemIndex } .collect { index -> val existingSmartspaceCount = smartspaceCount smartspaceCount = communalContent.count { it.isSmartspace() } val firstIndex = communalContent.indexOfFirst { it.isSmartspace() } // Scroll to the beginning of the smartspace area whenever the number of // smartspace elements grows if ( existingSmartspaceCount < smartspaceCount && !viewModel.isEditMode && index > firstIndex ) { gridState.animateScrollToItem(firstIndex) } } } } @OptIn(ExperimentalFoundationApi::class) @Composable private fun BoxScope.CommunalHubLazyGrid( Loading packages/SystemUI/src/com/android/systemui/communal/domain/model/CommunalContentModel.kt +2 −0 Original line number Diff line number Diff line Loading @@ -152,4 +152,6 @@ sealed interface CommunalContentModel { } fun isWidgetContent() = this is WidgetContent fun isSmartspace() = this is Smartspace } Loading
packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +32 −0 Original line number Diff line number Diff line Loading @@ -66,6 +66,7 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedButton import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.State import androidx.compose.runtime.collectAsState import androidx.compose.runtime.derivedStateOf Loading @@ -74,6 +75,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Alignment import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier Loading Loading @@ -150,6 +152,8 @@ fun CommunalHub( val contentPadding = gridContentPadding(viewModel.isEditMode, toolbarSize) val contentOffset = beforeContentPadding(contentPadding).toOffset() ScrollOnNewSmartspaceEffect(viewModel, gridState) Box( modifier = modifier Loading Loading @@ -266,6 +270,34 @@ fun CommunalHub( } } @Composable private fun ScrollOnNewSmartspaceEffect( viewModel: BaseCommunalViewModel, gridState: LazyGridState ) { val communalContent by viewModel.communalContent.collectAsState(initial = emptyList()) var smartspaceCount by remember { mutableStateOf(0) } LaunchedEffect(communalContent) { snapshotFlow { gridState.firstVisibleItemIndex } .collect { index -> val existingSmartspaceCount = smartspaceCount smartspaceCount = communalContent.count { it.isSmartspace() } val firstIndex = communalContent.indexOfFirst { it.isSmartspace() } // Scroll to the beginning of the smartspace area whenever the number of // smartspace elements grows if ( existingSmartspaceCount < smartspaceCount && !viewModel.isEditMode && index > firstIndex ) { gridState.animateScrollToItem(firstIndex) } } } } @OptIn(ExperimentalFoundationApi::class) @Composable private fun BoxScope.CommunalHubLazyGrid( Loading
packages/SystemUI/src/com/android/systemui/communal/domain/model/CommunalContentModel.kt +2 −0 Original line number Diff line number Diff line Loading @@ -152,4 +152,6 @@ sealed interface CommunalContentModel { } fun isWidgetContent() = this is WidgetContent fun isSmartspace() = this is Smartspace }