From bba6a56b4d628d5c26d4ac19c2c2e194eb301032 Mon Sep 17 00:00:00 2001 From: dinaraparanid Date: Fri, 22 Mar 2024 18:10:10 +0300 Subject: [PATCH 1/2] crop until full width/height --- .../main/java/com/smarttoolfactory/cropper/CropModifier.kt | 1 - .../java/com/smarttoolfactory/cropper/state/CropStateImpl.kt | 3 ++- .../java/com/smarttoolfactory/cropper/state/TransformState.kt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cropper/src/main/java/com/smarttoolfactory/cropper/CropModifier.kt b/cropper/src/main/java/com/smarttoolfactory/cropper/CropModifier.kt index 539afee..14ef68c 100644 --- a/cropper/src/main/java/com/smarttoolfactory/cropper/CropModifier.kt +++ b/cropper/src/main/java/com/smarttoolfactory/cropper/CropModifier.kt @@ -77,7 +77,6 @@ fun Modifier.crop( } }, onGesture = { centroid, pan, zoom, rotate, mainPointer, pointerList -> - coroutineScope.launch { cropState.onGesture( centroid = centroid, diff --git a/cropper/src/main/java/com/smarttoolfactory/cropper/state/CropStateImpl.kt b/cropper/src/main/java/com/smarttoolfactory/cropper/state/CropStateImpl.kt index e1039c1..3e1303d 100644 --- a/cropper/src/main/java/com/smarttoolfactory/cropper/state/CropStateImpl.kt +++ b/cropper/src/main/java/com/smarttoolfactory/cropper/state/CropStateImpl.kt @@ -294,7 +294,8 @@ abstract class CropState internal constructor( animationSpec: AnimationSpec = tween(400) ) { - val zoom = zoom.coerceAtLeast(1f) + // Оставляем текущий zoom + // val zoom = zoom.coerceAtLeast(1f) // Calculate new pan based on overlay val newDrawAreaRect = calculateValidImageDrawRect(overlayRect, drawAreaRect) diff --git a/cropper/src/main/java/com/smarttoolfactory/cropper/state/TransformState.kt b/cropper/src/main/java/com/smarttoolfactory/cropper/state/TransformState.kt index 2191385..cf38d5a 100644 --- a/cropper/src/main/java/com/smarttoolfactory/cropper/state/TransformState.kt +++ b/cropper/src/main/java/com/smarttoolfactory/cropper/state/TransformState.kt @@ -37,7 +37,7 @@ open class TransformState( val drawAreaSize: IntSize, initialZoom: Float = 1f, initialRotation: Float = 0f, - minZoom: Float = 1f, + minZoom: Float = 0.5f, // точно хватит maxZoom: Float = 10f, internal var zoomable: Boolean = true, internal var pannable: Boolean = true, @@ -55,7 +55,7 @@ open class TransformState( ) ) - internal val zoomMin = minZoom.coerceAtLeast(1f) + internal val zoomMin = minZoom.coerceAtLeast(0.5f) // точно хватит internal var zoomMax = maxZoom.coerceAtLeast(1f) private val zoomInitial = initialZoom.coerceIn(zoomMin, zoomMax) private val rotationInitial = initialRotation % 360 From 6452ce170b9510894901b3a1f5f48397d920cfef Mon Sep 17 00:00:00 2001 From: dinaraparanid Date: Sat, 23 Mar 2024 14:56:25 +0300 Subject: [PATCH 2/2] codestyle fixes --- .../com/smarttoolfactory/cropper/state/CropStateImpl.kt | 6 +++--- .../com/smarttoolfactory/cropper/state/TransformState.kt | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cropper/src/main/java/com/smarttoolfactory/cropper/state/CropStateImpl.kt b/cropper/src/main/java/com/smarttoolfactory/cropper/state/CropStateImpl.kt index 3e1303d..67a9e60 100644 --- a/cropper/src/main/java/com/smarttoolfactory/cropper/state/CropStateImpl.kt +++ b/cropper/src/main/java/com/smarttoolfactory/cropper/state/CropStateImpl.kt @@ -17,6 +17,8 @@ import com.smarttoolfactory.cropper.model.AspectRatio import com.smarttoolfactory.cropper.model.CropData import com.smarttoolfactory.cropper.settings.CropProperties +internal const val MIN_OVERLAY_RATIO = 0.5F + val CropState.cropData: CropData get() = CropData( zoom = animatableZoom.targetValue, @@ -293,9 +295,7 @@ abstract class CropState internal constructor( animate: Boolean, animationSpec: AnimationSpec = tween(400) ) { - - // Оставляем текущий zoom - // val zoom = zoom.coerceAtLeast(1f) + val zoom = zoom.coerceAtLeast(MIN_OVERLAY_RATIO) // Calculate new pan based on overlay val newDrawAreaRect = calculateValidImageDrawRect(overlayRect, drawAreaRect) diff --git a/cropper/src/main/java/com/smarttoolfactory/cropper/state/TransformState.kt b/cropper/src/main/java/com/smarttoolfactory/cropper/state/TransformState.kt index cf38d5a..9fadc91 100644 --- a/cropper/src/main/java/com/smarttoolfactory/cropper/state/TransformState.kt +++ b/cropper/src/main/java/com/smarttoolfactory/cropper/state/TransformState.kt @@ -16,6 +16,8 @@ import androidx.compose.ui.unit.IntSize import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch +private const val MAX_ZOOM = 10F + /** * State of the pan, zoom and rotation. Allows to change zoom, pan via [Animatable] * objects' [Animatable.animateTo], [Animatable.snapTo]. @@ -37,8 +39,8 @@ open class TransformState( val drawAreaSize: IntSize, initialZoom: Float = 1f, initialRotation: Float = 0f, - minZoom: Float = 0.5f, // точно хватит - maxZoom: Float = 10f, + minZoom: Float = MIN_OVERLAY_RATIO, + maxZoom: Float = MAX_ZOOM, internal var zoomable: Boolean = true, internal var pannable: Boolean = true, internal var rotatable: Boolean = true, @@ -55,7 +57,7 @@ open class TransformState( ) ) - internal val zoomMin = minZoom.coerceAtLeast(0.5f) // точно хватит + internal val zoomMin = minZoom.coerceAtLeast(MIN_OVERLAY_RATIO) internal var zoomMax = maxZoom.coerceAtLeast(1f) private val zoomInitial = initialZoom.coerceIn(zoomMin, zoomMax) private val rotationInitial = initialRotation % 360