Skip to content

Commit 3f582e1

Browse files
committed
Fix destination of animation for the first element
1 parent 5cfe624 commit 3f582e1

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

app/src/main/java/org/mydomain/myscan/view/CameraScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fun CameraScreen(
131131
onPageClick = { index -> viewModel.navigateTo(Screen.FinalizeDocument(index)) },
132132
listState = listState,
133133
onLastItemPosition =
134-
{ coords -> thumbnailCoords.value = coords.localToWindow(Offset.Zero) }
134+
{ offset -> thumbnailCoords.value = offset }
135135
)
136136
},
137137
cameraUiState = CameraUiState(pageIds.size, liveAnalysisState, captureState),
@@ -223,7 +223,7 @@ private fun CapturedImage(cameraUiState: CameraUiState, thumbnailCoords: Mutable
223223
val centerX = bounds.left + bounds.width / 2
224224
val centerY = bounds.top + bounds.height / 2
225225
with(density) {
226-
targetOffsetX = thumbnailCoords.value.x - centerX + PAGE_LIST_ELEMENT_SIZE_DP.dp.toPx()
226+
targetOffsetX = thumbnailCoords.value.x - centerX
227227
targetOffsetY = thumbnailCoords.value.y - centerY + justABitToTheTop.toPx()
228228
}
229229
}

app/src/main/java/org/mydomain/myscan/view/PageList.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ import androidx.compose.material3.MaterialTheme
3434
import androidx.compose.runtime.Composable
3535
import androidx.compose.ui.Alignment
3636
import androidx.compose.ui.Modifier
37+
import androidx.compose.ui.geometry.Offset
3738
import androidx.compose.ui.graphics.Color
3839
import androidx.compose.ui.graphics.asImageBitmap
39-
import androidx.compose.ui.layout.LayoutCoordinates
4040
import androidx.compose.ui.layout.onGloballyPositioned
41+
import androidx.compose.ui.platform.LocalDensity
4142
import androidx.compose.ui.unit.dp
4243

4344
const val PAGE_LIST_ELEMENT_SIZE_DP = 120
@@ -49,7 +50,7 @@ fun CommonPageList(
4950
onPageClick: (Int) -> Unit,
5051
listState: LazyListState = rememberLazyListState(),
5152
currentPageIndex: Int? = null,
52-
onLastItemPosition: ((LayoutCoordinates) -> Unit)? = null,
53+
onLastItemPosition: ((Offset) -> Unit)? = null,
5354
) {
5455
LazyRow (
5556
state = listState,
@@ -77,7 +78,14 @@ fun CommonPageList(
7778
Modifier.width(maxImageSize)
7879
val isLastItem = index == pageIds.lastIndex
7980
if (isLastItem && onLastItemPosition != null) {
80-
modifier = modifier.onGloballyPositioned(onLastItemPosition)
81+
val density = LocalDensity.current
82+
modifier = modifier.onGloballyPositioned()
83+
{ coordinates ->
84+
with(density) {
85+
onLastItemPosition(coordinates.localToWindow(
86+
Offset(x = PAGE_LIST_ELEMENT_SIZE_DP.dp.toPx(), y = 0f)))
87+
}
88+
}
8189
}
8290
Image(
8391
bitmap = bitmap,
@@ -91,6 +99,11 @@ fun CommonPageList(
9199
}
92100
}
93101
if (pageIds.isEmpty()) {
94-
Box(modifier = Modifier.height(120.dp)) {}
102+
var modifier = Modifier.height(120.dp)
103+
if (onLastItemPosition != null) {
104+
modifier = modifier.onGloballyPositioned()
105+
{ coordinates -> onLastItemPosition(coordinates.localToWindow(Offset.Zero)) }
106+
}
107+
Box(modifier = modifier) {}
95108
}
96109
}

0 commit comments

Comments
 (0)