fix(photo-editor): 修复外层 Card 未按图片比例自适应导致的上下黑边
This commit is contained in:
parent
b7607eebd9
commit
afd94604ad
@ -276,25 +276,29 @@ private fun EditorBody(
|
|||||||
.padding(16.dp),
|
.padding(16.dp),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
|
val srcAspect = state.sourceBitmap.width.toFloat() / state.sourceBitmap.height.toFloat()
|
||||||
|
val containerAspect by animateFloatAsState(
|
||||||
|
targetValue = RotationGeometry.stableAspect(srcAspect, state.rotationDegrees),
|
||||||
|
animationSpec = tween(durationMillis = 300, easing = FastOutSlowInEasing),
|
||||||
|
label = "rotateAspect"
|
||||||
|
)
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
shape = RoundedCornerShape(20.dp),
|
shape = RoundedCornerShape(20.dp),
|
||||||
colors = CardDefaults.cardColors(containerColor = Color.Black),
|
colors = CardDefaults.cardColors(containerColor = Color.Black),
|
||||||
border = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)),
|
border = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)),
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp)
|
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp),
|
||||||
|
modifier = Modifier.aspectRatio(containerAspect)
|
||||||
) {
|
) {
|
||||||
Box(
|
EditableImage(
|
||||||
modifier = Modifier.fillMaxSize(),
|
state = state,
|
||||||
contentAlignment = Alignment.Center
|
mode = activeTab,
|
||||||
) {
|
containerAspect = containerAspect,
|
||||||
EditableImage(
|
onCropChange = onCropChange,
|
||||||
state = state,
|
onAddPoint = onAddPoint,
|
||||||
mode = activeTab,
|
onEndStroke = onEndStroke,
|
||||||
onCropChange = onCropChange,
|
onDisplaySizeChange = onDisplaySizeChange
|
||||||
onAddPoint = onAddPoint,
|
)
|
||||||
onEndStroke = onEndStroke,
|
|
||||||
onDisplaySizeChange = onDisplaySizeChange
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (saving) {
|
if (saving) {
|
||||||
@ -345,11 +349,11 @@ private fun EditorBody(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun EditableImage(
|
private fun EditableImage(
|
||||||
state: PhotoEditorState,
|
state: PhotoEditorState,
|
||||||
mode: EditTab,
|
mode: EditTab,
|
||||||
|
containerAspect: Float,
|
||||||
onCropChange: (Float, Float, Float, Float) -> Unit,
|
onCropChange: (Float, Float, Float, Float) -> Unit,
|
||||||
onAddPoint: (Offset) -> Unit,
|
onAddPoint: (Offset) -> Unit,
|
||||||
onEndStroke: () -> Unit,
|
onEndStroke: () -> Unit,
|
||||||
@ -365,17 +369,9 @@ private fun EditableImage(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val srcAspect = state.sourceBitmap.width.toFloat() / state.sourceBitmap.height.toFloat()
|
|
||||||
val containerAspect by animateFloatAsState(
|
|
||||||
targetValue = RotationGeometry.stableAspect(srcAspect, state.rotationDegrees),
|
|
||||||
animationSpec = tween(durationMillis = 300, easing = FastOutSlowInEasing),
|
|
||||||
label = "rotateAspect"
|
|
||||||
)
|
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxSize()
|
||||||
.aspectRatio(containerAspect)
|
|
||||||
.background(Color.Black)
|
.background(Color.Black)
|
||||||
.onSizeChanged { size ->
|
.onSizeChanged { size ->
|
||||||
if (size.width > 0 && size.height > 0) {
|
if (size.width > 0 && size.height > 0) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user