You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add documentation regarding Custom preview annotation usage
Her I have added documentation for using Custom preview annotation with Showkase. I have added use cases and KSP vs KAPT differences. Also added docs
about how to use this with KAPT.
* Moved this documentation to an alternate section README.md
---------
Co-authored-by: Vinay Gaba <vinaygaba@gmail.com>
Copy file name to clipboardExpand all lines: README.md
+74Lines changed: 74 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -386,6 +386,80 @@ val typography = metadata.typographyList
386
386
387
387
```
388
388
389
+
##### 6. Custom/Multipreview Annotations
390
+
You can use custom preview annotations for Showkase as well. Custom preview annotations are annotations that are annotated with preview it self.
391
+
An example of this can be:
392
+
393
+
```kt
394
+
@Preview(name ="Custom Preview One First", group ="Custom Previews")
395
+
@Preview(name ="Custom Preview One Second", group ="Custom Previews")
396
+
annotationclassCustomPreview1
397
+
```
398
+
399
+
```kt
400
+
@Preview(name ="Custom Preview One First", group ="Custom Previews")
401
+
annotationclassCustomPreview2
402
+
```
403
+
404
+
this can be used to annotate a composable function like you would do any other preview function in Compose like this:
405
+
406
+
```kt
407
+
@CustomPreview1
408
+
@Composable
409
+
funCustomAnnotationPreview() {
410
+
}
411
+
```
412
+
413
+
This can also be combined like this:
414
+
415
+
```kt
416
+
@Preview(name ="Custom Preview One First", group ="Custom Previews")
417
+
@Preview(name ="Custom Preview One Second", group ="Custom Previews")
418
+
annotationclassCustomPreviewOne
419
+
420
+
421
+
@Preview(name ="Custom Preview Two First", group ="Custom Previews")
422
+
annotationclassCustomPreviewTwo
423
+
424
+
@CustomPreviewOne
425
+
@CustomPreviewTwo
426
+
@Composable
427
+
funCustomAnnotationPreviewCombined() {
428
+
}
429
+
```
430
+
431
+
###### KAPT vs KSP
432
+
433
+
Because of [this issue](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:
434
+
435
+
```kt
436
+
@Preview(name ="Shape 100 by 100", group ="Shapes", widthDp =100, heightDp =100)
437
+
@Preview(name ="Shape 150 by 150", group ="Shapes", widthDp =150, heightDp =150)
438
+
annotationclassCustomShape
439
+
```
440
+
441
+
This will be skipped by KAPT, but KSP will pick it up. However, if you have an annotation like:
442
+
443
+
```kt
444
+
@Preview(name ="Shape 100 by 100", group ="Shapes", widthDp =100, heightDp =100)
445
+
annotationclassCustomShape
446
+
```
447
+
It will be picked up by both KSP and KAPT.
448
+
449
+
###### Important for KAPT users
450
+
451
+
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:
0 commit comments