@@ -34,10 +34,11 @@ import androidx.compose.material3.MaterialTheme
3434import androidx.compose.runtime.Composable
3535import androidx.compose.ui.Alignment
3636import androidx.compose.ui.Modifier
37+ import androidx.compose.ui.geometry.Offset
3738import androidx.compose.ui.graphics.Color
3839import androidx.compose.ui.graphics.asImageBitmap
39- import androidx.compose.ui.layout.LayoutCoordinates
4040import androidx.compose.ui.layout.onGloballyPositioned
41+ import androidx.compose.ui.platform.LocalDensity
4142import androidx.compose.ui.unit.dp
4243
4344const 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