Skip to content

Commit 18ef0b5

Browse files
add initial scale animation and change color of ImageCropper
1 parent 2759f30 commit 18ef0b5

3 files changed

Lines changed: 57 additions & 37 deletions

File tree

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

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
@file:OptIn(ExperimentalAnimationApi::class)
2+
13
package com.smarttoolfactory.cropper
24

5+
import androidx.compose.animation.AnimatedVisibility
6+
import androidx.compose.animation.ExperimentalAnimationApi
7+
import androidx.compose.animation.core.tween
8+
import androidx.compose.animation.scaleIn
9+
import androidx.compose.foundation.background
310
import androidx.compose.foundation.layout.Box
11+
import androidx.compose.foundation.layout.fillMaxSize
412
import androidx.compose.foundation.layout.size
5-
import androidx.compose.material3.Text
6-
import androidx.compose.runtime.Composable
7-
import androidx.compose.runtime.LaunchedEffect
8-
import androidx.compose.runtime.remember
13+
import androidx.compose.runtime.*
914
import androidx.compose.ui.Alignment
1015
import androidx.compose.ui.Modifier
1116
import androidx.compose.ui.draw.clipToBounds
@@ -18,7 +23,6 @@ import androidx.compose.ui.platform.LocalDensity
1823
import androidx.compose.ui.platform.LocalLayoutDirection
1924
import androidx.compose.ui.unit.Dp
2025
import androidx.compose.ui.unit.IntSize
21-
import androidx.compose.ui.unit.sp
2226
import com.smarttoolfactory.cropper.crop.CropAgent
2327
import com.smarttoolfactory.cropper.draw.DrawingOverlay
2428
import com.smarttoolfactory.cropper.draw.ImageDrawCanvas
@@ -135,11 +139,6 @@ fun ImageCropper(
135139
*/
136140
val rectCrop = cropState.cropRect
137141

138-
val drawAreaRect = cropState.drawAreaRect
139-
140-
val pan = cropState.pan
141-
val zoom = cropState.zoom
142-
143142
val density = LocalDensity.current
144143
val layoutDirection = LocalLayoutDirection.current
145144

@@ -175,33 +174,54 @@ fun ImageCropper(
175174
cropState = cropState
176175
)
177176

178-
Box {
179-
ImageCropperImpl(
180-
modifier = imageModifier,
181-
imageBitmap = scaledImageBitmap,
182-
containerWidth = containerWidth,
183-
containerHeight = containerHeight,
184-
imageWidthPx = imageWidthPx,
185-
imageHeightPx = imageHeightPx,
186-
cropType = cropType,
187-
cropOutline = cropOutline,
188-
handleSize = cropProperties.handleSize,
189-
cropStyle = cropStyle,
190-
rectOverlay = cropState.overlayRect
191-
)
177+
Box(modifier = Modifier
178+
.fillMaxSize()
179+
.background(Color.Black)
180+
) {
181+
182+
/// Create a MutableTransitionState<Boolean> for the AnimatedVisibility.
183+
var visible by remember { mutableStateOf(false) }
192184

185+
LaunchedEffect(Unit) {
186+
delay(100)
187+
visible = true
188+
}
189+
190+
AnimatedVisibility(
191+
visible = visible,
192+
enter = scaleIn(tween(500))
193+
) {
194+
195+
ImageCropperImpl(
196+
modifier = imageModifier,
197+
imageBitmap = scaledImageBitmap,
198+
containerWidth = containerWidth,
199+
containerHeight = containerHeight,
200+
imageWidthPx = imageWidthPx,
201+
imageHeightPx = imageHeightPx,
202+
cropType = cropType,
203+
cropOutline = cropOutline,
204+
handleSize = cropProperties.handleSize,
205+
cropStyle = cropStyle,
206+
rectOverlay = cropState.overlayRect
207+
)
208+
}
209+
193210
// TODO Remove this text when cropper is complete. This is for debugging
194-
Text(
195-
modifier = Modifier.align(Alignment.TopStart),
196-
color = Color.White,
197-
fontSize = 10.sp,
198-
text = "imageWidthInPx: $imageWidthPx, imageHeightInPx: $imageHeightPx\n" +
199-
"bitmapWidth: $bitmapWidth, bitmapHeight: $bitmapHeight\n" +
200-
"zoom: $zoom, pan: $pan\n" +
201-
"drawAreaRect: $drawAreaRect, size: ${drawAreaRect.size}\n" +
202-
"overlayRect: ${cropState.overlayRect}, size: ${cropState.overlayRect.size}\n" +
203-
"cropRect: $rectCrop, size: ${rectCrop.size}"
204-
)
211+
// val drawAreaRect = cropState.drawAreaRect
212+
// val pan = cropState.pan
213+
// val zoom = cropState.zoom
214+
// Text(
215+
// modifier = Modifier.align(Alignment.TopStart),
216+
// color = Color.White,
217+
// fontSize = 10.sp,
218+
// text = "imageWidthInPx: $imageWidthPx, imageHeightInPx: $imageHeightPx\n" +
219+
// "bitmapWidth: $bitmapWidth, bitmapHeight: $bitmapHeight\n" +
220+
// "zoom: $zoom, pan: $pan\n" +
221+
// "drawAreaRect: $drawAreaRect, size: ${drawAreaRect.size}\n" +
222+
// "overlayRect: ${cropState.overlayRect}, size: ${cropState.overlayRect.size}\n" +
223+
// "cropRect: $rectCrop, size: ${rectCrop.size}"
224+
// )
205225
}
206226
}
207227
}

cropper/src/main/java/com/smarttoolfactory/cropper/settings/CropDefaults.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ object CropDefaults {
4949
drawOverlay: Boolean = true,
5050
drawGrid: Boolean = true,
5151
strokeWidth: Dp = 1.dp,
52-
overlayColor: Color = Color.DarkGray,
52+
overlayColor: Color = Color.Gray,
5353
handleColor: Color = Color.White
5454
): CropStyle {
5555
return CropStyle(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ open class TransformState(
6262

6363
internal val animatablePanX = Animatable(0f)
6464
internal val animatablePanY = Animatable(0f)
65-
internal val animatableZoom = Animatable(0f)
65+
internal val animatableZoom = Animatable(zoomInitial)
6666
internal val animatableRotation = Animatable(rotationInitial)
6767

6868
private val velocityTracker = VelocityTracker()

0 commit comments

Comments
 (0)