Fix destination of animation for the first element
This commit is contained in:
@@ -131,7 +131,7 @@ fun CameraScreen(
|
|||||||
onPageClick = { index -> viewModel.navigateTo(Screen.FinalizeDocument(index)) },
|
onPageClick = { index -> viewModel.navigateTo(Screen.FinalizeDocument(index)) },
|
||||||
listState = listState,
|
listState = listState,
|
||||||
onLastItemPosition =
|
onLastItemPosition =
|
||||||
{ coords -> thumbnailCoords.value = coords.localToWindow(Offset.Zero) }
|
{ offset -> thumbnailCoords.value = offset }
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
cameraUiState = CameraUiState(pageIds.size, liveAnalysisState, captureState),
|
cameraUiState = CameraUiState(pageIds.size, liveAnalysisState, captureState),
|
||||||
@@ -223,7 +223,7 @@ private fun CapturedImage(cameraUiState: CameraUiState, thumbnailCoords: Mutable
|
|||||||
val centerX = bounds.left + bounds.width / 2
|
val centerX = bounds.left + bounds.width / 2
|
||||||
val centerY = bounds.top + bounds.height / 2
|
val centerY = bounds.top + bounds.height / 2
|
||||||
with(density) {
|
with(density) {
|
||||||
targetOffsetX = thumbnailCoords.value.x - centerX + PAGE_LIST_ELEMENT_SIZE_DP.dp.toPx()
|
targetOffsetX = thumbnailCoords.value.x - centerX
|
||||||
targetOffsetY = thumbnailCoords.value.y - centerY + justABitToTheTop.toPx()
|
targetOffsetY = thumbnailCoords.value.y - centerY + justABitToTheTop.toPx()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,10 +34,11 @@ import androidx.compose.material3.MaterialTheme
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.geometry.Offset
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.asImageBitmap
|
import androidx.compose.ui.graphics.asImageBitmap
|
||||||
import androidx.compose.ui.layout.LayoutCoordinates
|
|
||||||
import androidx.compose.ui.layout.onGloballyPositioned
|
import androidx.compose.ui.layout.onGloballyPositioned
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
const val PAGE_LIST_ELEMENT_SIZE_DP = 120
|
const val PAGE_LIST_ELEMENT_SIZE_DP = 120
|
||||||
@@ -49,7 +50,7 @@ fun CommonPageList(
|
|||||||
onPageClick: (Int) -> Unit,
|
onPageClick: (Int) -> Unit,
|
||||||
listState: LazyListState = rememberLazyListState(),
|
listState: LazyListState = rememberLazyListState(),
|
||||||
currentPageIndex: Int? = null,
|
currentPageIndex: Int? = null,
|
||||||
onLastItemPosition: ((LayoutCoordinates) -> Unit)? = null,
|
onLastItemPosition: ((Offset) -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
LazyRow (
|
LazyRow (
|
||||||
state = listState,
|
state = listState,
|
||||||
@@ -77,7 +78,14 @@ fun CommonPageList(
|
|||||||
Modifier.width(maxImageSize)
|
Modifier.width(maxImageSize)
|
||||||
val isLastItem = index == pageIds.lastIndex
|
val isLastItem = index == pageIds.lastIndex
|
||||||
if (isLastItem && onLastItemPosition != null) {
|
if (isLastItem && onLastItemPosition != null) {
|
||||||
modifier = modifier.onGloballyPositioned(onLastItemPosition)
|
val density = LocalDensity.current
|
||||||
|
modifier = modifier.onGloballyPositioned()
|
||||||
|
{ coordinates ->
|
||||||
|
with(density) {
|
||||||
|
onLastItemPosition(coordinates.localToWindow(
|
||||||
|
Offset(x = PAGE_LIST_ELEMENT_SIZE_DP.dp.toPx(), y = 0f)))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Image(
|
Image(
|
||||||
bitmap = bitmap,
|
bitmap = bitmap,
|
||||||
@@ -91,6 +99,11 @@ fun CommonPageList(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pageIds.isEmpty()) {
|
if (pageIds.isEmpty()) {
|
||||||
Box(modifier = Modifier.height(120.dp)) {}
|
var modifier = Modifier.height(120.dp)
|
||||||
|
if (onLastItemPosition != null) {
|
||||||
|
modifier = modifier.onGloballyPositioned()
|
||||||
|
{ coordinates -> onLastItemPosition(coordinates.localToWindow(Offset.Zero)) }
|
||||||
|
}
|
||||||
|
Box(modifier = modifier) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user