Fix z order of popups

This commit is contained in:
MM20 2023-10-01 21:35:36 +02:00
parent 5a821eaabe
commit e08e9a370c
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
5 changed files with 17 additions and 12 deletions

View File

@ -66,6 +66,7 @@ import androidx.compose.ui.window.Popup
import androidx.compose.ui.window.PopupPositionProvider import androidx.compose.ui.window.PopupPositionProvider
import androidx.compose.ui.window.PopupProperties import androidx.compose.ui.window.PopupProperties
import de.mm20.launcher2.ui.ktx.toPixels import de.mm20.launcher2.ui.ktx.toPixels
import de.mm20.launcher2.ui.overlays.LocalZIndex
import de.mm20.launcher2.ui.overlays.Overlay import de.mm20.launcher2.ui.overlays.Overlay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlin.math.min import kotlin.math.min
@ -79,6 +80,7 @@ fun BottomSheetDialog(
confirmButton: @Composable (() -> Unit)? = null, confirmButton: @Composable (() -> Unit)? = null,
dismissButton: @Composable (() -> Unit)? = null, dismissButton: @Composable (() -> Unit)? = null,
dismissible: () -> Boolean = { true }, dismissible: () -> Boolean = { true },
zIndex: Float = LocalZIndex.current + 1f,
content: @Composable (paddingValues: PaddingValues) -> Unit, content: @Composable (paddingValues: PaddingValues) -> Unit,
) { ) {
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
@ -155,13 +157,7 @@ fun BottomSheetDialog(
CompositionLocalProvider( CompositionLocalProvider(
LocalAbsoluteTonalElevation provides 0.dp, LocalAbsoluteTonalElevation provides 0.dp,
) { ) {
val density = LocalDensity.current Overlay(zIndex = zIndex) {
val insets = WindowInsets.systemBars
WindowInsets
val positionProvider = remember(insets, density) {
BottomSheetPositionProvider(insets, density)
}
Overlay(zIndex = 9999f) {
BoxWithConstraints( BoxWithConstraints(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()

View File

@ -207,7 +207,7 @@ fun ItemPopup(origin: Rect, searchable: Searchable, onDismissRequest: () -> Unit
show.targetState = false show.targetState = false
} }
Overlay(zIndex = 1f) { Overlay {
Box( Box(
modifier = Modifier modifier = Modifier
.background(MaterialTheme.colorScheme.scrim.copy(alpha = 0.32f * animationProgress.value)) .background(MaterialTheme.colorScheme.scrim.copy(alpha = 0.32f * animationProgress.value))

View File

@ -92,7 +92,8 @@ fun CustomizeSearchableSheet(
Text(stringResource(id = android.R.string.cancel)) Text(stringResource(id = android.R.string.cancel))
} }
} }
} else null } else null,
zIndex = 100f,
) { ) {
if (!pickIcon) { if (!pickIcon) {
Column( Column(

View File

@ -5,7 +5,7 @@ import androidx.compose.runtime.DisposableEffect
@Composable @Composable
fun Overlay( fun Overlay(
zIndex: Float = 0f, zIndex: Float = LocalZIndex.current + 1f,
overlay: @Composable () -> Unit overlay: @Composable () -> Unit
) { ) {
val overlayManager = LocalOverlayManager.current val overlayManager = LocalOverlayManager.current

View File

@ -26,8 +26,12 @@ fun OverlayHost(
content() content()
} }
for (overlay in overlayManager.overlays) { for (overlay in overlayManager.overlays) {
Box(modifier = Modifier.zIndex(overlay.zIndex + 1f)) { Box(modifier = Modifier.zIndex(overlay.zIndex)) {
overlay() CompositionLocalProvider(
LocalZIndex provides overlay.zIndex
) {
overlay()
}
} }
} }
} }
@ -37,3 +41,7 @@ fun OverlayHost(
val LocalOverlayManager = compositionLocalOf<OverlayManager> { val LocalOverlayManager = compositionLocalOf<OverlayManager> {
OverlayManager() OverlayManager()
} }
val LocalZIndex = compositionLocalOf<Float> {
0f
}