Skip to content

Commit ac45140

Browse files
Merge pull request #45 from dinaraparanid/master
Crop with overlay ratio does not scale to full borders
2 parents 9658d61 + 6452ce1 commit ac45140

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

cropper/src/main/java/com/smarttoolfactory/cropper/CropModifier.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ fun Modifier.crop(
7777
}
7878
},
7979
onGesture = { centroid, pan, zoom, rotate, mainPointer, pointerList ->
80-
8180
coroutineScope.launch {
8281
cropState.onGesture(
8382
centroid = centroid,

cropper/src/main/java/com/smarttoolfactory/cropper/state/CropStateImpl.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import com.smarttoolfactory.cropper.model.AspectRatio
1717
import com.smarttoolfactory.cropper.model.CropData
1818
import com.smarttoolfactory.cropper.settings.CropProperties
1919

20+
internal const val MIN_OVERLAY_RATIO = 0.5F
21+
2022
val CropState.cropData: CropData
2123
get() = CropData(
2224
zoom = animatableZoom.targetValue,
@@ -293,8 +295,7 @@ abstract class CropState internal constructor(
293295
animate: Boolean,
294296
animationSpec: AnimationSpec<Float> = tween(400)
295297
) {
296-
297-
val zoom = zoom.coerceAtLeast(1f)
298+
val zoom = zoom.coerceAtLeast(MIN_OVERLAY_RATIO)
298299

299300
// Calculate new pan based on overlay
300301
val newDrawAreaRect = calculateValidImageDrawRect(overlayRect, drawAreaRect)

cropper/src/main/java/com/smarttoolfactory/cropper/state/TransformState.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import androidx.compose.ui.unit.IntSize
1616
import kotlinx.coroutines.coroutineScope
1717
import kotlinx.coroutines.launch
1818

19+
private const val MAX_ZOOM = 10F
20+
1921
/**
2022
* State of the pan, zoom and rotation. Allows to change zoom, pan via [Animatable]
2123
* objects' [Animatable.animateTo], [Animatable.snapTo].
@@ -37,8 +39,8 @@ open class TransformState(
3739
val drawAreaSize: IntSize,
3840
initialZoom: Float = 1f,
3941
initialRotation: Float = 0f,
40-
minZoom: Float = 1f,
41-
maxZoom: Float = 10f,
42+
minZoom: Float = MIN_OVERLAY_RATIO,
43+
maxZoom: Float = MAX_ZOOM,
4244
internal var zoomable: Boolean = true,
4345
internal var pannable: Boolean = true,
4446
internal var rotatable: Boolean = true,
@@ -55,7 +57,7 @@ open class TransformState(
5557
)
5658
)
5759

58-
internal val zoomMin = minZoom.coerceAtLeast(1f)
60+
internal val zoomMin = minZoom.coerceAtLeast(MIN_OVERLAY_RATIO)
5961
internal var zoomMax = maxZoom.coerceAtLeast(1f)
6062
private val zoomInitial = initialZoom.coerceIn(zoomMin, zoomMax)
6163
private val rotationInitial = initialRotation % 360

0 commit comments

Comments
 (0)