fix dialogs

This commit is contained in:
T8RIN
2024-11-10 18:47:00 +03:00
parent 7a336557ad
commit 2dcb552540
2 changed files with 21 additions and 28 deletions

View File

@ -17,7 +17,6 @@
package ru.tech.imageresizershrinker.core.ui.widget.enhanced package ru.tech.imageresizershrinker.core.ui.widget.enhanced
import android.view.Window
import androidx.activity.compose.PredictiveBackHandler import androidx.activity.compose.PredictiveBackHandler
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.Spring import androidx.compose.animation.core.Spring
@ -49,9 +48,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.compositionLocalWithComputedDefaultOf
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
@ -64,13 +60,11 @@ import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.semantics.paneTitle import androidx.compose.ui.semantics.paneTitle
import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.DialogWindowProvider
import com.t8rin.modalsheet.FullscreenPopup import com.t8rin.modalsheet.FullscreenPopup
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import ru.tech.imageresizershrinker.core.settings.presentation.provider.LocalSettingsState import ru.tech.imageresizershrinker.core.settings.presentation.provider.LocalSettingsState
@ -170,15 +164,6 @@ fun BasicEnhancedAlertDialog(
if (visibleAnimated) { if (visibleAnimated) {
FullscreenPopup { FullscreenPopup {
val dialogWindow = LocalDialogWindow.current
SideEffect {
dialogWindow.let { window ->
window?.setDimAmount(0f)
window?.setWindowAnimations(-1)
}
}
Box( Box(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center contentAlignment = Alignment.Center
@ -255,11 +240,6 @@ fun BasicEnhancedAlertDialog(
} }
} }
private val LocalDialogWindow: ProvidableCompositionLocal<Window?> =
compositionLocalWithComputedDefaultOf {
(LocalView.currentValue.parent as? DialogWindowProvider)?.window
}
@Composable @Composable
private fun EnhancedAlertDialogContent( private fun EnhancedAlertDialogContent(
buttons: @Composable () -> Unit, buttons: @Composable () -> Unit,

View File

@ -21,6 +21,9 @@ import androidx.activity.compose.BackHandler
import androidx.activity.compose.PredictiveBackHandler import androidx.activity.compose.PredictiveBackHandler
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
@ -53,6 +56,7 @@ import androidx.compose.material3.SheetValue
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.rememberBottomSheetScaffoldState import androidx.compose.material3.rememberBottomSheetScaffoldState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
@ -100,9 +104,22 @@ fun FullscreenEditOption(
) { ) {
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
var predictiveBackProgress by remember {
mutableFloatStateOf(0f)
}
LaunchedEffect(predictiveBackProgress, visible) {
if (!visible && predictiveBackProgress != 0f) {
delay(600)
predictiveBackProgress = 0f
}
}
AnimatedVisibility( AnimatedVisibility(
visible = visible, visible = visible,
modifier = Modifier.fillMaxSize() modifier = Modifier.fillMaxSize(),
enter = fadeIn(tween(600)),
exit = fadeOut(tween(600))
) { ) {
var showExitDialog by remember(visible) { mutableStateOf(false) } var showExitDialog by remember(visible) { mutableStateOf(false) }
val internalOnDismiss = { val internalOnDismiss = {
@ -112,9 +129,7 @@ fun FullscreenEditOption(
val direction = LocalLayoutDirection.current val direction = LocalLayoutDirection.current
val focus = LocalFocusManager.current val focus = LocalFocusManager.current
var predictiveBackProgress by remember {
mutableFloatStateOf(0f)
}
val animatedPredictiveBackProgress by animateFloatAsState(predictiveBackProgress) val animatedPredictiveBackProgress by animateFloatAsState(predictiveBackProgress)
val scale = (1f - animatedPredictiveBackProgress * 1.5f).coerceAtLeast(0.75f) val scale = (1f - animatedPredictiveBackProgress * 1.5f).coerceAtLeast(0.75f)
@ -316,12 +331,10 @@ fun FullscreenEditOption(
predictiveBackProgress = event.progress predictiveBackProgress = event.progress
} }
internalOnDismiss() internalOnDismiss()
} catch (_: Exception) { } catch (e: Exception) {
}
delay(400)
predictiveBackProgress = 0f predictiveBackProgress = 0f
} }
}
} else { } else {
BackHandler(onBack = internalOnDismiss) BackHandler(onBack = internalOnDismiss)
} }