Skip to content

0.5.1

Latest
Compare
Choose a tag to compare
@sergio-sastre sergio-sastre released this 12 Feb 16:14
12dd2f6

Support XR devices

  • #44 Previews with XR devices are now supported!
    @Preview(device = “spec:parent=xr_device")

Bug fixes

This release includes mainly bug fixes, namely:

Furthermore, it now throws RepeatableAnnotationNotSupportedException if repeatable annotations are used inside .excludeIfAnnotatedWithAnyOf() or includeAnnotationInfoForAllOf(), since they are not supported for now

A small summary of the 2 main bug fixes:

#47 Previews with default parameters

It is indeed possible to have previews with default parameters (I did not know about that, and I doubt many people know about that too).
So previews like the following, would throw exceptions before ComposablePreviewScanner 0.5.1, since it could not handle default parameters:

@Preview
@Composable
fun PreviewWithDefaultParams(
   arg0: Map<String, String> = mapOf("arg0" to "map"),
   arg1: String? = "arg1",
   arg2: String = "arg2",
   arg3: String = "arg3"
) {
   Text("${arg0.keys.first()} $arg1 $arg2 $arg3")
}

#41 Previews with same names inside the same file, but different arguments

Example

// Previews with the same name, different Signature (i.e. argument types)
@Preview
@Composable
fun ExampleSamePreviewName(
   // assume the ListProvider contains only one value
    @PreviewParameter(provider = StringProvider::class) name: String
){
    Example(name)
}

@Preview
@Composable
fun ExampleSamePreviewName(
   // assume the ListProvider contains only one value
    @PreviewParameter(provider = ListProvider::class) name: List<Int>
){
    Example(name.joinToString("."))
}

In such rare cases:

  1. The second preview was never rendered, since ComposablePreviewScanner was always taking the first preview matching the class and method names. This is fixed in 0.5.1
  2. Both previews would also generate the same Screenshot File name, since the class and method names are the same:
    MyClassName.ExampleSamePreviewName0

This means, the files are overriden, resulting in only one file instead of 2.
In order to generate different Screenshot file names for each preview, you need to use doNotIgnoreMethodParametersType() from 0.5.1 as follows:

val name = AndroidPreviewScreenshotIdBuilder(preview)
   // other options
   .doNotIgnoreMethodParametersType()
   .build()

which generates the following screenshot file names:
MyClassName.ExampleSamePreviewName_String0
MyClassName.ExampleSamePreviewName_List<Int>0

Since this is a special and rare case, methodParametersType is ignored by default to keep file names shorter