Skip to content

Commit dc78a07

Browse files
add click on frame and aspect ratio to scroll center
1 parent 7003520 commit dc78a07

File tree

3 files changed

+49
-14
lines changed

3 files changed

+49
-14
lines changed

app/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ dependencies {
6060
// Gestures
6161
implementation 'com.github.SmartToolFactory:Compose-Extended-Gestures:3.0.0'
6262
// Animated List
63-
implementation 'com.github.SmartToolFactory:Compose-AnimatedList:0.5.1'
63+
implementation 'com.github.SmartToolFactory:Compose-AnimatedList:0.6.1'
6464

6565
implementation "androidx.compose.ui:ui:$compose_version"
6666
// Tooling support (Previews, etc.)
@@ -73,25 +73,25 @@ dependencies {
7373
implementation "androidx.compose.material:material-icons-core:$compose_version"
7474
implementation "androidx.compose.material:material-icons-extended:$compose_version"
7575
// Integration with activities
76-
implementation 'androidx.activity:activity-compose:1.7.1'
76+
implementation 'androidx.activity:activity-compose:1.7.2'
7777
// Integration with ViewModels
7878
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1'
7979

8080
// Material Design 3 for Compose
81-
implementation "androidx.compose.material3:material3:1.1.0"
81+
implementation "androidx.compose.material3:material3:1.1.1"
8282

8383
def nav_compose_version = "2.5.3"
8484
implementation "androidx.navigation:navigation-compose:$nav_compose_version"
8585

86-
def accompanist_version = "0.25.0"
86+
def accompanist_version = "0.30.1"
8787

8888
// Accompanist
8989
implementation "com.google.accompanist:accompanist-systemuicontroller:$accompanist_version"
9090
implementation "com.google.accompanist:accompanist-pager:$accompanist_version"
9191
implementation "com.google.accompanist:accompanist-drawablepainter:$accompanist_version"
9292

9393
// Coil
94-
implementation("io.coil-kt:coil-compose:2.2.2")
94+
implementation("io.coil-kt:coil-compose:2.3.0")
9595

9696
// Photo Picker
9797
implementation("com.google.modernstorage:modernstorage-photopicker:1.0.0-alpha06")

app/src/main/java/com/smarttoolfactory/composecropper/preferences/AspectRatioSelection.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package com.smarttoolfactory.composecropper.preferences
22

3-
import androidx.compose.foundation.layout.padding
3+
import androidx.compose.foundation.clickable
4+
import androidx.compose.foundation.gestures.animateScrollBy
5+
import androidx.compose.foundation.interaction.MutableInteractionSource
46
import androidx.compose.foundation.layout.width
57
import androidx.compose.material3.MaterialTheme
68
import androidx.compose.runtime.*
79
import androidx.compose.ui.Modifier
810
import androidx.compose.ui.graphics.graphicsLayer
911
import androidx.compose.ui.unit.Dp
10-
import androidx.compose.ui.unit.dp
1112
import com.smarttoolfactory.animatedlist.AnimatedInfiniteLazyRow
1213
import com.smarttoolfactory.animatedlist.model.AnimationProgress
1314
import com.smarttoolfactory.cropper.model.CropAspectRatio
1415
import com.smarttoolfactory.cropper.model.aspectRatios
1516
import com.smarttoolfactory.cropper.widget.AspectRatioSelectionCard
17+
import kotlinx.coroutines.launch
1618

1719
@Composable
1820
internal fun AnimatedAspectRatioSelection(
@@ -22,13 +24,18 @@ internal fun AnimatedAspectRatioSelection(
2224
) {
2325

2426
var currentIndex by remember { mutableStateOf(initialSelectedIndex) }
27+
val coroutineScope = rememberCoroutineScope()
2528

2629
AnimatedInfiniteLazyRow(
27-
modifier = modifier.padding(horizontal = 10.dp),
30+
modifier = modifier,
2831
items = aspectRatios,
2932
inactiveItemPercent = 80,
3033
initialFirstVisibleIndex = initialSelectedIndex - 2
31-
) { animationProgress: AnimationProgress, index: Int, item: CropAspectRatio, width: Dp ->
34+
) { animationProgress: AnimationProgress,
35+
index: Int,
36+
item: CropAspectRatio,
37+
width: Dp,
38+
lazyListState ->
3239

3340
val scale = animationProgress.scale
3441
val color = animationProgress.color
@@ -39,6 +46,16 @@ internal fun AnimatedAspectRatioSelection(
3946
scaleX = scale
4047
scaleY = scale
4148
}
49+
.clickable(
50+
interactionSource = remember {
51+
MutableInteractionSource()
52+
},
53+
indication = null
54+
) {
55+
coroutineScope.launch {
56+
lazyListState.animateScrollBy(animationProgress.distanceToSelector)
57+
}
58+
}
4259
.width(width),
4360
contentColor = MaterialTheme.colorScheme.surface,
4461
color = color,

app/src/main/java/com/smarttoolfactory/composecropper/preferences/CropFrameSelection.kt

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package com.smarttoolfactory.composecropper.preferences
22

33
import CropFrameListDialog
4+
import androidx.compose.foundation.clickable
5+
import androidx.compose.foundation.gestures.animateScrollBy
6+
import androidx.compose.foundation.interaction.MutableInteractionSource
47
import androidx.compose.foundation.layout.fillMaxWidth
5-
import androidx.compose.foundation.layout.padding
68
import androidx.compose.foundation.layout.width
79
import androidx.compose.runtime.*
810
import androidx.compose.ui.Modifier
911
import androidx.compose.ui.unit.Dp
10-
import androidx.compose.ui.unit.dp
1112
import com.smarttoolfactory.animatedlist.AnimatedInfiniteLazyRow
1213
import com.smarttoolfactory.animatedlist.model.AnimationProgress
1314
import com.smarttoolfactory.cropper.model.AspectRatio
@@ -16,6 +17,7 @@ import com.smarttoolfactory.cropper.model.OutlineType
1617
import com.smarttoolfactory.cropper.settings.CropFrameFactory
1718
import com.smarttoolfactory.cropper.settings.CropOutlineProperty
1819
import com.smarttoolfactory.cropper.widget.CropFrameDisplayCard
20+
import kotlinx.coroutines.launch
1921

2022
/**
2123
* Crop frame selection
@@ -96,13 +98,18 @@ private fun CropFrameSelectionList(
9698
) {
9799

98100
var currentIndex by remember { mutableStateOf(initialSelectedIndex) }
101+
val coroutineScope = rememberCoroutineScope()
99102

100103
AnimatedInfiniteLazyRow(
101-
modifier = modifier.padding(horizontal = 10.dp),
104+
modifier = modifier,
102105
items = cropFrames,
103106
inactiveItemPercent = 80,
104107
initialFirstVisibleIndex = initialSelectedIndex - 2,
105-
) { animationProgress: AnimationProgress, index: Int, item: CropFrame, width: Dp ->
108+
) { animationProgress: AnimationProgress,
109+
index: Int,
110+
item: CropFrame,
111+
width: Dp,
112+
lazyListState ->
106113

107114
val scale = animationProgress.scale
108115
val color = animationProgress.color
@@ -113,7 +120,18 @@ private fun CropFrameSelectionList(
113120
val editable = item.editable
114121

115122
CropFrameDisplayCard(
116-
modifier = Modifier.width(width),
123+
modifier = Modifier
124+
.width(width)
125+
.clickable(
126+
interactionSource = remember {
127+
MutableInteractionSource()
128+
},
129+
indication = null
130+
) {
131+
coroutineScope.launch {
132+
lazyListState.animateScrollBy(animationProgress.distanceToSelector)
133+
}
134+
},
117135
editable = editable,
118136
scale = scale,
119137
outlineColor = color,

0 commit comments

Comments
 (0)