Skip to content

Commit

Permalink
Added ability to skip vanilla preview functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaygaba committed Dec 11, 2024
1 parent 9c3d6fc commit e4043b6
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -613,5 +613,12 @@ class ShowkaseProcessorTest : BaseProcessorTest() {
options["skipPrivatePreviews"] = "true"
compileInputsAndVerifyOutputs(options = options)
}

@Test
fun `composable functions with preview annotation are skipped`() {
val options = mutableMapOf<String, String>()
options["skipComposePreviews"] = "true"
compileInputsAndVerifyOutputs(options = options)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ShowkaseProcessorTest.composable_functions_with_preview_annotation_are_skipped.input

import androidx.compose.runtime.Composable
import com.airbnb.android.showkase.annotation.ShowkaseComposable
import androidx.compose.ui.tooling.preview.Preview

@ShowkaseComposable(name = "name1", group = "group1")
@Composable
public fun TestShowkaseComposable1() {

}

@ShowkaseComposable(name = "name2", group = "group2")
@Composable
public fun TestShowkaseComposable2() {

}

@Preview(name = "name3", group = "group3")
@Composable
public fun TestPreviewComposable3() {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ShowkaseProcessorTest.composable_functions_with_preview_annotation_are_skipped.input

import com.airbnb.android.showkase.annotation.ShowkaseComposable
import androidx.compose.runtime.Composable
import com.airbnb.android.showkase.annotation.ShowkaseRoot
import com.airbnb.android.showkase.annotation.ShowkaseRootModule

@ShowkaseRoot
public class TestShowkaseRoot: ShowkaseRootModule {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// This is an auto-generated file. Please do not edit/modify this file.
package com.airbnb.android.showkase

import com.airbnb.android.showkase.`annotation`.ShowkaseCodegenMetadata

public class
ShowkaseMetadata_showkaseprocessortest_composable_functions_with_preview_annotation_are_skipped_input
{
@ShowkaseCodegenMetadata(
showkaseName = "name1",
showkaseGroup = "group1",
packageName =
"ShowkaseProcessorTest.composable_functions_with_preview_annotation_are_skipped.input",
packageSimpleName = "input",
showkaseElementName = "TestShowkaseComposable1",
insideObject = false,
insideWrapperClass = false,
showkaseKDoc = "",
generatedPropertyName = "TestShowkaseComposable1group1name1",
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
)
public
fun ShowkaseProcessorTestcomposablefunctionswithpreviewannotationareskippedinputTestShowkaseComposable1group1name1() {
}

@ShowkaseCodegenMetadata(
showkaseName = "name2",
showkaseGroup = "group2",
packageName =
"ShowkaseProcessorTest.composable_functions_with_preview_annotation_are_skipped.input",
packageSimpleName = "input",
showkaseElementName = "TestShowkaseComposable2",
insideObject = false,
insideWrapperClass = false,
showkaseKDoc = "",
generatedPropertyName = "TestShowkaseComposable2group2name2",
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
)
public
fun ShowkaseProcessorTestcomposablefunctionswithpreviewannotationareskippedinputTestShowkaseComposable2group2name2() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This is an auto-generated file. Please do not edit/modify this file.
package ShowkaseProcessorTest.composable_functions_with_preview_annotation_are_skipped.input

import androidx.compose.runtime.Composable
import com.airbnb.android.showkase.models.ShowkaseBrowserComponent

public val TestShowkaseComposable1group1name1: ShowkaseBrowserComponent = ShowkaseBrowserComponent(
group = "group1",
componentName = "name1",
componentKDoc = "",
componentKey =
"""ShowkaseProcessorTest.composable_functions_with_preview_annotation_are_skipped.input_TestShowkaseComposable1_null_group1_name1_0_null""",
isDefaultStyle = false,
component = @Composable { TestShowkaseComposable1() }
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This is an auto-generated file. Please do not edit/modify this file.
package ShowkaseProcessorTest.composable_functions_with_preview_annotation_are_skipped.input

import androidx.compose.runtime.Composable
import com.airbnb.android.showkase.models.ShowkaseBrowserComponent

public val TestShowkaseComposable2group2name2: ShowkaseBrowserComponent = ShowkaseBrowserComponent(
group = "group2",
componentName = "name2",
componentKDoc = "",
componentKey =
"""ShowkaseProcessorTest.composable_functions_with_preview_annotation_are_skipped.input_TestShowkaseComposable2_null_group2_name2_0_null""",
isDefaultStyle = false,
component = @Composable { TestShowkaseComposable2() }
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// This is an auto-generated file. Please do not edit/modify this file.
package ShowkaseProcessorTest.composable_functions_with_preview_annotation_are_skipped.input

import com.airbnb.android.showkase.`annotation`.ShowkaseRootCodegen
import com.airbnb.android.showkase.models.ShowkaseBrowserColor
import com.airbnb.android.showkase.models.ShowkaseBrowserComponent
import com.airbnb.android.showkase.models.ShowkaseBrowserTypography
import com.airbnb.android.showkase.models.ShowkaseProvider
import kotlin.collections.List

@ShowkaseRootCodegen(
numComposablesWithoutPreviewParameter = 2,
numComposablesWithPreviewParameter = 0,
numColors = 0,
numTypography = 0,
)
public class TestShowkaseRootCodegen : ShowkaseProvider {
override fun getShowkaseComponents(): List<ShowkaseBrowserComponent> {

return listOf<ShowkaseBrowserComponent>(
TestShowkaseComposable1group1name1,
TestShowkaseComposable2group2name2,
)
}

override fun getShowkaseColors(): List<ShowkaseBrowserColor> {

return listOf<ShowkaseBrowserColor>(
)
}

override fun getShowkaseTypography(): List<ShowkaseBrowserTypography> {

return listOf<ShowkaseBrowserTypography>(
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// This is an auto-generated file. Please do not edit/modify this file.
package ShowkaseProcessorTest.composable_functions_with_preview_annotation_are_skipped.input

import android.content.Context
import android.content.Intent
import com.airbnb.android.showkase.models.Showkase
import com.airbnb.android.showkase.models.ShowkaseElementsMetadata
import com.airbnb.android.showkase.models.ShowkaseProvider
import com.airbnb.android.showkase.ui.ShowkaseBrowserActivity

/**
* Helper function that's autogenerated and gives you an intent to start the ShowkaseBrowser.
*/
public fun Showkase.getBrowserIntent(context: Context): Intent {
val intent = Intent(context, ShowkaseBrowserActivity::class.java)
intent.putExtra("SHOWKASE_ROOT_MODULE",
"ShowkaseProcessorTest.composable_functions_with_preview_annotation_are_skipped.input.TestShowkaseRoot")
return intent
}

/**
* Helper function that's give's you access to Showkase metadata. This contains data about the
* composables, colors and typography in your codebase that's rendered in showkase.
*/
public fun Showkase.getMetadata(): ShowkaseElementsMetadata {
try {
val showkaseComponentProvider =
Class.forName("ShowkaseProcessorTest.composable_functions_with_preview_annotation_are_skipped.input.TestShowkaseRootCodegen")
.getDeclaredConstructor()
.newInstance() as ShowkaseProvider
return showkaseComponentProvider.metadata()
} catch(exception: ClassNotFoundException) {
error("The class wasn't generated correctly. Make sure that you have setup Showkase correctly by following the steps here - https://github.com/airbnb/Showkase#Installation.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ShowkaseProcessor @JvmOverloads constructor(
?.toSet()?.let { set.addAll(it) }
return set
}
override fun getSupportedOptions() = mutableSetOf("skipPrivatePreviews", "multiPreviewType")
override fun getSupportedOptions() = mutableSetOf("skipPrivatePreviews", "skipComposePreviews", "multiPreviewType")

override fun process(environment: XProcessingEnv, round: XRoundEnv) {
val componentMetadata = processComponentAnnotation(round)
Expand Down Expand Up @@ -129,6 +129,10 @@ class ShowkaseProcessor @JvmOverloads constructor(

private fun processPreviewAnnotation(roundEnvironment: XRoundEnv): Set<ShowkaseMetadata.Component> {
val skipPrivatePreviews = environment.options["skipPrivatePreviews"] == "true"
val skipComposePreviews = environment.options["skipComposePreviews"] == "true"

if (skipComposePreviews) return emptySet()

return roundEnvironment.getElementsAnnotatedWith(PREVIEW_CLASS_NAME)
.mapNotNull { element ->
if (showkaseValidator.checkElementIsAnnotationClass(element)) {
Expand Down

0 comments on commit e4043b6

Please sign in to comment.