-
Notifications
You must be signed in to change notification settings - Fork 108
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
Add support for CustomPreviewAnnotations in Showkase 🚿 🌈 #303
Add support for CustomPreviewAnnotations in Showkase 🚿 🌈 #303
Conversation
…ustom annotation and return components annotated by the annotation
Retrieving metadata from classpath
…Metadata file gen
we are checking if the flag is present, not that it is true
With the custom annotation feature we are having a bit to many components for the test emulator. We need to scroll town the page in the test to ensure that the components that we are verifying are visible
be215b0
to
5d4db05
Compare
Thanks a lot for this work @oas004 🙏 🙏 🎆 🍾 |
showkase-processor/src/main/java/com/airbnb/android/showkase/processor/ShowkaseProcessor.kt
Outdated
Show resolved
Hide resolved
showkase-processor/src/main/java/com/airbnb/android/showkase/processor/ShowkaseProcessor.kt
Outdated
Show resolved
Hide resolved
showkase-processor/src/main/java/com/airbnb/android/showkase/processor/ShowkaseProcessor.kt
Show resolved
Hide resolved
showkase-processor/src/main/java/com/airbnb/android/showkase/processor/ShowkaseProcessor.kt
Outdated
Show resolved
Hide resolved
showkase-processor/src/main/java/com/airbnb/android/showkase/processor/ShowkaseProcessor.kt
Show resolved
Hide resolved
showkase-processor/src/main/java/com/airbnb/android/showkase/processor/ShowkaseProcessor.kt
Outdated
Show resolved
Hide resolved
showkase-processor/src/main/java/com/airbnb/android/showkase/processor/ShowkaseProcessor.kt
Outdated
Show resolved
Hide resolved
showkase-processor/src/main/java/com/airbnb/android/showkase/processor/ShowkaseProcessor.kt
Show resolved
Hide resolved
showkase-processor/src/main/java/com/airbnb/android/showkase/processor/ShowkaseProcessor.kt
Show resolved
Hide resolved
This was done because we figured out that the metadata generation strategy works and this will give a better result to the enduser.
312680c
to
720166d
Compare
8d9f910
to
fc3f173
Compare
fc3f173
to
d277c86
Compare
sample-submodule-2/src/main/java/com/airbnb/android/submodule/showkasesample/LocalePreview.kt
Outdated
Show resolved
Hide resolved
db3eafe
to
7ccca0e
Compare
showkase-processor/src/main/java/com/airbnb/android/showkase/processor/ShowkaseProcessor.kt
Show resolved
Hide resolved
...rocessor/src/main/java/com/airbnb/android/showkase/processor/writer/ShowkaseBrowserWriter.kt
Show resolved
Hide resolved
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.
Fantastic job on this PR 👏🏻 This has been a long time coming but I'm so glad you were able to be persistent and took care of all the cases that we could think of.
@vinaygaba When this is merged, can you please also make a new release? This would help me with my work at work a lot! Thanks guys for this work 🙏 |
Wow this is awesome! 🥳 Thanks a lot for all the help and mentorship through the process! Learned a lot from this! |
Hi @oas004, I've tested this and it works really well. One question related to stacked custom preview, would something like this work?
|
Hi @anhanh11001 :) So glad to hear that it is working! The case that you are describing should work for KSP. I think we have a test case for this here:https://github.com/airbnb/Showkase/blob/master/showkase-processor-testing/src/test/resources/ShowkaseProcessorTest/composable_function_with_multiple_repeatable_custom_preview_annotation_generates_output/input/Composables.kt that is very similar :) Is it not working in your project? |
I see, I also use |
I think this should work out of the box if you are using KSP. I will try to check this out as well! |
I had the same problem and I found that we should apply ksp to the module we have the custom preview annotation. |
This was moved from #263 to avoid a lot of the heat after rebasing. Also fixed some of the stuff for the compiler args so that it works for KAPT as well.
Add support for CustomMultiPreviewAnnotations in Showkase.
This is the third PR in a series to add support for Custom MultiPreview Annotations. Referencing as a followup on #259 and #255.
By completing this should solve #233
resolves #233
What do I mean by Custom Preview Annotations?
This is an annotation in the form
this can be used to annotate a composable function like you would do any other preview function in Compose like this:
This can also be combined like this:
They should be able to have the custom annotations and the use of them in different modules in a project.
For more information, please see docs on tooling in compose here
Goal
The goal is to add support for this in Showkase. We would like showkase to act like the tooling in Android Studio does. That means that when Android Studio Preview would have generated a Preview, showkase should also generate a ShowkaseMetadata function.
KAPT vs KSP
Because of https://youtrack.jetbrains.com/issue/KT-49682/Support-JVM-IR-in-KAPT-stub-generation KAPT does not quite support repeatable annotations from Kotlin. This means that if you have an annotation class like:
This will be skipped by KAPT, but KSP will pick it up. However, if you have an annotation like:
It will be picked up by both KSP and KAPT.
Important for KAPT users
You will need to provide a compiler arg in you module for the custom preview annotations that you are using and expecting to be picked up by Showkase. This can be done with the following code:
It is important to remember to use the whole qualified name of the annotation, and not just the name.
Testing
Sample App
In the sample app I have introduced CustomShape from the same module
And FontPreview from the same module
You can check this in the sample app if you build it with KSP.
Browser Test
In the browser tests I have introduced CustomTextPreview
There was already a composable to verify compilation from a pervious PR, so used that as well. Since the CustomTextPreview only had one Preview annotation, this was tested to be visible with KAPT as well.
I have done the same with the submodule in the browser test. However, here I introduced CustomSizePreview and CustomFontSizePreview and verified that it works with both KAPT and KSP.
Processor Test
In the processor tests, I have made tests that make sure all the correct metadata objects are created and that we are creating the files to store the custom annotations that the processor has registered. You can check these tests in
showcase-processor-testing
module.