Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee2d6002 authored by Andrew X's avatar Andrew X
Browse files

Request the focus on the QuickSettingsContainer when it shows

This CL requests the focus on QuickSettingsContainer when it shows. Then
the user only needs one tab key press to move focus on the QS toolbar's
profile button.

Without this change, the first several tab presses do not trigger any
focus ring, which is confusing.

Bug: 443126358
Flag: EXEMPT bugfix
Change-Id: I9d257f4a545df0632758dd03dad200eb9195beec
parent df7dfcb9
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
@@ -38,6 +39,7 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.IconButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
@@ -46,6 +48,8 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.blur
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
@@ -275,8 +279,20 @@ private fun ContentScope.QuickSettingsContainer(
        if (QsDetailedView.isEnabled) containerViewModel.detailsViewModel.activeTileDetails
        else null

    val focusRequester = remember { FocusRequester() }

    LaunchedEffect(focusRequester) {
        // Request focus on the `QuickSettingsContainer` without user interaction so that the user
        // can press the tab key once to enter the Quick Settings area. Without this line, the user
        // has to tab through unrelated views of the higher view hierarchy level.
        focusRequester.requestFocus()
    }

    AnimatedContent(
        modifier = Modifier.sysuiResTag("quick_settings_container"),
        modifier = Modifier
            .focusRequester(focusRequester)
            .focusable()
            .sysuiResTag("quick_settings_container"),
        targetState =
            when {
                isEditing -> ShadeBodyState.Editing