From 03ec6b0eb54381bbde3f396d7102fdbcf99628ea Mon Sep 17 00:00:00 2001 From: samosvalishe Date: Mon, 21 Sep 2026 14:11:06 +0300 Subject: [PATCH] =?UTF-8?q?perf(ui):=20=D0=BD=D0=B5=20=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D0=BE=D0=BC=D0=BF=D0=BE=D0=B7=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B2=D1=81=D1=8E=20=D0=BA=D0=BD=D0=BE=D0=BF?= =?UTF-8?q?=D0=BA=D1=83=20=D0=B3=D0=B5=D1=80=D0=BE=D1=8F=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BA=D0=B0=D0=B6=D0=B4=D0=BE=D0=BC=20=D0=BA=D0=B0=D0=B4=D1=80?= =?UTF-8?q?=D0=B5=20=D0=BC=D0=BE=D1=80=D1=84=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/screens/home/ConnectionHero.kt | 114 ++++++++++++------ 1 file changed, 75 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/com/freeturn/app/ui/screens/home/ConnectionHero.kt b/app/src/main/java/com/freeturn/app/ui/screens/home/ConnectionHero.kt index 717777e..3a12976 100644 --- a/app/src/main/java/com/freeturn/app/ui/screens/home/ConnectionHero.kt +++ b/app/src/main/java/com/freeturn/app/ui/screens/home/ConnectionHero.kt @@ -53,6 +53,7 @@ import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.Density +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp @@ -141,8 +142,6 @@ private fun HeroToggleButton( // Форма, размер и цвет тянутся одними и теми же спеками - иначе переход распадается на слои. val colorSpec = MaterialTheme.motionScheme.slowEffectsSpec() val spatialSpec = MaterialTheme.motionScheme.defaultSpatialSpec() - val effectsSpec = MaterialTheme.motionScheme.defaultEffectsSpec() - val fastEffectsSpec = MaterialTheme.motionScheme.fastEffectsSpec() val containerColor by animateColorAsState( targetValue = when (kind) { @@ -171,18 +170,16 @@ private fun HeroToggleButton( label = "btn_scale" ) - val heroShape = rememberMorphingShape( - target = when (kind) { - HeroKind.Idle -> MaterialShapes.Cookie12Sided - HeroKind.Busy -> MaterialShapes.Sunny - HeroKind.Running -> MaterialShapes.Circle - HeroKind.Error -> MaterialShapes.SoftBurst - }, - reducedMotion = reducedMotion - ) + val heroTarget = when (kind) { + HeroKind.Idle -> MaterialShapes.Cookie12Sided + HeroKind.Busy -> MaterialShapes.Sunny + HeroKind.Running -> MaterialShapes.Circle + HeroKind.Error -> MaterialShapes.SoftBurst + } val rotation = rememberHeroSpin(spinning = kind == HeroKind.Busy && !reducedMotion) val handSpin = remember { Animatable(0f) } + val handSpinState = handSpin.asState() val spinnable = decor && kind == HeroKind.Idle val settleSpec = MaterialTheme.motionScheme.slowSpatialSpec() LaunchedEffect(spinnable) { @@ -201,8 +198,12 @@ private fun HeroToggleButton( ) } - Surface( + MorphingHeroSurface( + target = heroTarget, + reducedMotion = reducedMotion, onClick = onClick, + color = containerColor, + tonalElevation = if (kind == HeroKind.Running) 3.dp else 1.dp, modifier = Modifier .size(HeroButtonSize) .leafSpin(handSpin, spinnable) @@ -212,42 +213,77 @@ private fun HeroToggleButton( scaleY = scale.value rotationZ = rotation.value + handSpin.value } - .semantics { contentDescription = buttonLabel }, - shape = heroShape, - color = containerColor, - tonalElevation = if (kind == HeroKind.Running) 3.dp else 1.dp + .semantics { contentDescription = buttonLabel } ) { - Box( - // Контр-вращение: крутится только фигура. - modifier = Modifier - .fillMaxSize() - .graphicsLayer { rotationZ = -(rotation.value + handSpin.value) }, - contentAlignment = Alignment.Center - ) { - if (reducedMotion) { - HeroIcon(kind = kind, tint = contentColor) - } else { - AnimatedContent( - targetState = kind, - transitionSpec = { - (fadeIn(effectsSpec) + scaleIn(spatialSpec, initialScale = 0.85f)) - .togetherWith(fadeOut(fastEffectsSpec) + scaleOut(fastEffectsSpec, targetScale = 0.85f)) - }, - label = "hero_icon" - ) { k -> - HeroIcon(kind = k, tint = contentColor) - } - } - } + HeroFace( + kind = kind, + tint = contentColor, + reducedMotion = reducedMotion, + rotation = rotation, + handSpin = handSpinState + ) } - // Поверх кнопки: слой без pointerInput, тап проходит насквозь в Surface. if (decor) { AutumnLeafBurst(burstKey = burstKey, buttonSize = HeroButtonSize) } } } +@Composable +private fun MorphingHeroSurface( + target: RoundedPolygon, + reducedMotion: Boolean, + onClick: () -> Unit, + color: Color, + tonalElevation: Dp, + modifier: Modifier = Modifier, + content: @Composable () -> Unit +) { + Surface( + onClick = onClick, + modifier = modifier, + shape = rememberMorphingShape(target, reducedMotion), + color = color, + tonalElevation = tonalElevation, + content = content + ) +} + +@Composable +private fun HeroFace( + kind: HeroKind, + tint: Color, + reducedMotion: Boolean, + rotation: State, + handSpin: State +) { + Box( + modifier = Modifier + .fillMaxSize() + .graphicsLayer { rotationZ = -(rotation.value + handSpin.value) }, + contentAlignment = Alignment.Center + ) { + if (reducedMotion) { + HeroIcon(kind = kind, tint = tint) + } else { + val spatialSpec = MaterialTheme.motionScheme.defaultSpatialSpec() + val effectsSpec = MaterialTheme.motionScheme.defaultEffectsSpec() + val fastEffectsSpec = MaterialTheme.motionScheme.fastEffectsSpec() + AnimatedContent( + targetState = kind, + transitionSpec = { + (fadeIn(effectsSpec) + scaleIn(spatialSpec, initialScale = 0.85f)) + .togetherWith(fadeOut(fastEffectsSpec) + scaleOut(fastEffectsSpec, targetScale = 0.85f)) + }, + label = "hero_icon" + ) { k -> + HeroIcon(kind = k, tint = tint) + } + } + } +} + /** Непрерывное вращение фигуры с доводом до полного оборота на выходе. */ @Composable private fun rememberHeroSpin(spinning: Boolean): State {