Skip to content

Commit 191729e

Browse files
add default cropper colors for transparent background
1 parent 1dd4feb commit 191729e

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

app/src/main/java/com/smarttoolfactory/composecropper/MainActivity.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.smarttoolfactory.composecropper
33
import android.os.Bundle
44
import androidx.activity.ComponentActivity
55
import androidx.activity.compose.setContent
6+
import androidx.compose.foundation.layout.Column
67
import androidx.compose.foundation.layout.fillMaxSize
78
import androidx.compose.material3.MaterialTheme
89
import androidx.compose.material3.Surface
@@ -20,7 +21,9 @@ class MainActivity : ComponentActivity() {
2021
modifier = Modifier.fillMaxSize(),
2122
color = MaterialTheme.colorScheme.background
2223
) {
23-
ImageCropDemo()
24+
Column {
25+
ImageCropDemo()
26+
}
2427
}
2528
}
2629
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import com.smarttoolfactory.cropper.settings.CropStyle
3737
import com.smarttoolfactory.cropper.settings.CropType
3838
import com.smarttoolfactory.cropper.state.DynamicCropState
3939
import com.smarttoolfactory.cropper.state.rememberCropState
40+
import com.smarttoolfactory.cropper.ui.theme.BackgroundIdle
41+
import com.smarttoolfactory.cropper.ui.theme.BackgroundPressed
4042
import kotlinx.coroutines.Dispatchers
4143
import kotlinx.coroutines.delay
4244
import kotlinx.coroutines.flow.*
@@ -113,15 +115,15 @@ fun ImageCropper(
113115
keys = resetKeys
114116
)
115117

116-
val isTouched = remember(cropState) {
118+
val isTouched by remember(cropState) {
117119
derivedStateOf {
118120
cropState is DynamicCropState && handlesTouched(cropState.touchRegion)
119121
}
120122
}
121123

122124
val transparentColor by animateColorAsState(
123125
animationSpec = tween(300, easing = LinearEasing),
124-
targetValue = if (isTouched.value) Color(0x66000000) else Color(0x99000000)
126+
targetValue = if (isTouched) BackgroundPressed else BackgroundIdle
125127
)
126128

127129
// Crops image when user invokes crop operation
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.smarttoolfactory.cropper.ui.theme
2+
3+
import androidx.compose.ui.graphics.Color
4+
5+
val BackgroundPressed = Color(0x66000000)
6+
val BackgroundIdle = Color(0x99000000)

0 commit comments

Comments
 (0)