Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for render mode SHRINK for AccessibilityRenderExtension #1355

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ public class AccessibilityRenderExtension : RenderExtension {
orientation = LinearLayout.HORIZONTAL
weightSum = 2f
layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
isMeasureWithLargestChildEnabled = true // Allows for snapshot with SHRINK render mode

val overlay = AccessibilityOverlayView(context).apply {
addView(contentView, FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT))
}

val contentLayoutParams = contentView.layoutParams ?: generateLayoutParams(null)
addView(overlay, LinearLayout.LayoutParams(contentLayoutParams.width, contentLayoutParams.height, 1f))
addView(overlay, LinearLayout.LayoutParams(0, contentLayoutParams.height, 1f))

val overlayDetailsView = AccessibilityOverlayDetailsView(context)
addView(overlayDetailsView, LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT, 1f))
addView(overlayDetailsView, LinearLayout.LayoutParams(0, MATCH_PARENT, 1f))

OneShotPreDrawListener.add(this) {
val elements = buildList {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package app.cash.paparazzi.accessibility

import android.widget.TextView
import app.cash.paparazzi.DeviceConfig
import app.cash.paparazzi.Paparazzi
import app.cash.paparazzi.Snapshot
import app.cash.paparazzi.SnapshotHandler
import app.cash.paparazzi.internal.ImageUtils
import com.android.ide.common.rendering.api.SessionParams
import org.junit.Rule
import org.junit.Test
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO

class AccessibilityRenderExtensionShrinkTest {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we combine this with AccessibilityRenderExtensionTest + TestParameterInjector? Looks like renderingMode is the only argument that differs between the two.

private val snapshotHandler = TestSnapshotVerifier()

@get:Rule
val paparazzi = Paparazzi(
deviceConfig = DeviceConfig.NEXUS_5,
snapshotHandler = snapshotHandler,
renderExtensions = setOf(AccessibilityRenderExtension()),
renderingMode = SessionParams.RenderingMode.SHRINK
)

@Test
fun `verify baseline`() {
val view = TextView(paparazzi.context).apply {
id = 1
text = "Text View Sample"
setPadding(50, 50, 50, 50)
}
paparazzi.snapshot(view, name = "accessibility-shrink")
}

private class TestSnapshotVerifier : SnapshotHandler {
override fun newFrameHandler(
snapshot: Snapshot,
frameCount: Int,
fps: Int
): SnapshotHandler.FrameHandler {
return object : SnapshotHandler.FrameHandler {
override fun handle(image: BufferedImage) {
val expected = File("src/test/resources/${snapshot.name}.png")
ImageUtils.assertImageSimilar(
relativePath = expected.path,
image = image,
goldenImage = ImageIO.read(expected),
maxPercentDifferent = 0.1
)
}

override fun close() = Unit
}
}

override fun close() = Unit
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.