Skip to content

Instantly share code, notes, and snippets.

@artsmvch
Created April 30, 2024 20:34
Show Gist options
  • Save artsmvch/4fe37b57f81cf35e2f0db89e1534a139 to your computer and use it in GitHub Desktop.
Save artsmvch/4fe37b57f81cf35e2f0db89e1534a139 to your computer and use it in GitHub Desktop.
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@Composable
fun DrawModifierBug() {
val listState = rememberLazyListState()
val items = List(100) { it }
val iconSize = 32.dp
val iconSizePx = with(LocalDensity.current) { iconSize.toPx() }
val iconOffsetX = with(LocalDensity.current) { 12.dp.toPx() }
LazyColumn(
state = listState,
modifier = Modifier
.background(Color.Black)
.fillMaxSize()
.drawBehind {
listState.layoutInfo.visibleItemsInfo.forEach { itemInfo ->
drawCircle(
center = Offset(
x = iconOffsetX + iconSizePx / 2f,
y = itemInfo.offset + itemInfo.size / 2f
),
color = Color.LightGray,
radius = iconSizePx / 2f
)
}
}
) {
items(items) {
Box(
Modifier
.fillMaxWidth()
.wrapContentHeight()
.padding(start = 50.dp, top = 8.dp, end = 16.dp, bottom = 8.dp)
) {
Surface(
modifier = Modifier
.fillMaxWidth()
.height(80.dp),
shape = RoundedCornerShape(8.dp),
color = Color.DarkGray
) {
Text(
modifier = Modifier
.wrapContentSize()
.padding(16.dp),
text = "Text $it",
color = Color.White,
fontSize = 18.sp
)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment