Slide 1

Slide 1 text

A Snapshot Preview of Paparazzi 2.0 📸 John Rodriguez

Slide 2

Slide 2 text

Recap: DCNYC 2023

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

src/main/res src/debug/res appcompat.aar:/res build/intermediates/res/merged/debug

Slide 5

Slide 5 text

AppResourceRepository ModuleResourceRepository ProjectResourceRepository ResourceFolderResourceRepository AarResourceRepository

Slide 6

Slide 6 text

RFRR (src/main/res) RFRR (src/debug/res) RFRR (resValues) MRR (feature1:views) RFRR (src/main/res) RFRR (src/debug/res) RFRR (resValues) MRR (feature2:views) PRR (main app) AppRR (main repo) AarRR (./gradle/transforms/res/)

Slide 7

Slide 7 text

• Initial pro fi ling shows heap usage drops from about ~52.9MB to ~1.7MB! • Now supports application and dynamic feature modules! • Various bugs around string resources also fi xed! • “Easier” to migrate to another build system

Slide 8

Slide 8 text

• Initial pro fi ling shows heap usage drops from about ~52.9MB to ~1.7MB! • Now supports application and dynamic feature modules! • Various bugs around string resources also fi xed! • “Easier” to migrate to another build system

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

class ValidateAccessibilityTest { @get:Rule val paparazzi = Paparazzi(validateAccessibility = true) @Test fun validateTextContrast() { paparazzi.snapshot( TextView(paparazzi.context).apply { textA= "Low Contrast" setTextColor(Color.WHITE) setBackgroundColor(Color.WHITE) } ) } } Accessibility issue of type LOW_CONTRAST on no-id: The item's text contrast ratio is 1.00. This ratio is based on a text color of #FFFFFF and background color of #FFFFFF. Consider increasing this item's text contrast ratio to 4.50 or greater.

Slide 13

Slide 13 text

class ComposeTest { @get:Rule val paparazzi = Paparazzi( deviceConfig = DeviceConfig.WEAR_OS_SMALL_ROUND, ) @Test fun compose() { paparazzi.snapshot { HelloPaparazzi() } } }

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

:feature:ui compose:ui-android:1.7.2@aar implementation apply plugin: 'com.android.library' apply plugin: 'org.jetbrains.kotlin.android'

Slide 36

Slide 36 text

:paparazzi apply plugin: ‘org.jetbrains.kotlin.jvm' compose:ui-android:1.7.2@aar

Slide 37

Slide 37 text

jar +--- META-INF | +--- services | \--- ... +--- app | +--- cash | \--- Paparazzi.class | \--- ... ... aar +--- META-INF | +--- services | \--- ... +--- AndroidManifest.xml +--- assets | \--- ... +--- baseline-profile.txt +--- classes.jar +--- jni | \--- ... +--- lint.jar +--- proguard.txt +--- public.txt +--- R.txt \--- res +--- values \--- values.xml

Slide 38

Slide 38 text

jar +--- META-INF | +--- services | \--- ... +--- app | +--- cash | \--- Paparazzi.class | \--- ... ... aar +--- META-INF | +--- services | \--- ... +--- AndroidManifest.xml +--- assets | \--- ... +--- baseline-profile.txt +--- classes.jar +--- jni | \--- ... +--- lint.jar +--- proguard.txt +--- public.txt +--- R.txt \--- res +--- values \--- values.xml

Slide 39

Slide 39 text

dependencies.registerTransform(IdentityTransform :: class.java) { it.from.attribute(AndroidArtifacts.ARTIFACT_TYPE, "jar") it.to.attribute(AndroidArtifacts.ARTIFACT_TYPE, "aarAsJar") }

Slide 40

Slide 40 text

dependencies.registerTransform(IdentityTransform :: class.java) { it.from.attribute(AndroidArtifacts.ARTIFACT_TYPE, "jar") it.to.attribute(AndroidArtifacts.ARTIFACT_TYPE, "aarAsJar") } jar IdentityTransform aarAsJar(jar)

Slide 41

Slide 41 text

dependencies.registerTransform(ExtractClassesTransform :: class.java) { it.from.attribute(AndroidArtifacts.ARTIFACT_TYPE, "aar") it.to.attribute(AndroidArtifacts.ARTIFACT_TYPE, "aarAsJar") }

Slide 42

Slide 42 text

dependencies.registerTransform(ExtractClassesTransform :: class.java) { it.from.attribute(AndroidArtifacts.ARTIFACT_TYPE, "aar") it.to.attribute(AndroidArtifacts.ARTIFACT_TYPE, "aarAsJar") } aar ExtractClassesTransform aarAsJar(classes.jar)

Slide 43

Slide 43 text

val aarAsJar = project.configurations .resolvable("implementatio n​ AarAsJar") a {a it.attributes.attribute(AndroidArtifacts.ARTIFACT_TYPE, "release") it.attributes.attribut e​​(​​​ Usage.USAGE_ATTRIBUTE, project.objects.named(Usage :: class.java, Usage.JAVA_API) ) } .incoming .artifactViewa{a it.attributes.attribute(AndroidArtifacts.ARTIFACT_TYPE, "aarAsJar") a }a .files

Slide 44

Slide 44 text

project.configurations .getByName("implementatio n​ ") .dependencies .add(project.dependencies.create (​ aarAsJar))

Slide 45

Slide 45 text

project.configurations .getByName("implementatio n​ ") .dependencies .add(project.dependencies.create (​ aarAsJar)) // paparazzi/build.gradle apply plugin: 'aar2jar' dependencies { implementationAarAsJar libs.androidx.compose.ui.android implementationAarAsJar libs.androidx.activity }

