-
Notifications
You must be signed in to change notification settings - Fork 11
feat: Generate stories from @Preview composables #70
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
Open
congvc-dev
wants to merge
23
commits into
Kotlin:main
Choose a base branch
from
congvc-dev:preview-scanner
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
30fba00
add :modules:preview-processor
congvc-dev e343aa5
Add PreviewProcessor and first good test
congvc-dev b89fdcf
Implement PreviewProcessor
congvc-dev 909d4d7
Add missing SymbolProcessorProvider metadata
congvc-dev ec79a93
generated stories are in org.jetbrains.compose.storytale.generated
congvc-dev fba031b
Add previewParameter functions for non Story scopes
congvc-dev 704cb23
apply spotless
congvc-dev 9ba6ec2
add :modules:preview-processor-test
congvc-dev 885c84e
move PreviewProcessorTest to :modules:preview-processor-test
congvc-dev 1ac4019
add AssertableFile.kt and Compilation.kt
congvc-dev 0eb1388
apply spotless
congvc-dev c0ce783
bump JDK version v21 in github workflows
congvc-dev 2f1cd84
disable proguard for :gallery-demo desktop target
congvc-dev a498709
pretty PreviewProcessorTest
congvc-dev 2350e9a
Support multiple @Preview composables
congvc-dev b84713d
Add @Preview composables samples in :gallery-demo
congvc-dev 6df79a6
apply spotless
congvc-dev e74c5e6
Merge branch 'ci-java-21' into preview-scanner
congvc-dev 2d1634a
Sort validPreviewFunctions before generatePreviewFile in PreviewProce…
congvc-dev a233b23
apply spotless
congvc-dev 53680fb
Add PublicPreviewComposableRegistrar
congvc-dev 146268d
Add MakePreviewPublicFirExtensionRegistrar
congvc-dev 2fa23cb
apply spotless
congvc-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
gallery-demo/src/commonMain/kotlin/storytale/gallery/demo/PreviewCheckbox.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package storytale.gallery.demo | ||
|
||
import androidx.compose.material3.TriStateCheckbox | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.state.ToggleableState | ||
import androidx.compose.ui.state.ToggleableState.Indeterminate | ||
import androidx.compose.ui.state.ToggleableState.Off | ||
import androidx.compose.ui.state.ToggleableState.On | ||
import org.jetbrains.compose.storytale.previewParameter | ||
import org.jetbrains.compose.ui.tooling.preview.Preview | ||
|
||
@Preview | ||
@Composable | ||
@Suppress("ktlint") | ||
private fun PreviewCheckbox() { | ||
var state by previewParameter(ToggleableState.entries) | ||
|
||
TriStateCheckbox( | ||
state = state, | ||
onClick = { | ||
state = when (state) { | ||
On -> Indeterminate | ||
Off -> On | ||
Indeterminate -> Off | ||
} | ||
}, | ||
) | ||
} |
51 changes: 51 additions & 0 deletions
51
gallery-demo/src/desktopMain/kotlin/storytale/gallery/demo/PreviewButton.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package storytale.gallery.demo | ||
|
||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.AddCircle | ||
import androidx.compose.material3.ExtendedFloatingActionButton | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.SegmentedButton | ||
import androidx.compose.material3.SegmentedButtonDefaults | ||
import androidx.compose.material3.SingleChoiceSegmentedButtonRow | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.mutableIntStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import org.jetbrains.compose.storytale.previewParameter | ||
|
||
@org.jetbrains.compose.ui.tooling.preview.Preview | ||
@Composable | ||
@Suppress("ktlint") | ||
private fun PreviewExtendedFAB() { | ||
val bgColor by previewParameter(MaterialTheme.colorScheme.primary) | ||
|
||
ExtendedFloatingActionButton(onClick = {}, containerColor = bgColor) { | ||
Icon(imageVector = Icons.Default.AddCircle, contentDescription = null) | ||
Spacer(Modifier.padding(4.dp)) | ||
Text("Extended") | ||
} | ||
} | ||
|
||
@androidx.compose.desktop.ui.tooling.preview.Preview | ||
@Composable | ||
@Suppress("ktlint") | ||
private fun PreviewSegmentedButton() { | ||
val selectedIndex = remember { mutableIntStateOf(0) } | ||
|
||
SingleChoiceSegmentedButtonRow { | ||
repeat(3) { index -> | ||
SegmentedButton( | ||
selected = index == selectedIndex.value, | ||
onClick = { selectedIndex.value = index }, | ||
shape = SegmentedButtonDefaults.itemShape(index, 3), | ||
) { | ||
Text("Button $index", modifier = Modifier.padding(4.dp)) | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import org.gradle.kotlin.dsl.compileOnly | ||
import org.gradle.kotlin.dsl.kotlin | ||
import org.gradle.kotlin.dsl.project | ||
import org.gradle.kotlin.dsl.withType | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask | ||
|
||
plugins { | ||
alias(libs.plugins.kotlinMultiplatform) | ||
alias(libs.plugins.androidLibrary) | ||
alias(libs.plugins.jetbrainsCompose) | ||
alias(libs.plugins.compose.compiler) | ||
} | ||
|
||
kotlin { | ||
jvm() | ||
androidTarget() | ||
|
||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
compileOnly(compose.runtime) | ||
} | ||
} | ||
val jvmMain by getting { | ||
dependencies { | ||
implementation(compose.components.uiToolingPreview) | ||
implementation(project(":modules:preview-processor")) | ||
implementation(kotlin("test")) | ||
|
||
implementation(compose.runtime) | ||
implementation(kotlin("compiler-embeddable")) | ||
implementation(kotlin("compose-compiler-plugin-embeddable")) | ||
implementation(kotlin("test")) | ||
implementation(libs.assertj.core) | ||
implementation(libs.junit) | ||
implementation(libs.kotlinCompileTesting.ksp) | ||
implementation(project(":modules:runtime-api")) | ||
} | ||
} | ||
val androidUnitTest by getting { | ||
dependsOn(jvmMain) | ||
|
||
dependencies { | ||
implementation("androidx.compose.ui:ui-tooling-preview-android:1.7.0") | ||
} | ||
} | ||
val jvmTest by getting { | ||
dependencies { | ||
implementation("androidx.compose.ui:ui-tooling-preview-desktop:1.7.0") | ||
} | ||
} | ||
} | ||
} | ||
|
||
android { | ||
compileSdk = 35 | ||
namespace = "org.jetbrains.compose.storytale.preview.processor.test" | ||
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") | ||
defaultConfig { | ||
minSdk = 24 | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_21 | ||
targetCompatibility = JavaVersion.VERSION_21 | ||
} | ||
} | ||
|
||
tasks.withType<KotlinCompilationTask<*>>().configureEach { | ||
compilerOptions.optIn.add("org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi") | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know yet what exactly requires java 21 in this PR, but we need to stick to java 17 (should be compatible with java 17), because it's used in Compose repository.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on this job, I suspect that my PR uses KSP 2.1.20-2.0.1 which was compiled with Java 21. Lowering KSP version perhaps the plausible option here