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

Make stacked preview annotations generate showkaseMetadata components for each annotation #259

Merged
merged 15 commits into from Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -173,6 +173,7 @@ to understand the behavior when you don't pass any properties.
**Note:** Make sure that you add this annotation to only those functions that meet the following criteria:
- Functions that don't have any parameters
- If it does have a parameter, it has to be annotated with `@PreviewParameter` that is provided a `PreviewParameterProvider` implementation.
- Stacked `@Preview` and `ShowkaseComposable` annotations are only supported with KSP at the moment. This is because of this [issue](https://youtrack.jetbrains.com/issue/KT-49682).

This is identical to how `@Preview` works in Compose as well so Showkase just adheres to the same rules.

Expand Down
@@ -1,5 +1,7 @@
package com.airbnb.android.showkasesample

import android.content.res.Configuration.UI_MODE_NIGHT_NO
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
Expand All @@ -9,6 +11,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.airbnb.android.showkase.annotation.ShowkaseComposable

Expand Down Expand Up @@ -44,3 +47,24 @@ fun BasicChipYellowPreview() {
modifier = Modifier.background(color = Color.Yellow)
)
}

@Preview(name = "Basic Chip Blue Light", group = "Chips", uiMode = UI_MODE_NIGHT_NO)
@Preview(name = "Basic Chip Blue Dark", group = "Chips", uiMode = UI_MODE_NIGHT_YES)
@Composable
fun BasicChipBluePreview() {
BasicChip(
text = "Chip Component",
modifier = Modifier.background(color = Color.Blue)
)
}


@ShowkaseComposable(name = "Basic Chip Grey Light", group = "Chips")
vinaygaba marked this conversation as resolved.
Show resolved Hide resolved
@ShowkaseComposable(name = "Basic Chip Grey Dark", group = "Chips")
@Composable
fun BasicChipGreyPreview() {
BasicChip(
text = "Chip Component",
modifier = Modifier.background(color = Color.Gray)
)
}
Expand Up @@ -57,6 +57,7 @@ package com.airbnb.android.showkase.annotation
@MustBeDocumented
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.FUNCTION)
@Repeatable
@Suppress("LongParameterList")
annotation class ShowkaseComposable(
val name: String = "",
Expand Down
7 changes: 7 additions & 0 deletions showkase-browser-testing/build.gradle
Expand Up @@ -20,6 +20,7 @@ android {
exclude 'META-INF/gradle/incremental.annotation.processors'
exclude("META-INF/*.kotlin_module")
}

defaultConfig {
minSdkVersion 26
targetSdkVersion 32
Expand All @@ -28,6 +29,12 @@ android {
// "pm clear" command after each test invocation. This command ensures
// that the app's state is completely cleared between tests.
testInstrumentationRunnerArguments clearPackageData: 'true'

if (project.hasProperty('useKsp')) {
buildConfigField "boolean", "IS_RUNNING_KSP", "true"
} else {
buildConfigField "boolean", "IS_RUNNING_KSP", "false"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
Expand Down