Skip to content

Commit 39280d0

Browse files
committed
Add support for render mode SHRINK for AccessibilityRenderExtension
1 parent 85696ae commit 39280d0

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

paparazzi/src/main/java/app/cash/paparazzi/accessibility/AccessibilityRenderExtension.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,17 @@ public class AccessibilityRenderExtension : RenderExtension {
4040
orientation = LinearLayout.HORIZONTAL
4141
weightSum = 2f
4242
layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
43+
isMeasureWithLargestChildEnabled = true // Allows for snapshot with SHRINK render mode
4344

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

4849
val contentLayoutParams = contentView.layoutParams ?: generateLayoutParams(null)
49-
addView(overlay, LinearLayout.LayoutParams(contentLayoutParams.width, contentLayoutParams.height, 1f))
50+
addView(overlay, LinearLayout.LayoutParams(0, contentLayoutParams.height, 1f))
5051

5152
val overlayDetailsView = AccessibilityOverlayDetailsView(context)
52-
addView(overlayDetailsView, LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT, 1f))
53+
addView(overlayDetailsView, LinearLayout.LayoutParams(0, MATCH_PARENT, 1f))
5354

5455
OneShotPreDrawListener.add(this) {
5556
val elements = buildList {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package app.cash.paparazzi.accessibility
2+
3+
import android.widget.TextView
4+
import app.cash.paparazzi.DeviceConfig
5+
import app.cash.paparazzi.Paparazzi
6+
import app.cash.paparazzi.Snapshot
7+
import app.cash.paparazzi.SnapshotHandler
8+
import app.cash.paparazzi.internal.ImageUtils
9+
import com.android.ide.common.rendering.api.SessionParams
10+
import org.junit.Rule
11+
import org.junit.Test
12+
import java.awt.image.BufferedImage
13+
import java.io.File
14+
import javax.imageio.ImageIO
15+
16+
class AccessibilityRenderExtensionShrinkTest {
17+
private val snapshotHandler = TestSnapshotVerifier()
18+
19+
@get:Rule
20+
val paparazzi = Paparazzi(
21+
deviceConfig = DeviceConfig.NEXUS_5,
22+
snapshotHandler = snapshotHandler,
23+
renderExtensions = setOf(AccessibilityRenderExtension()),
24+
renderingMode = SessionParams.RenderingMode.SHRINK
25+
)
26+
27+
@Test
28+
fun `verify baseline`() {
29+
val view = TextView(paparazzi.context).apply {
30+
id = 1
31+
text = "Text View Sample"
32+
setPadding(50, 50, 50, 50)
33+
}
34+
paparazzi.snapshot(view, name = "accessibility-shrink")
35+
}
36+
37+
private class TestSnapshotVerifier : SnapshotHandler {
38+
override fun newFrameHandler(
39+
snapshot: Snapshot,
40+
frameCount: Int,
41+
fps: Int
42+
): SnapshotHandler.FrameHandler {
43+
return object : SnapshotHandler.FrameHandler {
44+
override fun handle(image: BufferedImage) {
45+
val expected = File("src/test/resources/${snapshot.name}.png")
46+
ImageUtils.assertImageSimilar(
47+
relativePath = expected.path,
48+
image = image,
49+
goldenImage = ImageIO.read(expected),
50+
maxPercentDifferent = 0.1
51+
)
52+
}
53+
54+
override fun close() = Unit
55+
}
56+
}
57+
58+
override fun close() = Unit
59+
}
60+
}
9.68 KB
Loading

0 commit comments

Comments
 (0)