@@ -19,7 +19,6 @@ import android.graphics.BitmapFactory
1919import android.util.Log
2020import androidx.camera.core.ImageProxy
2121import androidx.camera.view.PreviewView
22- import androidx.compose.animation.core.animateDp
2322import androidx.compose.animation.core.animateFloat
2423import androidx.compose.animation.core.tween
2524import androidx.compose.animation.core.updateTransition
@@ -36,7 +35,6 @@ import androidx.compose.foundation.layout.Row
3635import androidx.compose.foundation.layout.fillMaxSize
3736import androidx.compose.foundation.layout.fillMaxWidth
3837import androidx.compose.foundation.layout.height
39- import androidx.compose.foundation.layout.offset
4038import androidx.compose.foundation.layout.padding
4139import androidx.compose.foundation.layout.size
4240import androidx.compose.foundation.layout.width
@@ -54,15 +52,16 @@ import androidx.compose.runtime.DisposableEffect
5452import androidx.compose.runtime.LaunchedEffect
5553import androidx.compose.runtime.MutableState
5654import androidx.compose.runtime.getValue
55+ import androidx.compose.runtime.mutableFloatStateOf
5756import androidx.compose.runtime.mutableStateOf
5857import androidx.compose.runtime.remember
5958import androidx.compose.runtime.setValue
6059import androidx.compose.ui.Alignment
6160import androidx.compose.ui.Modifier
62- import androidx.compose.ui.draw.scale
6361import androidx.compose.ui.geometry.Offset
6462import androidx.compose.ui.graphics.Color
6563import androidx.compose.ui.graphics.asImageBitmap
64+ import androidx.compose.ui.graphics.graphicsLayer
6665import androidx.compose.ui.layout.boundsInWindow
6766import androidx.compose.ui.layout.onGloballyPositioned
6867import androidx.compose.ui.platform.LocalConfiguration
@@ -201,32 +200,31 @@ private fun CapturedImage(cameraUiState: CameraUiState, thumbnailCoords: Mutable
201200 }
202201 val transition = updateTransition(targetState = isAnimating, label = " captureAnimation" )
203202 val density = LocalDensity .current
204- var targetOffsetX by remember { mutableStateOf( 0 .dp ) }
205- var targetOffsetY by remember { mutableStateOf( 0 .dp ) }
203+ var targetOffsetX by remember { mutableFloatStateOf( 0f ) }
204+ var targetOffsetY by remember { mutableFloatStateOf( 0f ) }
206205
207- val offsetX by transition.animateDp (
206+ val offsetX by transition.animateFloat (
208207 transitionSpec = { tween(durationMillis = ANIMATION_DURATION ) },
209208 label = " offsetX"
210- ) { if (it) targetOffsetX else 0 .dp }
211- val offsetY by transition.animateDp (
209+ ) { if (it) targetOffsetX else 0f }
210+ val offsetY by transition.animateFloat (
212211 transitionSpec = { tween(durationMillis = ANIMATION_DURATION ) },
213212 label = " offsetY"
214- ) { if (it) targetOffsetY else 0 .dp }
213+ ) { if (it) targetOffsetY else 0f }
215214 val scale by transition.animateFloat(
216215 transitionSpec = { tween(durationMillis = ANIMATION_DURATION ) },
217216 label = " scale"
218217 ) { if (it) 0.3f else 1f }
219218
220-
221219 val justABitToTheTop = 100 .dp
222220 Box (modifier = Modifier
223221 .onGloballyPositioned { coordinates ->
224222 val bounds = coordinates.boundsInWindow()
225223 val centerX = bounds.left + bounds.width / 2
226224 val centerY = bounds.top + bounds.height / 2
227225 with (density) {
228- targetOffsetX = thumbnailCoords.value.x.toDp() - centerX.toDp() + PAGE_LIST_ELEMENT_SIZE_DP .dp
229- targetOffsetY = thumbnailCoords.value.y.toDp() - centerY.toDp() + justABitToTheTop
226+ targetOffsetX = thumbnailCoords.value.x - centerX + PAGE_LIST_ELEMENT_SIZE_DP .dp.toPx()
227+ targetOffsetY = thumbnailCoords.value.y - centerY + justABitToTheTop.toPx()
230228 }
231229 }
232230 ) {
@@ -236,8 +234,12 @@ private fun CapturedImage(cameraUiState: CameraUiState, thumbnailCoords: Mutable
236234 modifier = Modifier
237235 .fillMaxSize()
238236 .padding(24 .dp)
239- .offset(x = offsetX, y = offsetY - justABitToTheTop)
240- .scale(scale)
237+ .graphicsLayer {
238+ translationX = offsetX
239+ translationY = offsetY - justABitToTheTop.toPx()
240+ scaleX = scale
241+ scaleY = scale
242+ }
241243 )
242244 }
243245 }
0 commit comments