POC - Compiler Plugin (IR) to wrap Theme Composable around Preview function body#302
Draft
ychescale9 wants to merge 3 commits intomainfrom
Draft
POC - Compiler Plugin (IR) to wrap Theme Composable around Preview function body#302ychescale9 wants to merge 3 commits intomainfrom
ychescale9 wants to merge 3 commits intomainfrom
Conversation
6238ebd to
0c4734f
Compare
0c4734f to
e3f9948
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
POC for a Kotlin Compiler Plugin (IR) that transforms the functions annotated with a custom Preview annotation to wrap a user defined lambda call expression around the body.
This is meant to simplify writing Compose Previews by eliminating the need to wrap a Theme Composable around every preview, so instead of:
We can write this:
Where
@PreviewKStreamlinedis a custom Preview annotation we define:We also defines the wrapping function to be used for transforming the function body:
We then specify the custom annotation and the wrapping function to use in the plugin extension:
plugins { id("io.github.reactivecircus.cocoon") ... } cocoon { annotation.set("io.github.reactivecircus.kstreamlined.android.foundation.designsystem.preview.PreviewKStreamlined") wrappingFunction.set("io.github.reactivecircus.kstreamlined.android.foundation.designsystem.preview.KSThemeWithSurface") }During Kotlin compilation the plugin will modify the function body to produce the IR equivalent to:
Without the plugin
With the plugin
Limitations
.classfiles, and ignores the ones built by Gradle. So user has to press the "Build & Refresh" button everytime after a change.