facebook / screenshot-tests-for-android

Generate fast deterministic screenshots during Android instrumentation tests
http://facebook.github.io/screenshot-tests-for-android
Apache License 2.0
1.74k stars 229 forks source link

View clipping to outline doesn't work on screenshots #276

Open N-Olifer opened 3 years ago

N-Olifer commented 3 years ago

When make a screenshot test for some layout, and some custom view inside contains outline clipping like that:

        view.outlineProvider = object : ViewOutlineProvider() {
            override fun getOutline(v: View, outline: Outline) {
                outline.setRoundRect(0, 0, v.width, v.height, 50)
            }
        }
        view.clipToOutline = true

It works correctly in real app, but doesn't work on screenshot (view appears without clipping). Maybe, it's related to hardware acceleration somehow.

Is there some workaround to make clipping work on screenshots?

xiphirx commented 3 years ago

Clipping and elevation happen in a separate rendering pipeline that we dont participate in when we take a screenshot afaik, so no we can't capture that. We would need to investigate other methods of taking screenshots of views that do capture that rendering output, but I'm not aware of any outside of adb screencap, but then that would take a screenshot of the entire screen.

donny-li-ck commented 1 year ago

Hello, I'm experiencing the same issue when taking screenshots of my Jetpack Compose views using the Modifier.clip modifier. Is there a workaround of some sort?