11package com.smarttoolfactory.composebeforeafter.demo
22
3+ import androidx.annotation.OptIn
34import androidx.compose.animation.core.FastOutSlowInEasing
45import androidx.compose.animation.core.InfiniteTransition
56import androidx.compose.animation.core.RepeatMode
@@ -37,6 +38,7 @@ import androidx.compose.ui.res.imageResource
3738import androidx.compose.ui.text.font.FontWeight
3839import androidx.compose.ui.unit.dp
3940import androidx.compose.ui.unit.sp
41+ import androidx.media3.common.util.UnstableApi
4042import com.smarttoolfactory.beforeafter.AfterLabel
4143import com.smarttoolfactory.beforeafter.BeforeAfterLayout
4244import com.smarttoolfactory.beforeafter.BeforeLabel
@@ -45,46 +47,47 @@ import com.smarttoolfactory.beforeafter.OverlayStyle
4547import com.smarttoolfactory.composebeforeafter.R
4648import kotlin.math.roundToInt
4749
50+ @OptIn(UnstableApi ::class )
4851@Composable
4952fun BeforeAfterLayoutDemo () {
5053
5154 Column (
5255 modifier = Modifier
5356 .fillMaxSize()
5457 .padding(10 .dp)
55- .verticalScroll(rememberScrollState())
58+ .verticalScroll(rememberScrollState()),
5659 ) {
5760
5861 val imageBefore = ImageBitmap .imageResource(
59- LocalContext .current.resources, R .drawable.image_before_after_shoes_a
62+ LocalContext .current.resources, R .drawable.image_before_after_shoes_a,
6063 )
6164
6265 val imageAfter = ImageBitmap .imageResource(
63- LocalContext .current.resources, R .drawable.image_before_after_shoes_b
66+ LocalContext .current.resources, R .drawable.image_before_after_shoes_b,
6467 )
6568
6669
6770 val imageBefore2 = ImageBitmap .imageResource(
68- LocalContext .current.resources, R .drawable.landscape5_before
71+ LocalContext .current.resources, R .drawable.landscape5_before,
6972 )
7073
7174 val imageAfter2 = ImageBitmap .imageResource(
72- LocalContext .current.resources, R .drawable.landscape5
75+ LocalContext .current.resources, R .drawable.landscape5,
7376 )
7477 Text (
7578 text = " BeforeAfterLayout" ,
7679 fontSize = 20 .sp,
7780 fontWeight = FontWeight .Bold ,
7881 color = MaterialTheme .colorScheme.primary,
79- modifier = Modifier .padding(8 .dp)
82+ modifier = Modifier .padding(8 .dp),
8083 )
8184
8285 Text (
8386 text = " Customization" ,
8487 fontSize = 16 .sp,
8588 fontWeight = FontWeight .Bold ,
8689 color = MaterialTheme .colorScheme.primary,
87- modifier = Modifier .padding(8 .dp)
90+ modifier = Modifier .padding(8 .dp),
8891 )
8992
9093 BeforeAfterLayout (
@@ -103,8 +106,10 @@ fun BeforeAfterLayoutDemo() {
103106 dividerWidth = 2 .dp,
104107 thumbShape = CutCornerShape (8 .dp),
105108 thumbBackgroundColor = Color .Red ,
106- thumbTintColor = Color .White
107- )
109+ thumbTintColor = Color .White ,
110+ ),
111+ onProgressStart = { println (" Slider move: Start" ) },
112+ onProgressEnd = { println (" Slider move: End" ) },
108113 )
109114
110115
@@ -114,7 +119,7 @@ fun BeforeAfterLayoutDemo() {
114119 fontSize = 16 .sp,
115120 fontWeight = FontWeight .Bold ,
116121 color = MaterialTheme .colorScheme.primary,
117- modifier = Modifier .padding(8 .dp)
122+ modifier = Modifier .padding(8 .dp),
118123 )
119124
120125 BeforeAfterLayout (
@@ -128,7 +133,9 @@ fun BeforeAfterLayoutDemo() {
128133 afterContent = {
129134 DemoImage (imageBitmap = imageAfter2)
130135 },
131- contentOrder = ContentOrder .AfterBefore
136+ contentOrder = ContentOrder .AfterBefore ,
137+ onProgressStart = { println (" Slider move: Start" ) },
138+ onProgressEnd = { println (" Slider move: End" ) },
132139 )
133140
134141 Spacer (modifier = Modifier .height(50 .dp))
@@ -142,10 +149,10 @@ fun BeforeAfterLayoutDemo() {
142149 animationSpec = infiniteRepeatable(
143150 animation = tween(
144151 durationMillis = 4000 ,
145- easing = FastOutSlowInEasing
152+ easing = FastOutSlowInEasing ,
146153 ),
147- repeatMode = RepeatMode .Reverse
148- )
154+ repeatMode = RepeatMode .Reverse ,
155+ ),
149156 )
150157
151158
@@ -154,7 +161,7 @@ fun BeforeAfterLayoutDemo() {
154161 fontSize = 16 .sp,
155162 fontWeight = FontWeight .Bold ,
156163 color = MaterialTheme .colorScheme.primary,
157- modifier = Modifier .padding(8 .dp)
164+ modifier = Modifier .padding(8 .dp),
158165 )
159166 BeforeAfterLayout (
160167 modifier = Modifier
@@ -171,7 +178,9 @@ fun BeforeAfterLayoutDemo() {
171178 enableZoom = false ,
172179 beforeLabel = null ,
173180 afterLabel = null ,
174- overlay = null
181+ overlay = null ,
182+ onProgressStart = { println (" Slider move: Start" ) },
183+ onProgressEnd = { println (" Slider move: End" ) },
175184 )
176185
177186 Spacer (modifier = Modifier .height(50 .dp))
@@ -181,7 +190,7 @@ fun BeforeAfterLayoutDemo() {
181190 fontSize = 16 .sp,
182191 fontWeight = FontWeight .Bold ,
183192 color = MaterialTheme .colorScheme.primary,
184- modifier = Modifier .padding(8 .dp)
193+ modifier = Modifier .padding(8 .dp),
185194 )
186195
187196 BeforeAfterLayout (
@@ -199,7 +208,7 @@ fun BeforeAfterLayoutDemo() {
199208 AfterLabel (text = " Material Design3" )
200209 },
201210 enableZoom = false ,
202- overlayStyle = OverlayStyle (thumbPositionPercent = 60f )
211+ overlayStyle = OverlayStyle (thumbPositionPercent = 60f ),
203212 )
204213
205214 // FIXME There is a bug with Exoplayer2 and setting Modifier.graphicsLayer
@@ -212,7 +221,7 @@ fun BeforeAfterLayoutDemo() {
212221 fontSize = 16 .sp,
213222 fontWeight = FontWeight .Bold ,
214223 color = MaterialTheme .colorScheme.primary,
215- modifier = Modifier .padding(8 .dp)
224+ modifier = Modifier .padding(8 .dp),
216225 )
217226 BeforeAfterLayout (
218227 modifier = Modifier
@@ -222,17 +231,19 @@ fun BeforeAfterLayoutDemo() {
222231 MyPlayer (
223232 modifier = Modifier
224233 .border(3 .dp, Color .Red ),
225- uri = " asset:///floodplain_dirty.mp4"
234+ uri = " asset:///floodplain_dirty.mp4" ,
226235 )
227236 },
228237 afterContent = {
229238 MyPlayer (
230239 modifier = Modifier
231240 .border(3 .dp, Color .Yellow ),
232- uri = " asset:///floodplain_clean.mp4"
241+ uri = " asset:///floodplain_clean.mp4" ,
233242 )
234243 },
235- enableZoom = false
244+ enableZoom = false ,
245+ onProgressStart = { println (" Slider move: Start" ) },
246+ onProgressEnd = { println (" Slider move: End" ) },
236247 )
237248 }
238249}
@@ -245,7 +256,7 @@ private fun DemoImage(imageBitmap: ImageBitmap) {
245256 .aspectRatio(4 / 3f ),
246257 bitmap = imageBitmap,
247258 contentDescription = null ,
248- contentScale = ContentScale .FillBounds
259+ contentScale = ContentScale .FillBounds ,
249260 )
250261}
251262
@@ -258,12 +269,12 @@ private fun BeforeComposable(progress: Float) {
258269 .clip(RoundedCornerShape (50 ))
259270 .fillMaxWidth()
260271 .background(MaterialTheme .colorScheme.primary),
261- horizontalAlignment = Alignment .CenterHorizontally
272+ horizontalAlignment = Alignment .CenterHorizontally ,
262273 ) {
263274 Text (
264275 text = " ${(progress).roundToInt()} %" ,
265276 fontSize = 40 .sp,
266- color = MaterialTheme .colorScheme.onPrimary
277+ color = MaterialTheme .colorScheme.onPrimary,
267278 )
268279 }
269280
@@ -274,14 +285,14 @@ private fun AfterComposable(progress: Float) {
274285 Column (
275286 modifier = Modifier
276287 .border(3 .dp, MaterialTheme .colorScheme.primary, RoundedCornerShape (50 ))
277- // .clip(RoundedCornerShape(50))
288+ .clip(RoundedCornerShape (50 ))
278289 .fillMaxWidth(),
279- horizontalAlignment = Alignment .CenterHorizontally
290+ horizontalAlignment = Alignment .CenterHorizontally ,
280291 ) {
281292 Text (
282293 text = " ${(progress).roundToInt()} %" ,
283294 fontSize = 40 .sp,
284- color = MaterialTheme .colorScheme.primary
295+ color = MaterialTheme .colorScheme.primary,
285296 )
286297 }
287298}
0 commit comments