Skip to content
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 @@ -7,7 +7,6 @@ import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome.FROM_CACHE
import org.gradle.testkit.runner.TaskOutcome.SUCCESS
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import java.io.File
import java.nio.file.Files
Expand Down Expand Up @@ -697,7 +696,6 @@ class PaparazziPluginTest {
}

@Test
@Ignore
fun withMaterialComponents() {
val fixtureRoot = File("src/test/projects/material-components-present")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ android {
}

dependencies {
implementation 'com.google.android.material:material:1.5.0-alpha03'
}
implementation 'com.google.android.material:material:1.6.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import org.junit.Test

class ButtonViewTest {
@get:Rule
val paparazzi = Paparazzi(theme = "Theme.MaterialComponents")
val paparazzi = Paparazzi(
theme = "Theme.MaterialComponents.NoActionBar",
appCompatViewInflaterClassName = "com.google.android.material.theme.MaterialComponentsViewInflater",
)

@Test
fun testViews() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 24 additions & 16 deletions paparazzi/src/main/java/app/cash/paparazzi/Paparazzi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import com.android.layoutlib.bridge.impl.RenderAction
import com.android.layoutlib.bridge.impl.RenderSessionImpl
import java.awt.image.BufferedImage
import java.lang.reflect.Field
import java.lang.reflect.Method
import java.lang.reflect.Modifier
import java.util.Date
import java.util.concurrent.TimeUnit
Expand All @@ -86,6 +87,7 @@ class Paparazzi @JvmOverloads constructor(
private val theme: String = "android:Theme.Material.NoActionBar.Fullscreen",
private val renderingMode: RenderingMode = RenderingMode.NORMAL,
private val appCompatEnabled: Boolean = true,
private val appCompatViewInflaterClassName: String = "androidx.appcompat.app.AppCompatViewInflater",
private val maxPercentDifference: Double = 0.1,
private val snapshotHandler: SnapshotHandler = determineHandler(maxPercentDifference),
private val renderExtensions: Set<RenderExtension> = setOf()
Expand Down Expand Up @@ -444,22 +446,8 @@ class Paparazzi @JvmOverloads constructor(
context: Context,
attrs: AttributeSet
): View? {
val appCompatViewInflaterClass =
Class.forName("androidx.appcompat.app.AppCompatViewInflater")

val createViewMethod = appCompatViewInflaterClass
.getDeclaredMethod(
"createView",
View::class.java,
String::class.java,
Context::class.java,
AttributeSet::class.java,
Boolean::class.javaPrimitiveType,
Boolean::class.javaPrimitiveType,
Boolean::class.javaPrimitiveType,
Boolean::class.javaPrimitiveType
)
.apply { isAccessible = true }
val appCompatViewInflaterClass = Class.forName(appCompatViewInflaterClassName)
val createViewMethod = getCreateViewMethod(appCompatViewInflaterClass) ?: throw IllegalStateException("View inflater doesn't have `createView` method")

val inheritContext = true
val readAndroidTheme = true
Expand All @@ -476,6 +464,26 @@ class Paparazzi @JvmOverloads constructor(
) as View?
}

fun getCreateViewMethod(clazz: Class<*>): Method? {
try {
return clazz
.getDeclaredMethod(
"createView",
View::class.java,
String::class.java,
Context::class.java,
AttributeSet::class.java,
Boolean::class.javaPrimitiveType,
Boolean::class.javaPrimitiveType,
Boolean::class.javaPrimitiveType,
Boolean::class.javaPrimitiveType
)
.apply { isAccessible = true }
} catch (error: NoSuchMethodException) {
return clazz.superclass?.let { getCreateViewMethod(it) }
}
}

override fun onCreateView(
name: String,
context: Context,
Expand Down