diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/qs/composefragment/QSFragmentCompose.kt | 133 |
1 files changed, 65 insertions, 68 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/composefragment/QSFragmentCompose.kt b/packages/SystemUI/src/com/android/systemui/qs/composefragment/QSFragmentCompose.kt index 66ac01ab95a0..51d232946b97 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/composefragment/QSFragmentCompose.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/composefragment/QSFragmentCompose.kt @@ -52,7 +52,6 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.layout.onPlaced import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.layout.positionInRoot @@ -62,7 +61,6 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.CustomAccessibilityAction import androidx.compose.ui.semantics.customActions import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.round import androidx.lifecycle.Lifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle @@ -191,58 +189,22 @@ constructor( val context = inflater.context val composeView = ComposeView(context).apply { - setBackPressedDispatcher() - setContent { - PlatformTheme { - val visible by viewModel.qsVisible.collectAsStateWithLifecycle() - - AnimatedVisibility( - visible = visible, - modifier = - Modifier.windowInsetsPadding(WindowInsets.navigationBars) - .thenIf(notificationScrimClippingParams.isEnabled) { - Modifier.notificationScrimClip( - notificationScrimClippingParams.leftInset, - notificationScrimClippingParams.top, - notificationScrimClippingParams.rightInset, - notificationScrimClippingParams.bottom, - notificationScrimClippingParams.radius, + repeatWhenAttached { + repeatOnLifecycle(Lifecycle.State.CREATED) { + setViewTreeOnBackPressedDispatcherOwner( + object : OnBackPressedDispatcherOwner { + override val onBackPressedDispatcher = + OnBackPressedDispatcher().apply { + setOnBackInvokedDispatcher( + it.viewRootImpl.onBackInvokedDispatcher ) } - .graphicsLayer { elevation = 4.dp.toPx() }, - ) { - val isEditing by - viewModel.containerViewModel.editModeViewModel.isEditing - .collectAsStateWithLifecycle() - val animationSpecEditMode = tween<Float>(EDIT_MODE_TIME_MILLIS) - AnimatedContent( - targetState = isEditing, - transitionSpec = { - fadeIn(animationSpecEditMode) togetherWith - fadeOut(animationSpecEditMode) - }, - label = "EditModeAnimatedContent", - ) { editing -> - if (editing) { - val qqsPadding by - viewModel.qqsHeaderHeight.collectAsStateWithLifecycle() - EditMode( - viewModel = viewModel.containerViewModel.editModeViewModel, - modifier = - Modifier.fillMaxWidth() - .padding(top = { qqsPadding }) - .padding( - horizontal = { - QuickSettingsShade.Dimensions.Padding - .roundToPx() - } - ), - ) - } else { - CollapsableQuickSettingsSTL() - } + + override val lifecycle: Lifecycle = + this@repeatWhenAttached.lifecycle } - } + ) + setContent { this@QSFragmentCompose.Content() } } } } @@ -261,6 +223,58 @@ constructor( return frame } + @Composable + private fun Content() { + PlatformTheme { + val visible by viewModel.qsVisible.collectAsStateWithLifecycle() + + AnimatedVisibility( + visible = visible, + modifier = + Modifier.windowInsetsPadding(WindowInsets.navigationBars).thenIf( + notificationScrimClippingParams.isEnabled + ) { + Modifier.notificationScrimClip( + notificationScrimClippingParams.leftInset, + notificationScrimClippingParams.top, + notificationScrimClippingParams.rightInset, + notificationScrimClippingParams.bottom, + notificationScrimClippingParams.radius, + ) + }, + ) { + val isEditing by + viewModel.containerViewModel.editModeViewModel.isEditing + .collectAsStateWithLifecycle() + val animationSpecEditMode = tween<Float>(EDIT_MODE_TIME_MILLIS) + AnimatedContent( + targetState = isEditing, + transitionSpec = { + fadeIn(animationSpecEditMode) togetherWith fadeOut(animationSpecEditMode) + }, + label = "EditModeAnimatedContent", + ) { editing -> + if (editing) { + val qqsPadding by viewModel.qqsHeaderHeight.collectAsStateWithLifecycle() + EditMode( + viewModel = viewModel.containerViewModel.editModeViewModel, + modifier = + Modifier.fillMaxWidth() + .padding(top = { qqsPadding }) + .padding( + horizontal = { + QuickSettingsShade.Dimensions.Padding.roundToPx() + } + ), + ) + } else { + CollapsableQuickSettingsSTL() + } + } + } + } + } + /** * STL that contains both QQS (tiles) and QS (brightness, tiles, footer actions), but no Edit * mode. It tracks [QSFragmentComposeViewModel.expansionState] to drive the transition between @@ -649,23 +663,6 @@ constructor( } } -private fun View.setBackPressedDispatcher() { - repeatWhenAttached { - repeatOnLifecycle(Lifecycle.State.CREATED) { - setViewTreeOnBackPressedDispatcherOwner( - object : OnBackPressedDispatcherOwner { - override val onBackPressedDispatcher = - OnBackPressedDispatcher().apply { - setOnBackInvokedDispatcher(it.viewRootImpl.onBackInvokedDispatcher) - } - - override val lifecycle: Lifecycle = this@repeatWhenAttached.lifecycle - } - ) - } - } -} - private suspend inline fun <Listener : Any, Data> setListenerJob( listenerFlow: MutableStateFlow<Listener?>, dataFlow: Flow<Data>, |