Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: recursively set LAYER_TYPE_SOFTWARE before Screenshot.snap
ViewHelpers only sets software layer on the root view. Fabric child views
retain hardware display lists which view.draw(canvas) cannot capture,
producing blank (white background only) screenshots. Walk the full tree
and set LAYER_TYPE_SOFTWARE on every node before snapping.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
  • Loading branch information
EmilioBejasa and claude committed Mar 30, 2026
commit c8ceb5fdd3c72bd792b2e9d86d743dde6558ffa9
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.util.Log
import android.view.Choreographer
import android.view.ContextThemeWrapper
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
Expand Down Expand Up @@ -132,10 +133,9 @@ abstract class BaseStoryScreenshotTest {

val screenshotName = story.id.replace("--", "_")
instrumentation.runOnMainSync {
ViewHelpers.setupView(view)
.setExactWidthPx(SCREEN_WIDTH_PX)
.setExactHeightPx(SCREEN_HEIGHT_PX)
.layout()
// view.draw(canvas) can't capture children that have hardware display
// lists. Force the entire tree to software so draw() sees all content.
setLayerTypeSoftwareRecursively(view)
Screenshot.snap(view).setName(screenshotName).record()
}
Log.d(TAG, "Screenshot captured: $screenshotName")
Expand Down Expand Up @@ -233,6 +233,20 @@ abstract class BaseStoryScreenshotTest {
}
}

/**
* Recursively sets LAYER_TYPE_SOFTWARE on every view in the tree.
* view.draw(canvas) skips children that have hardware display lists;
* forcing software rendering on all nodes ensures the full tree is captured.
*/
private fun setLayerTypeSoftwareRecursively(view: View) {
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
if (view is ViewGroup) {
for (i in 0 until view.childCount) {
setLayerTypeSoftwareRecursively(view.getChildAt(i))
}
}
}

private fun waitTwoFrames() {
val instrumentation = InstrumentationRegistry.getInstrumentation()
repeat(2) {
Expand Down
Loading