Skip to content

Instantly share code, notes, and snippets.

@bmc08gt
Created December 5, 2023 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmc08gt/fec88e5caab41011a3a065101c7e35e3 to your computer and use it in GitHub Desktop.
Save bmc08gt/fec88e5caab41011a3a065101c7e35e3 to your computer and use it in GitHub Desktop.
M.measured {}
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.IntSize
fun IntSize.toDp(density: Density): DpSize = with(density) { DpSize(width = width.toDp(), height = height.toDp()) }
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.layout.onPlaced
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.DpSize
import dev.bmcreations.leftovers.utils.toDp
fun Modifier.measured(block: (DpSize) -> Unit): Modifier = composed {
val density = LocalDensity.current
onPlaced { block(it.size.toDp(density)) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment