revert(photo-editor): 恢复点击裁剪 icon 进入裁剪的交互

撤销"切到裁剪 tab 自动进入裁剪"的改动,保留原来的两步操作:
点击下方裁剪 icon 进入裁剪模式,再次点击 ✓ 确认裁剪。

ViewModel 恢复 toggleCrop,删除无用的 enterCrop/exitCrop;
保留裁剪框拖动的 bug 修复(本地累积值 + rememberUpdatedState)。
This commit is contained in:
xfy 2026-07-22 15:20:13 +08:00
parent d3ebd6829b
commit 70c97ed9d5
2 changed files with 18 additions and 20 deletions

View File

@ -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)
}
}
}

View File

@ -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()) {