### CI Git LFS Setup Script Example Source: https://github.com/cashapp/paparazzi/blob/master/README.md An example script for CI environments to ensure Git LFS is installed and pulls snapshots correctly. This is crucial for consistent test runs. ```bash if [[ is running snapshot tests ]]; then # fail fast if files not checked in using git lfs "$HOOKS_DIR"/pre-receive git lfs install --local git lfs pull fi ``` -------------------------------- ### Paparazzi Setup and Snapshot with JUnit 5 Source: https://github.com/cashapp/paparazzi/blob/master/README.md Provides the necessary setup and teardown methods for using Paparazzi with JUnit 5. This includes initializing and cleaning up the Paparazzi instance for each test. ```kotlin lateinit var paparazzi: Paparazzi @BeforeEach fun setup(testInfo: TestInfo) { paparazzi = Paparazzi().apply { setup( testName = TestName( packageName = testInfo.testClass.get().`package`?.name.orEmpty(), className = testInfo.testClass.get().simpleName, methodName = testInfo.testMethod.get().name ) ) } } @AfterEach fun tearDown() { paparazzi.teardown() } @Test fun snapshot_example() { val view = paparazzi.inflate(android.R.layout.simple_list_item_1).apply { text = "Hello Paparazzi" textSize = 24f gravity = Gravity.CENTER } paparazzi.snapshot(view) } ``` -------------------------------- ### Install Git LFS Source: https://github.com/cashapp/paparazzi/blob/master/README.md Installs Git Large File Storage (LFS) using Homebrew. This is recommended for managing large snapshot files. ```bash brew install git-lfs ``` -------------------------------- ### Configure Paparazzi with AccessibilityRenderExtension Source: https://github.com/cashapp/paparazzi/blob/master/docs/accessibility.md Add the AccessibilityRenderExtension to your Paparazzi configuration to enable accessibility snapshot testing. This setup is required before creating accessibility snapshot tests. ```kotlin @get: val paparazzi = Paparazzi( renderExtensions = setOf(AccessibilityRenderExtension()), ) ``` -------------------------------- ### Set Accessibility Traversal Order Source: https://github.com/cashapp/paparazzi/blob/master/docs/accessibility.md Define the order in which accessibility services traverse UI elements using `accessibilityTraversalAfter`. This example sets up three TextViews where 'Third' is traversed after 'Second', and 'Second' after 'First'. ```kotlin val first = TextView(context).apply { id = View.generateViewId() text = "First" } val second = TextView(context).apply { id = View.generateViewId() text = "Second" accessibilityTraversalAfter = first.id } val third = TextView(context).apply { id = View.generateViewId() text = "Third" accessibilityTraversalAfter = second.id } ``` -------------------------------- ### Basic Paparazzi Test with Views and Composables Source: https://github.com/cashapp/paparazzi/blob/master/README.md Demonstrates how to use Paparazzi with both traditional Android Views and Jetpack Compose. Ensure you have the Paparazzi rule and appropriate configurations. ```kotlin class LaunchViewTest { @get:Rule val paparazzi = Paparazzi( deviceConfig = PIXEL_5, theme = "android:Theme.Material.Light.NoActionBar" // ...see docs for more options ) @Test fun launchView() { val view = paparazzi.inflate(R.layout.launch) // or... // val view = LaunchView(paparazzi.context) view.setModel(LaunchModel(title = "paparazzi")) paparazzi.snapshot(view) } @Test fun launchComposable() { paparazzi.snapshot { MyComposable() } } } ``` -------------------------------- ### Configure Git Hooks for LFS Source: https://github.com/cashapp/paparazzi/blob/master/README.md Sets up Git LFS to track PNG snapshot files. This ensures that large files are handled correctly by Git. ```bash git config core.hooksPath # optional, confirm where your git hooks will be installed git lfs install --local git lfs track "**/snapshots/**/*.png" git add .gitattributes # Optional to improve git checkout performance git config lfs.setlockablereadonly false ``` -------------------------------- ### Gradle Task to Verify Paparazzi Snapshots Source: https://github.com/cashapp/paparazzi/blob/master/README.md Runs tests and compares current snapshots against previously recorded golden values. Failures will generate diffs for review. ```bash ./gradlew :sample:verifyPaparazziDebug ``` -------------------------------- ### Snapshotting UI with DropdownMenu Source: https://github.com/cashapp/paparazzi/blob/master/docs/accessibility.md Capture a snapshot of a UI component that includes a DropdownMenu. This is useful for verifying how accessibility properties are handled for elements within pop-up menus. ```kotlin paparazzi.snapshot { Box(Modifier.fillMaxSize()) { DropdownMenu(expanded = true, onDismissRequest = {}) { DropdownMenuItem(text = { Text("Option 1") }, onClick = {}) DropdownMenuItem(text = { Text("Option 2") }, onClick = {}) } } } ``` -------------------------------- ### Configure Snapshots Repository for Development Versions Source: https://github.com/cashapp/paparazzi/blob/master/README.md Adds a Maven repository to your Gradle configuration to access development snapshots of the Paparazzi library. This is useful for testing unreleased versions. ```groovy repositories { // ... maven { url 'https://central.sonatype.com/repository/maven-snapshots/' } } ``` -------------------------------- ### Gradle Task to Record Paparazzi Snapshots Source: https://github.com/cashapp/paparazzi/blob/master/README.md Saves current snapshots as golden values. These are typically stored in a source-controlled location for future verification. ```bash ./gradlew :sample:recordPaparazziDebug ``` -------------------------------- ### Gradle Plugin Application with buildscript Source: https://github.com/cashapp/paparazzi/blob/master/README.md Applies the Paparazzi Gradle plugin using the traditional `buildscript` block. This method is compatible with older Gradle versions. ```groovy buildscript { repositories { mavenCentral() google() } dependencies { classpath 'app.cash.paparazzi:paparazzi-gradle-plugin:2.0.0-alpha05' } } apply plugin: 'app.cash.paparazzi' ``` -------------------------------- ### Snapshotting a Mixed View Hierarchy (View + Compose) Source: https://github.com/cashapp/paparazzi/blob/master/docs/accessibility.md Test a UI hierarchy that combines Android Views and Jetpack Compose elements. This snippet demonstrates how to snapshot such a mixed view. Ensure the AccessibilityRenderExtension is configured. ```kotlin @Test fun mixedTest() { val mixedView = MixedView(paparazzi.context) paparazzi.snapshot(mixedView) } ``` -------------------------------- ### Compose: Element Visibility and Filtering Source: https://github.com/cashapp/paparazzi/blob/master/docs/accessibility.md Demonstrates how Compose elements are excluded from accessibility legends based on semantics like invisibility or zero alpha. Also shows how clearAndSetSemantics overrides child content. ```kotlin Column { // Excluded: invisible to user Text(modifier = Modifier.semantics { invisibleToUser() }, text = "Hidden") // Excluded: zero alpha Text(modifier = Modifier.alpha(0f), text = "Transparent") // Included: overridden semantics Column(modifier = Modifier.clearAndSetSemantics { contentDescription = "Custom description" }) { Text("Child text is not in legend") } } ``` -------------------------------- ### Gradle Task to Run Tests and Generate Reports Source: https://github.com/cashapp/paparazzi/blob/master/README.md Executes all tests and generates an HTML report detailing test runs and snapshots. This is useful for reviewing test results. ```bash ./gradlew :sample:testDebug ``` -------------------------------- ### Compose: Traversal Order with traversalIndex Source: https://github.com/cashapp/paparazzi/blob/master/docs/accessibility.md Illustrates how to control the accessibility traversal order in Compose using the traversalIndex modifier. Lower values are prioritized, with layout order as a tiebreaker. ```kotlin Column { Text("Third", modifier = Modifier.semantics { traversalIndex = 2f }) Text("First", modifier = Modifier.semantics { traversalIndex = -1f }) Text("Second") // Default traversalIndex = 0f } // Legend order: First, Second, Third ``` -------------------------------- ### Gradle Plugin Application with Plugins DSL Source: https://github.com/cashapp/paparazzi/blob/master/README.md Applies the Paparazzi Gradle plugin using the modern plugins DSL. This is the recommended approach for newer Gradle versions. ```groovy plugins { id 'app.cash.paparazzi' version '2.0.0-alpha05' } ``` -------------------------------- ### Snapshotting a Jetpack Compose Composable Source: https://github.com/cashapp/paparazzi/blob/master/docs/accessibility.md Use this snippet to create an accessibility snapshot test for a Jetpack Compose UI element. Ensure the AccessibilityRenderExtension is configured. ```kotlin @Test fun composableTest() { paparazzi.snapshot { MyComposable() } } ``` -------------------------------- ### Workaround for LocalInspectionMode in Composables Source: https://github.com/cashapp/paparazzi/blob/master/README.md Demonstrates how to wrap a Composable that checks for `LocalInspectionMode` with a `CompositionLocalProvider`. This ensures the snapshot represents production output rather than a preview mode. ```kotlin @Test fun inspectionModeView() { paparazzi.snapshot( CompositionLocalProvider(LocalInspectionMode provides true) { YourComposable() } ) } ``` -------------------------------- ### Snapshotting an Android View Source: https://github.com/cashapp/paparazzi/blob/master/docs/accessibility.md Create an accessibility snapshot test for a custom Android View. This requires instantiating the view and passing it to the snapshot function. Ensure the AccessibilityRenderExtension is configured. ```kotlin @Test fun viewTest() { val view = MyCustomView(paparazzi.context) paparazzi.snapshot(view) } ``` -------------------------------- ### Force Lottie Executor for Paparazzi Compatibility Source: https://github.com/cashapp/paparazzi/blob/master/README.md Forces Lottie to use a single-threaded executor that runs tasks on the current thread. This is a workaround for issues where Lottie animations might cause exceptions in Paparazzi. ```kotlin @Before fun setup() { LottieTask.EXECUTOR = Executor(Runnable::run) } ``` -------------------------------- ### CI Pre-receive Hook for Git LFS Verification Source: https://github.com/cashapp/paparazzi/blob/master/README.md A script to be used in a CI environment's pre-receive hook. It verifies that files are committed using Git LFS, preventing potential issues. ```bash # compares files that match .gitattributes filter to those actually tracked by git-lfs diff <(git ls-files ':(attr:filter=lfs)' | sort) <(git lfs ls-files -n | sort) >/dev/null ret=$? if [[ $ret -ne 0 ]]; then echo >&2 "This remote has detected files committed without using Git LFS. Run 'brew install git-lfs && git lfs install' to install it and re-commit your files."; exit 1; fi ``` -------------------------------- ### Determinate and Adjustable Progress Indicators in Compose Source: https://github.com/cashapp/paparazzi/blob/master/docs/accessibility.md Implement determinate progress with `CircularProgressIndicator` and adjustable sliders with custom labels using the `semantics` modifier and `setProgress` action. ```kotlin // Determinate progress CircularProgressIndicator(progress = 0.75f) // Adjustable slider with custom label Slider( modifier = Modifier.semantics { setProgress("Adjust volume") { true } }, value = 0.5f, onValueChange = {} ) ``` -------------------------------- ### Custom Accessibility Actions in Views Source: https://github.com/cashapp/paparazzi/blob/master/docs/accessibility.md Add custom accessibility actions to Views using `ViewCompat.setAccessibilityDelegate` and `AccessibilityNodeInfoCompat.AccessibilityActionCompat`. This allows defining specific interactions beyond standard ones. ```kotlin ViewCompat.setAccessibilityDelegate(button, object : AccessibilityDelegateCompat() { override fun onInitializeAccessibilityNodeInfo(host: View, info: AccessibilityNodeInfoCompat) { super.onInitializeAccessibilityNodeInfo(host, info) info.addAction( AccessibilityNodeInfoCompat.AccessibilityActionCompat( AccessibilityNodeInfoCompat.ACTION_CLICK, "Custom Click Action" ) ) } }) ``` -------------------------------- ### Setting On-Click Label in Compose Source: https://github.com/cashapp/paparazzi/blob/master/docs/accessibility.md Provide an `onClickLabel` in the `clickable` modifier to give context about what happens when a Compose element is activated. This is read by screen readers. ```kotlin Box(modifier = Modifier.clickable(onClickLabel = "Add to cart") { }) { Text("Product") } ``` -------------------------------- ### Jetifier Configuration to Ignore Dependencies Source: https://github.com/cashapp/paparazzi/blob/master/README.md Adds configuration to `gradle.properties` to exclude specific Android dependencies from Jetifier migration. This can prevent conflicts when migrating from Support libraries. ```properties android.jetifier.ignorelist=android-base-common,common ``` -------------------------------- ### Custom Accessibility Actions in Compose Source: https://github.com/cashapp/paparazzi/blob/master/docs/accessibility.md Define custom accessibility actions for Compose elements using the `semantics` modifier and a list of `CustomAccessibilityAction`. Each action provides a specific interaction. ```kotlin Box(modifier = Modifier.semantics { customActions = listOf( CustomAccessibilityAction("Delete") { true }, CustomAccessibilityAction("Archive") { true } ) }) { /* ... */ } ``` -------------------------------- ### Link Annotations in Compose AnnotatedString Source: https://github.com/cashapp/paparazzi/blob/master/docs/accessibility.md Surface links within an `AnnotatedString` in Compose as accessibility actions. URL links are rendered as `` and clickable links as ``. ```kotlin val annotatedString = buildAnnotatedString { append("Visit ") pushLink(LinkAnnotation.Url("https://example.com")) append("our website") pop() } Text(text = annotatedString) // Legend: "Visit our website, : our website" ``` -------------------------------- ### Setting Semantic Role in Compose Source: https://github.com/cashapp/paparazzi/blob/master/docs/accessibility.md Use the `semantics` modifier with `role` to define the semantic role of a Compose UI element. This helps assistive technologies identify the element's purpose. ```kotlin Box(modifier = Modifier.semantics { role = Role.Button }) { Text("Submit") } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.