-
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 Custom Preview Annotations #263
Add support for Custom Preview Annotations #263
Conversation
showkase-processor/src/main/java/com/airbnb/android/showkase/processor/ShowkaseProcessor.kt
Show resolved
Hide resolved
...ase-processor/src/main/java/com/airbnb/android/showkase/processor/models/ShowkaseMetadata.kt
Outdated
Show resolved
Hide resolved
...ase-processor/src/main/java/com/airbnb/android/showkase/processor/models/ShowkaseMetadata.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
Outdated
Show resolved
Hide resolved
showkase-processor/src/main/java/com/airbnb/android/showkase/processor/ShowkaseProcessor.kt
Show resolved
Hide resolved
...e-processor/src/main/java/com/airbnb/android/showkase/processor/logging/ShowkaseValidator.kt
Outdated
Show resolved
Hide resolved
sample/src/main/java/com/airbnb/android/showkasesample/CustomPreview.kt
Outdated
Show resolved
Hide resolved
111b43d
to
5fc4bef
Compare
db752cf
to
5d8ba7e
Compare
...rocessor/src/main/java/com/airbnb/android/showkase/processor/writer/ShowkaseBrowserWriter.kt
Show resolved
Hide resolved
7b0419c
to
ea3e4c7
Compare
e6646de
to
aad61a6
Compare
a32b305
to
f46bef0
Compare
It looks like it runs ksp anyway if the property is there
9e6d946
to
6cd4a89
Compare
showkase-processor/src/main/java/com/airbnb/android/showkase/processor/ShowkaseProcessor.kt
Outdated
Show resolved
Hide resolved
return (showkaseComposablesMetadata + previewComposablesMetadata) | ||
|
||
// This is for getting custom annotations from class path | ||
val customAnnotationMetadataFromClassPath = |
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.
Why are we picking from the classpath here? Why not do it at the same place where we do it for @Preview
and @ShowkaseComposable
annotations
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 think the reason I have to split this up into two methods, is that the processCustomAnnotation
method only uses the supported annotations type qualified name and was meant for KAPT to work. But the processCustomAnnotationFromClassPath
was meant to get the stored annotation metadata from each round and based on that check if we had any qualified names we could search for. The reason we have to split them up is that we are using some of the other properties from the stored metadata that we store on each round I believe. Maybe I can remove the processCustomAnnotation
and merge that into the processCustomAnnotationFromClassPath
but I think that might risk it becoming very messy? And I kinda don't know how to handle that we get preview name and such from the stored metadata and not from the supported compile option name thingy 🤔
Is this still planned in near future? Is any help needed? |
With this PR it should work for KSP. We had to do some changes for KAPT. I think I will have to make another PR because there is to much conflicts and we have to change the approach a bit after some of the changes that has been merged. I have not gotten around to it quite yet because of other things. If you want to help and check this out, you are more than welcome to :) |
Hi @oas004 , thanks for the work! My team’s work is dependent on this custom preview annotation in order to support Paparazzi screenshot testing. Can I ask if there are estimated timeline on having this released (only KSP is already great to us)? I’d love to help if I can do anything but I’m really new to annotation processing programming so maybe guides are needed |
Hey @anhanh11001. Sorry for blocking you. Had a bit to much on my plate at work, so this has been a bit down prioritised. I will try my best to get some work in on this this week. Since we have released #255, it should at least not throw at compile time, it will just be bypassed from Showkase point of view. I think the stuff in this PR should be enough for it to work with KSP at least. It has to be changed along with this #284 |
Closing this in favour of #303 |
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
What do I mean by Custom MultiPreview 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.
Testing
Sample App
In the sample app I have introduced
Shapes
. This is to showkase different shapes in Showkase.Here I have made two internal (in same module) and one external (in submodule) annotations
Internals:
Eksternal
This is annotating different Composables in the
shapes
domain. Here is an overview of the Composables that are annotated.The
RoundRectanglePreview
here is also annotated with a singularPreview
annotation to check that the combination works. Since It is annotated with two annotations that has twopreview
annotations this should generate 2 + 2 + 1 previews in Showkase.Please check out the app with the
useKsp=true
and click on theshapes
tab to see the samples.Browser Test
For the UI tests I have currently made two custom annotations. One internal (same module) and one external(submodule)
Internal
External
These are annotating different Composables. Here I have tried to combine them as well with each other and with singular ones.
Added tests for the different cases and checked that they are generating individual Composables in their respective group.
This should be the same as what is generated in the Sample application just with different names.
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.What is left
This is very much still a work in progress. I have tried to list up what I have left under to get an overview.
- [ ] Add docs about how to support your custom preview annotations.- This should be done in a different PR that can be merged just before release so that it does not cause confusion.- [ ] Add processor testing submodule so that I can test that the annotation being in a different library module will generate a showkaseMetadata object.- Not possible because testing library does not support this