Open takahirom opened 3 months ago
This would be for default options right? For options applying to a single Preview, I’d bet the best is to provide a @ RoborazziConfig annotation with params matching the options -and annotate your @ Previews with it.
then you can get that info via
AndroidComposablePreviewScanner()
…
.includeAnnotationInfoForAllOf(RoborazziConfig::class.java)
and map them in the tests with
ComposablePreview<AndroidPreview>.getAnnotation<RoborazziConfig>()
You can find some examples here:
Thanks! I believe we have two main use cases for this:
(In Roborazzi)
annotation class RoborazziConfig(xxxx)
class AndroidComposePreviewTester : ComposePreviewTester<AndroidPreviewInfo> {
// This will be a new method of ComposePreviewTester
override fun roborazziOptions(): RoborazziOptions {
// How to access the composablePreview here?
// options().composablePreview or passing as a parameter
val someOptions = composablePreview.getAnnotation<RoborazziConfig>().xxxx
return RoborazziOptions(xxx)
}
override fun test(composablePreview) {
val roborazziOptions = roborazziOptions()
...
}
}
https://github.com/takahirom/roborazzi/blob/main/roborazzi-compose-preview-scanner-support/src/main/java/com/github/takahirom/roborazzi/RoborazziPreviewScannerSupport.kt#L85C1-L85C34 (The current implementation of AndroidComposePreviewTester)
(In user project)
class MyCustomComposePreviewTester : ComposePreviewTester<AndroidPreviewInfo> by AndroidComposePreviewTester() {
override fun roborazziOptions(): RoborazziOptions {
// How to access the composablePreview here?
// options().composablePreview or passing as a parameter
val someOptions = composablePreview.getAnnotation<UserCustomConfig>().xxxx
return RoborazziOptions(xxx)
}
}
I think we need to consider adding a new roborazziOptions()
method to the tester interface and determine how we can pass composablePreview to roborazziOptions()
, or explore other approaches.
So for me there are 3 use cases then:
I'd focus first on providing options 1 & 2 3rd is definitely harder to maintain and for more advanced users. I'd rather add it later, if ever.
My suggestion is to create a
roborazziOptions(): RoborazziOptions
function in the tester interface to set up the RoborazziOptions. However, we might want to access the annotations of the Preview function within roborazziOptions(). We could pass a ComposablePreview instance as a parameter, but I'm unsure if there's a more efficient approach.