Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Do not clip bounds of AndroidView in Compose

AndroidView will clip its content to the layout bounds, as being clipped is a common assumption made by Views – keeping clipping disabled might lead to unexpected drawing behavior. Note this deviates from Compose’s practice of keeping clipping opt-in, disabled by default.

(src)

This seems to suggest that there is a way to turn clipping off, but I can’t manage to do so.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’ve tried:

  • Modifier.graphicsLayer(clip = false) on the AndroidView
  • clipToPadding = false on the View
  • clipToOutline = false on the View
  • clipChildren = false on the View

Is it possible to turn off clipping?

>Solution :

It’s a known feature request, here’s a workaround until it’s implemented:

@Composable
fun <T : View> AndroidView(
    clipToBounds: Boolean,
    factory: (Context) -> T,
    modifier: Modifier = Modifier,
    update: (T) -> Unit = NoOpUpdate,
) {
    androidx.compose.ui.viewinterop.AndroidView(
        factory = factory,
        modifier = modifier,
        update = if (clipToBounds) {
            update
        } else {
            {
                (it.parent as? ViewGroup)?.clipChildren = false
                update(it)
            }
        }
    )
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading