From 6cf8747eeecd8d5910c3fe08d6ba207a5b20d79f Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Sun, 8 Oct 2023 15:38:39 +0200 Subject: [PATCH] Pull down scaffold: add scale animation --- .../launcher2/ui/launcher/PullDownScaffold.kt | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/PullDownScaffold.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/PullDownScaffold.kt index 3362e28b..110d5f5c 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/PullDownScaffold.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/PullDownScaffold.kt @@ -1,5 +1,6 @@ package de.mm20.launcher2.ui.launcher +import android.app.WallpaperManager import android.view.HapticFeedbackConstants import androidx.activity.compose.BackHandler import androidx.compose.animation.AnimatedVisibility @@ -49,6 +50,7 @@ import androidx.compose.runtime.remember 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.geometry.Offset import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.TransformOrigin @@ -86,6 +88,7 @@ import de.mm20.launcher2.ui.launcher.widgets.clock.ClockWidget import de.mm20.launcher2.ui.locals.LocalPreferDarkContentOverWallpaper import kotlinx.coroutines.launch import kotlin.math.absoluteValue +import kotlin.math.min import kotlin.math.roundToInt @Composable @@ -101,6 +104,7 @@ fun PullDownScaffold( val searchVM: SearchVM = viewModel() val density = LocalDensity.current + val context = LocalContext.current val actions by searchVM.searchActionResults @@ -148,6 +152,12 @@ fun PullDownScaffold( } } + val dragProgress by remember { + derivedStateOf { + (offsetY.value.absoluteValue / toggleSearchThreshold).coerceAtMost(1f) + } + } + val systemUiController = rememberSystemUiController() val isWidgetsAtStart by remember { @@ -379,7 +389,6 @@ fun PullDownScaffold( } ) } - //.nestedScroll(nestedScrollConnection) .offset { IntOffset(0, offsetY.value.toInt()) }, contentAlignment = Alignment.TopCenter ) { @@ -428,6 +437,8 @@ fun PullDownScaffold( pagerState.currentPage + pagerState.currentPageOffsetFraction transformOrigin = TransformOrigin.Center alpha = 1 - progress + scaleX = 1f - (dragProgress * 0.05f) + scaleY = 1f - (dragProgress * 0.05f) } .pointerInput(gestureManager.shouldDetectDoubleTaps) { detectTapGestures( @@ -493,7 +504,9 @@ fun PullDownScaffold( val progress = pagerState.currentPage + pagerState.currentPageOffsetFraction transformOrigin = TransformOrigin.Center - alpha = progress + alpha = min(progress, 1f - dragProgress * 0.1f) + scaleX = min(1f - (dragProgress * 0.05f), 1f - (1f - progress) * 0.1f) + scaleY = min(1f - (dragProgress * 0.05f),1f - (1f - progress) * 0.1f) } .fillMaxSize() .padding( @@ -560,8 +573,6 @@ fun PullDownScaffold( val searchBarColor by viewModel.searchBarColor.collectAsState() val searchBarStyle by viewModel.searchBarStyle.collectAsState() - val context = LocalContext.current - val launchOnEnter by searchVM.launchOnEnter.collectAsState(false) LauncherSearchBar(