From 70c97ed9d523ebe6558d58c86f5ec86a0667da78 Mon Sep 17 00:00:00 2001 From: xfy Date: Wed, 22 Jul 2026 15:20:13 +0800 Subject: [PATCH] =?UTF-8?q?revert(photo-editor):=20=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E8=A3=81=E5=89=AA=20icon=20=E8=BF=9B?= =?UTF-8?q?=E5=85=A5=E8=A3=81=E5=89=AA=E7=9A=84=E4=BA=A4=E4=BA=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 撤销"切到裁剪 tab 自动进入裁剪"的改动,保留原来的两步操作: 点击下方裁剪 icon 进入裁剪模式,再次点击 ✓ 确认裁剪。 ViewModel 恢复 toggleCrop,删除无用的 enterCrop/exitCrop; 保留裁剪框拖动的 bug 修复(本地累积值 + rememberUpdatedState)。 --- .../plus/rua/project/PhotoEditorViewModel.kt | 18 +++++++---------- .../plus/rua/project/ui/PhotoEditorScreen.kt | 20 ++++++++++--------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/core/src/main/kotlin/plus/rua/project/PhotoEditorViewModel.kt b/core/src/main/kotlin/plus/rua/project/PhotoEditorViewModel.kt index 80431dc..71c3a48 100644 --- a/core/src/main/kotlin/plus/rua/project/PhotoEditorViewModel.kt +++ b/core/src/main/kotlin/plus/rua/project/PhotoEditorViewModel.kt @@ -80,18 +80,14 @@ class PhotoEditorViewModel( update { it.copy(rotationDegrees = it.rotationDegrees + delta) } } - /** 进入裁剪模式:仅在尚未启用时初始化为默认居中区域,已启用则保留当前框。 */ - fun enterCrop() { + /** 开启/关闭裁剪。开启时使用默认居中 4:3 裁剪框。 */ + fun toggleCrop() { update { - if (it.cropEnabled) it - else it.copy(cropLeft = 0.1f, cropTop = 0.1f, cropRight = 0.9f, cropBottom = 0.9f) - } - } - - /** 退出裁剪模式:清空裁剪框(不应用裁剪)。 */ - fun exitCrop() { - update { - it.copy(cropLeft = null, cropRight = null, cropTop = 0f, cropBottom = 1f) + if (it.cropEnabled) { + it.copy(cropLeft = null, cropRight = null, cropTop = 0f, cropBottom = 1f) + } else { + it.copy(cropLeft = 0.1f, cropTop = 0.1f, cropRight = 0.9f, cropBottom = 0.9f) + } } } diff --git a/core/src/main/kotlin/plus/rua/project/ui/PhotoEditorScreen.kt b/core/src/main/kotlin/plus/rua/project/ui/PhotoEditorScreen.kt index 33fb1a4..a68e8c4 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/PhotoEditorScreen.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/PhotoEditorScreen.kt @@ -97,14 +97,6 @@ fun PhotoEditorScreen( var activeTab by remember { mutableStateOf(EditTab.ROTATE) } val savedPath = state.savedPath - // 切到裁剪 tab 自动进入裁剪模式;切走则退出(不应用裁剪) - LaunchedEffect(activeTab, state.editorState) { - when (activeTab) { - EditTab.CROP -> viewModel.enterCrop() - else -> viewModel.exitCrop() - } - } - if (savedPath != null) { LaunchedEffect(savedPath) { onSaved(savedPath) } } @@ -167,6 +159,7 @@ fun PhotoEditorScreen( activeTab = activeTab, onTabChange = { activeTab = it }, onRotate = viewModel::rotate, + onCropToggle = viewModel::toggleCrop, onApplyCrop = viewModel::applyCrop, onCropChange = viewModel::updateCrop, onAddPoint = viewModel::addStrokePoint, @@ -191,6 +184,7 @@ private fun EditorBody( activeTab: EditTab, onTabChange: (EditTab) -> Unit, onRotate: (Int) -> Unit, + onCropToggle: () -> Unit, onApplyCrop: () -> Unit, onCropChange: (Float, Float, Float, Float) -> Unit, onAddPoint: (Offset) -> Unit, @@ -255,6 +249,7 @@ private fun EditorBody( mode = activeTab, state = state, onRotate = onRotate, + onCropToggle = onCropToggle, onApplyCrop = onApplyCrop, onUndoStroke = onUndoStroke, onStrokeColorChange = onStrokeColorChange, @@ -522,6 +517,7 @@ private fun ToolBar( mode: EditTab, state: PhotoEditorState, onRotate: (Int) -> Unit, + onCropToggle: () -> Unit, onApplyCrop: () -> Unit, onUndoStroke: () -> Unit, onStrokeColorChange: (Color) -> Unit, @@ -541,10 +537,16 @@ private fun ToolBar( Icon(Icons.Filled.RotateRight, contentDescription = "右转 90°") } } - EditTab.CROP -> { + EditTab.CROP -> if (state.cropEnabled) { + // 已进入裁剪模式:✓ 确认裁剪(烘焙到源图) FilledIconButton(onClick = onApplyCrop) { Icon(Icons.Filled.Done, contentDescription = "确认裁剪") } + } else { + // 未进入:点击进入裁剪模式 + FilledIconButton(onClick = onCropToggle) { + Icon(Icons.Filled.Crop, contentDescription = "进入裁剪") + } } EditTab.HANDWRITE -> { IconButton(onClick = onUndoStroke, enabled = state.strokes.isNotEmpty()) {