Slide 46

Slide 46 text

public fun snapshot( name: String? = null, composable: @Composable () -> Unit ) { createFrameHandler(name).use { handler -> frameHandler = handler sdk.snapshot(composable) } } @Test fun compose() { paparazzi.snapshot { HelloPaparazzi() } }

Slide 47

Slide 47 text

public fun snapshot( name: String? = null, composable: @Composable () -> Unit ) { createFrameHandler(name).use { handler -> frameHandler = handler sdk.snapshot(composable) } } @Test fun compose() { paparazzi.snapshot { HelloPaparazzi() } }

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

Jan 2024

Slide 52

Slide 52 text

Mar 2024

Slide 53

Slide 53 text

May 2024

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

=

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

package sun.java2d; public final class SunGraphics2D extends Graphics2D implements ConstrainableGraphics, Cloneable, DestSurfaceProvider { // cached state for various draw[String,Char,Byte] optimizations public FontInfo checkFontInfo(FontInfo info, Font font, FontRenderContext frc) { ... } }

Slide 62

Slide 62 text

package sun.java2d; public final class SunGraphics2D extends Graphics2D implements ConstrainableGraphics, Cloneable, DestSurfaceProvider { // cached state for various draw[String,Char,Byte] optimizations public FontInfo checkFontInfo(FontInfo info, Font font, FontRenderContext frc) { ... if (FontUtilities.isMacOSX14 && (aahint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF)) { aahint = SunHints.INTVAL_TEXT_ANTIALIAS_ON; } ... } }

Slide 63

Slide 63 text

package sun.java2d; public final class SunGraphics2D extends Graphics2D implements ConstrainableGraphics, Cloneable, DestSurfaceProvider { // cached state for various draw[String,Char,Byte] optimizations public FontInfo checkFontInfo(FontInfo info, Font font, FontRenderContext frc) { ... if (FontUtilities.isMacOSX14 && (aahint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF)) { aahint = SunHints.INTVAL_TEXT_ANTIALIAS_ON; } ... } }

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

https://www.w3.org/TR/png/#apng-frame-based-animation

Slide 71

Slide 71 text

class LottieTest { @get:Rule val paparazzi = Paparazzi() @Test fun lottie() { val composition = LottieCompositionFactory.fromRawResSync( paparazzi.context, R.raw.lottie_logo ).value !! val view = LottieAnimationView(paparazzi.context) view.setComposition(composition) view.playAnimation() } }

Slide 72

Slide 72 text

class LottieTest { @get:Rule val paparazzi = Paparazzi() @Test fun lottie() { val composition = LottieCompositionFactory.fromRawResSync( paparazzi.context, R.raw.lottie_logo ).value !! val view = LottieAnimationView(paparazzi.context) view.setComposition(composition) view.playAnimation() paparazzi.gif(view, "lottie", start = 0L, end = 5000L, fps = 60) } }

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

src/main/res src/debug/res appcompat.aar:/res build/intermediates/res/merged/debug

Slide 77

Slide 77 text

RFRR (src/main/res) RFRR (src/debug/res) RFRR (resValues) MRR (feature1:views) RFRR (src/main/res) RFRR (src/debug/res) RFRR (resValues) MRR (feature2:views) PRR (main app) AppRR (main repo) AarRR (./gradle/transforms/res/)

Slide 78

Slide 78 text

// com.android.ide.common.resources.ResourceTable Table< ResourceNamespace, ResourceType, ListMultimap > delegate: = Tables.newCustomTable( new HashMap <> (), () -> Maps.newEnumMap(ResourceType.class) );

Slide 79

Slide 79 text

// com.android.ide.common.resources.ResourceTable Table< ResourceNamespace, ResourceType, ListMultimap > delegate: = Tables.newCustomTable( new HashMap <> (), () -> Maps.newEnumMap(ResourceType.class) ); R.string.title

Slide 80

Slide 80 text

// com.android.ide.common.resources.ResourceTable Table< ResourceNamespace, ResourceType, ListMultimap > delegate: = Tables.newCustomTable( new HashMap <> (), () -> Maps.newEnumMap(ResourceType.class) ); ResourceNamespace = ResourceNamespace.RES_AUTO ResourceType = ResourceType.STRING key = "title" ResourceItem = module/src/main/res/values.xml@title="Hello world" R.string.title

Slide 81

Slide 81 text

R.string.title But how do we get: ?

Slide 82

Slide 82 text

// com/sample/R.jar public final class R { class string { public static final int title = 0x22012; ... } ... }

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

public fun main() { val me = "/Users/jrod" System.setProperty("paparazzi.project.dir", ".") System.setProperty("paparazzi.build.dir", "build") System.setProperty("paparazzi.artifacts.cache.dir", "$me/.gradle/caches") System.setProperty("paparazzi.test.resources", "$me/Development/paparazzi/sample/build/intermediates/paparazzi/debug/resources.json") System.setProperty("paparazzi.platform.data.root", "$me/.gradle/caches/transforms-4/ ... /layoutlib-native-macarm-2023.2.1-6c7316c") val output = File("test.png") val sdk = PaparazziSdk( onNewFrame = { image -> ImageIO.write(image, "PNG", output) } ) sdk.setup() sdk.prepare() sdk.snapshot(buildView(sdk.context)) sdk.teardown() println("Done!") }

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

.com/cashapp/paparazzi

Slide 88

Slide 88 text

A Snapshot Preview of Paparazzi 2.0 📸 @jrodbx