Created
May 6, 2024 09:56
-
-
Save artsmvch/a9b88f4399981f5b7abc3af4506b1bdb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.compose.foundation.background | |
import androidx.compose.foundation.layout.Arrangement | |
import androidx.compose.foundation.layout.Box | |
import androidx.compose.foundation.layout.fillMaxHeight | |
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.wrapContentSize | |
import androidx.compose.foundation.lazy.LazyColumn | |
import androidx.compose.foundation.lazy.items | |
import androidx.compose.foundation.lazy.rememberLazyListState | |
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.geometry.Size | |
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 itemHeight = 60.dp | |
val itemHeightPx = with(LocalDensity.current) { itemHeight.toPx() } | |
val itemOffsetPx = with(LocalDensity.current) { 16.dp.toPx() } | |
LazyColumn( | |
state = listState, | |
verticalArrangement = Arrangement.spacedBy(8.dp), | |
modifier = Modifier | |
.background(Color.Black) | |
.fillMaxSize() | |
.drawBehind { | |
listState.layoutInfo.visibleItemsInfo.forEach { itemInfo -> | |
drawRect( | |
topLeft = Offset( | |
x = itemOffsetPx, | |
y = itemInfo.offset.toFloat() | |
), | |
size = Size(itemHeightPx, itemHeightPx), | |
color = Color.Yellow, | |
) | |
} | |
} | |
) { | |
items(items) { | |
Box( | |
Modifier | |
.fillMaxWidth() | |
.height(itemHeight) | |
.padding(start = 80.dp, top = 0.dp, end = 16.dp, bottom = 0.dp) | |
) { | |
Surface( | |
modifier = Modifier | |
.fillMaxWidth() | |
.fillMaxHeight(), | |
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