From bc9face5a14a6f9c43dd446aff49b1b67505740f Mon Sep 17 00:00:00 2001 From: Super12138 <70494801+Super12138@users.noreply.github.com> Date: Sun, 8 Feb 2026 08:07:00 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E5=BE=85?= =?UTF-8?q?=E5=8A=9E=E5=8D=A1=E7=89=87=E5=85=B1=E4=BA=AB=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E8=BD=AC=E5=9C=BA=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/ui/pages/editor/TodoEditorPage.kt | 3 +- .../todo/ui/pages/tasks/ProgressFragment.kt | 137 ------------------ .../todo/ui/pages/tasks/TasksPage.kt | 4 +- 3 files changed, 5 insertions(+), 139 deletions(-) delete mode 100644 app/src/main/kotlin/cn/super12138/todo/ui/pages/tasks/ProgressFragment.kt diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/TodoEditorPage.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/TodoEditorPage.kt index 2cd6a99..8df1660 100644 --- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/TodoEditorPage.kt +++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/TodoEditorPage.kt @@ -73,7 +73,8 @@ fun SharedTransitionScope.TodoEditPage( toDo = toDo, modifier = modifier.sharedBounds( sharedContentState = rememberSharedContentState(key = "${Constants.KEY_TODO_ITEM_TRANSITION}_${toDo.id}"), - animatedVisibilityScope = LocalNavAnimatedContentScope.current + animatedVisibilityScope = LocalNavAnimatedContentScope.current, + resizeMode = SharedTransitionScope.ResizeMode.RemeasureToBounds ), onSave = onSave, onDelete = onDelete, diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/tasks/ProgressFragment.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/tasks/ProgressFragment.kt deleted file mode 100644 index d38259b..0000000 --- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/tasks/ProgressFragment.kt +++ /dev/null @@ -1,137 +0,0 @@ -package cn.super12138.todo.ui.pages.tasks - -import androidx.compose.animation.AnimatedVisibility -import androidx.compose.animation.core.animateFloatAsState -import androidx.compose.animation.expandVertically -import androidx.compose.animation.fadeIn -import androidx.compose.animation.fadeOut -import androidx.compose.animation.shrinkVertically -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size -import androidx.compose.material3.CircularWavyProgressIndicator -import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.ProgressIndicatorDefaults -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.StrokeCap -import androidx.compose.ui.graphics.drawscope.Stroke -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.semantics.clearAndSetSemantics -import androidx.compose.ui.semantics.contentDescription -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.unit.dp -import cn.super12138.todo.R -import cn.super12138.todo.ui.TodoDefaults - -@OptIn(ExperimentalMaterial3ExpressiveApi::class) -@Composable -fun ProgressFragment( - totalTasks: Int, - completedTasks: Int, - modifier: Modifier = Modifier -) { - val context = LocalContext.current - - val thickStrokeWidth = with(LocalDensity.current) { TodoDefaults.trackThickness.toPx() } - val thickStroke = remember(thickStrokeWidth) { - Stroke(width = thickStrokeWidth, cap = StrokeCap.Round) - } - - val remainTasks = totalTasks - completedTasks - val progress = if (totalTasks != 0) { - completedTasks / totalTasks.toFloat() - } else { - // 没有任务时 - 0f - } - - Box( - modifier = modifier.padding(20.dp), - contentAlignment = Alignment.Center - ) { - val animatedProgress by animateFloatAsState( - targetValue = progress, - animationSpec = ProgressIndicatorDefaults.ProgressAnimationSpec - ) - - CircularWavyProgressIndicator( - progress = { animatedProgress }, - stroke = thickStroke, - trackStroke = thickStroke, - amplitude = { progress -> - if (progress <= 0.1f || progress >= 0.95f) { - 0f - } else { - TodoDefaults.waveAmplitude - } - }, - wavelength = TodoDefaults.waveLength, - waveSpeed = TodoDefaults.waveSpeed, - modifier = Modifier - .size(175.dp) - .clearAndSetSemantics {} - ) - - Column(horizontalAlignment = Alignment.CenterHorizontally) { - Row( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.clearAndSetSemantics { - contentDescription = if (totalTasks != 0) { - context.getString( - R.string.accessibility_progress_tasks, - totalTasks, - completedTasks, - remainTasks - ) - } else { - context.getString(R.string.accessibility_progress_no_tasks) - } - } - ) { - Text( - text = completedTasks.toString(), - style = MaterialTheme.typography.displaySmall.copy( - fontWeight = FontWeight.Bold - ) - ) - Text( - text = stringResource(R.string.placeholder_divider), - style = MaterialTheme.typography.displayMedium.copy( - fontWeight = FontWeight.Bold - ) - ) - Text( - text = totalTasks.toString(), - style = MaterialTheme.typography.displayMedium.copy( - fontWeight = FontWeight.Bold - ) - ) - } - AnimatedVisibility( - visible = remainTasks != 0, - enter = fadeIn(MaterialTheme.motionScheme.fastSpatialSpec()) + expandVertically( - MaterialTheme.motionScheme.fastSpatialSpec() - ), - exit = fadeOut(MaterialTheme.motionScheme.fastSpatialSpec()) + shrinkVertically( - MaterialTheme.motionScheme.fastSpatialSpec() - ), - ) { - Text( - text = stringResource(R.string.tip_remain_tasks, remainTasks), - style = MaterialTheme.typography.labelMedium, - modifier = Modifier.clearAndSetSemantics {} - ) - } - } - } -} \ No newline at end of file diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/tasks/TasksPage.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/tasks/TasksPage.kt index a287c0f..c3243d3 100644 --- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/tasks/TasksPage.kt +++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/tasks/TasksPage.kt @@ -27,6 +27,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.zIndex import androidx.navigation3.ui.LocalNavAnimatedContentScope import cn.super12138.todo.R import cn.super12138.todo.constants.Constants @@ -142,7 +143,8 @@ fun SharedTransitionScope.TasksPage( modifier = Modifier .sharedBounds( sharedContentState = rememberSharedContentState(key = "${Constants.KEY_TODO_ITEM_TRANSITION}_${task.id}"), - animatedVisibilityScope = LocalNavAnimatedContentScope.current + animatedVisibilityScope = LocalNavAnimatedContentScope.current, + resizeMode = SharedTransitionScope.ResizeMode.RemeasureToBounds ) .animateItem( fadeInSpec = MaterialTheme.motionScheme.defaultEffectsSpec(),