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 Snapshot class to capture snapshot info #1546

Open
wants to merge 23 commits 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
5 changes: 5 additions & 0 deletions paparazzi-annotations/build.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'org.jetbrains.kotlin.plugin.compose'
apply plugin: 'com.vanniktech.maven.publish'

dependencies {
implementation libs.compose.runtime
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class PaparazziPlugin @Inject constructor(
private val buildOperationRunner: BuildOperationRunner,
private val buildOperationExecutor: BuildOperationExecutor
) : Plugin<Project> {

override fun apply(project: Project) {
val supportedPlugins = listOf("com.android.application", "com.android.library", "com.android.dynamic-feature")
project.afterEvaluate {
Expand Down
9 changes: 6 additions & 3 deletions paparazzi-preview-runtime/api/paparazzi-preview-runtime.api
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
public final class app/cash/paparazzi/preview/runtime/PaparazziPreviewData {
public abstract interface class app/cash/paparazzi/preview/runtime/PaparazziPreviewData {
}

public final class app/cash/paparazzi/preview/runtime/PaparazziPreviewData$Default : app/cash/paparazzi/preview/runtime/PaparazziPreviewData {
public static final field $stable I
public fun <init> (Ljava/lang/String;Lkotlin/jvm/functions/Function2;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Lkotlin/jvm/functions/Function2;
public final fun copy (Ljava/lang/String;Lkotlin/jvm/functions/Function2;)Lapp/cash/paparazzi/preview/runtime/PaparazziPreviewData;
public static synthetic fun copy$default (Lapp/cash/paparazzi/preview/runtime/PaparazziPreviewData;Ljava/lang/String;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lapp/cash/paparazzi/preview/runtime/PaparazziPreviewData;
public final fun copy (Ljava/lang/String;Lkotlin/jvm/functions/Function2;)Lapp/cash/paparazzi/preview/runtime/PaparazziPreviewData$Default;
public static synthetic fun copy$default (Lapp/cash/paparazzi/preview/runtime/PaparazziPreviewData$Default;Ljava/lang/String;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lapp/cash/paparazzi/preview/runtime/PaparazziPreviewData$Default;
public fun equals (Ljava/lang/Object;)Z
public final fun getComposable ()Lkotlin/jvm/functions/Function2;
public final fun getSnapshotName ()Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ package app.cash.paparazzi.preview.runtime

import androidx.compose.runtime.Composable

public data class PaparazziPreviewData(
val snapshotName: String,
val composable: @Composable () -> Unit
)
/**
* Represents composables annotated with @Paparazzi annotation
*
* Default - Represents a composable with no parameters
*/
public sealed interface PaparazziPreviewData {

public data class Default(
val snapshotName: String,
val composable: @Composable () -> Unit
) : PaparazziPreviewData {
override fun toString(): String = snapshotName
}
}
11 changes: 11 additions & 0 deletions paparazzi-preview-test-junit/api/paparazzi-preview-test-junit.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class app/cash/paparazzi/preview/PaparazziValuesProvider : com/google/testing/junit/testparameterinjector/TestParameterValuesProvider {
public static final field $stable I
public fun <init> (Ljava/util/List;)V
protected fun provideValues (Lcom/google/testing/junit/testparameterinjector/TestParameterValuesProvider$Context;)Ljava/util/List;
}

public final class app/cash/paparazzi/preview/SnapshotKt {
public static final fun snapshot (Lapp/cash/paparazzi/Paparazzi;Lapp/cash/paparazzi/preview/runtime/PaparazziPreviewData;Ljava/lang/String;)V
public static synthetic fun snapshot$default (Lapp/cash/paparazzi/Paparazzi;Lapp/cash/paparazzi/preview/runtime/PaparazziPreviewData;Ljava/lang/String;ILjava/lang/Object;)V
}

10 changes: 10 additions & 0 deletions paparazzi-preview-test-junit/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'org.jetbrains.kotlin.plugin.compose'
apply plugin: 'com.vanniktech.maven.publish'

dependencies {
compileOnly libs.compose.runtime
implementation projects.paparazzi
implementation projects.paparazziPreviewRuntime
api libs.testParameterInjector
}
4 changes: 4 additions & 0 deletions paparazzi-preview-test-junit/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POM_ARTIFACT_ID=paparazzi-preview-test-junit
POM_NAME=Paparazzi Preview Test JUnit
POM_DESCRIPTION=Adds helpers to use in code generated from Paparazzi Gradle Plugin for composables annotated with @Paparazzi
POM_PACKAGING=jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright Square, Inc.
package app.cash.paparazzi.preview

import app.cash.paparazzi.Paparazzi
import app.cash.paparazzi.preview.runtime.PaparazziPreviewData
import com.google.testing.junit.testparameterinjector.TestParameterValuesProvider

/**
* Take a snapshot of the given [previewData].
*/
public fun Paparazzi.snapshot(previewData: PaparazziPreviewData, name: String? = null) {
when (previewData) {
is PaparazziPreviewData.Default -> snapshotDefault(previewData, name)
}
}

/**
* A `@TestParameter` values provider for the given [annotations].
*
* Example usage:
* ```
* private class ValuesProvider : PaparazziValuesProvider(paparazziAnnotations)
* ```
*/
public open class PaparazziValuesProvider(
private val annotations: List<PaparazziPreviewData>
) : TestParameterValuesProvider() {
override fun provideValues(context: Context?): MutableList<*> = annotations.toMutableList()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright Square, Inc.
package app.cash.paparazzi.preview

import app.cash.paparazzi.Paparazzi
import app.cash.paparazzi.preview.runtime.PaparazziPreviewData

internal fun Paparazzi.snapshotDefault(previewData: PaparazziPreviewData.Default, name: String?) {
snapshot(name) {
previewData.composable()
}
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ include ':paparazzi-gradle-plugin'
include ':paparazzi-preview-lints'
include ':paparazzi-preview-processor'
include ':paparazzi-preview-runtime'
include ':paparazzi-preview-test-junit'

include ':sample'

Expand Down
Loading