https://kotlinlang.org logo
Title
e

eygraber

02/13/2023, 5:04 AM
Is it possible to merge
Preview
annotations? For example, if I have a
annotation class FontScalePreviews
annotated with a bunch of different
@Preview
with
fontScale
set, and a
annotation class DensityScalePreviews
with a bunch of different
@Preview
with
device
set, can I create another annotation that merges those?
m

mattinger

02/13/2023, 5:18 AM
I tried this, and it seems like when it encounters that, it renders multiple previews. The Preview annotation is allowed to be specified multiple times, so that you can see a variety of different preview configurations of a single function. I'm not convinced there's a way to have it merge the attributes together. So while you can create a composite annotation, there's no way to mix and match. Each Preview annotation gets rendered on it's own
a

Alex Vanyo

02/13/2023, 5:38 PM
Yeah, the current behavior is that each underlying
@Preview
annotation will be rendered, and they won’t “cross-multiply” to apply combinations. That would be cool for `@Preview`s that have orthogonal parameters specified, but I’m not sure how you’d handle cases where multiply `@Preview`s specify the same conflicting parameter. You would probably just have to make a new multi-preview annotation with the manual merging.
e

eygraber

02/13/2023, 5:46 PM
I was imagining some way of specifying which parameters to merge. I was able to achieve this by just exploding the Preview annotations for every combination of font scale and density that I wanted, but there's a lot 😬