mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
Fix FEX dropdown scaling and Discover search focus (#681)
This commit is contained in:
1 parent
1c1a96cb19
commit
623fb3fb62
5 files changed
+217
-3
No files matched your search
@@ -62,6 +62,7 @@ import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -98,6 +99,7 @@ import androidx.compose.ui.text.style.TextAlign
|
||||
import kotlin.math.roundToInt
|
||||
import androidx.compose.ui.input.InputMode
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalInputModeManager
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
@@ -281,11 +283,16 @@ fun AnchoredMenu(
|
||||
android.util.Log.i("AnchoredMenu", "requested first option focus")
|
||||
}
|
||||
}
|
||||
val gap = with(LocalDensity.current) { 6.dp.roundToPx() }
|
||||
// Popup installs Android's window density. Keep the app scale from the anchor, including
|
||||
// the matching dp window dimensions used to cap and scroll the menu.
|
||||
val density = LocalDensity.current
|
||||
val configuration = LocalConfiguration.current
|
||||
val gap = with(density) { 6.dp.roundToPx() }
|
||||
val provider = remember(gap, compact) { if (compact) BelowStartProvider(gap) else BelowEndProvider(gap) }
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
Popup(popupPositionProvider = provider, onDismissRequest = onDismiss, properties = PopupProperties(focusable = true)) {
|
||||
CompositionLocalProvider(LocalDensity provides density, LocalConfiguration provides configuration) {
|
||||
AnimatedVisibility(
|
||||
visibleState = state,
|
||||
enter = fadeIn(Motion.tw(180)) + scaleIn(Motion.sp(0.7f), initialScale = 0.94f, transformOrigin = TransformOrigin(if (compact) 0f else 1f, 0f)),
|
||||
@@ -345,6 +352,7 @@ fun AnchoredMenu(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.clipToBounds
|
||||
import androidx.compose.ui.draw.drawBehind
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.focus.focusProperties
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.geometry.Rect
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
@@ -85,7 +86,10 @@ import androidx.compose.ui.layout.onSizeChanged
|
||||
import androidx.compose.ui.layout.positionInRoot
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.platform.LocalInputModeManager
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
@@ -267,8 +271,9 @@ private fun SetupButton(s: FrontEndState, busy: Boolean, full: Dp, ring: Int, on
|
||||
|
||||
// ---- storefront ------------------------------------------------------------------------------------
|
||||
|
||||
@OptIn(androidx.compose.ui.ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
private fun Storefront(s: FrontEndState, a: FrontEndActions) {
|
||||
internal fun Storefront(s: FrontEndState, a: FrontEndActions) {
|
||||
val ctx = LocalContext.current
|
||||
val narrow = LocalNarrowPane.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
@@ -290,6 +295,9 @@ private fun Storefront(s: FrontEndState, a: FrontEndActions) {
|
||||
}
|
||||
val ff = LocalFrontFocus.current
|
||||
val inputMode = LocalInputModeManager.current
|
||||
val focusManager = LocalFocusManager.current
|
||||
val keyboard = LocalSoftwareKeyboardController.current
|
||||
val view = LocalView.current
|
||||
// Cards, where they are, for the page that opens from one.
|
||||
val cards = remember { HashMap<String, Rect>() }
|
||||
var viewportAt by remember { mutableStateOf(Offset.Zero) }
|
||||
@@ -300,6 +308,11 @@ private fun Storefront(s: FrontEndState, a: FrontEndActions) {
|
||||
LaunchedEffect(openApp) {
|
||||
val id = openApp
|
||||
if (id != null) {
|
||||
// The grid stays composed for the return animation. Release its native search field
|
||||
// before covering it, so its focus ring and keyboard do not follow onto the app page.
|
||||
focusManager.clearFocus(force = true)
|
||||
view.findFocus()?.clearFocus()
|
||||
keyboard?.hide()
|
||||
detailFrom = cards[id]?.let { Origin(it.translate(-viewportAt), 16f * density.density) }
|
||||
leaving = false
|
||||
detail = id
|
||||
@@ -350,7 +363,10 @@ private fun Storefront(s: FrontEndState, a: FrontEndActions) {
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Box(Modifier.weight(1f).fillMaxWidth().clipToBounds().onGloballyPositioned { viewportAt = it.positionInRoot() }) {
|
||||
Column(
|
||||
Modifier.fillMaxSize().graphicsLayer { scaleX = sink; scaleY = sink; alpha = fade }.verticalScroll(rememberScrollState()).padding(bottom = 16.dp),
|
||||
Modifier.fillMaxSize().focusProperties {
|
||||
enter = { if (detail == null) androidx.compose.ui.focus.FocusRequester.Default else androidx.compose.ui.focus.FocusRequester.Cancel }
|
||||
}.focusGroup()
|
||||
.graphicsLayer { scaleX = sink; scaleY = sink; alpha = fade }.verticalScroll(rememberScrollState()).padding(bottom = 16.dp),
|
||||
) {
|
||||
val open: (String) -> Unit = { openApp = it }
|
||||
when (mode) {
|
||||
|
||||
Reference in new issue
Block a user