Releases: sergio-sastre/ComposablePreviewScanner
0.5.1
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:
- 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
- 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
0.5.0
NEW: Scanning Previews in different Source Sets
Add support to scan @Preview
s located in sourceSets different from 'main', like 'screenshotTest' or 'androidTest'
- Closes #32
AndroidComposablePreviewScanner()
// optional to scan previews in compiled classes of other source sets, like "screenshotTest" or "androidTest"
// if omitted, it scans previews in Main at build time
.setTargetSourceSet(
Classpath(SourceSet.SCREENSHOT_TEST) // scan previews under "screenshotTest"
)
.scanPackageTrees("your.package")
...
.getPreviews()
0.4.0
NEW! Parsing Preview Device String
This version provides DevicePreviewInfoParser.parse(device: String)
which returns a Device
object containing all the necessary information to support different devices in your Roborazzi & Paparazzi screenshot tests!
It can parse ALL possible combinations of "device strings" up to Android Studio Lady Bug, namely:
// The over 80 devices supported either by id and/or name, for instance:
@Preview(device = "id:pixel_9_pro")
@Preview(device = "name:Pixel 9 Pro")
@Preview(device = "spec:parent=pixel_9_pro, orientation=landscape, navigation=buttons")
// And custom devices
@Preview(device = "spec:width = 411dp, height = 891dp, orientation = landscape, dpi = 420, isRound = false, chinSize = 0dp, cutout = corner")
@Preview(device = "spec:id=reference_desktop,shape=Normal,width=1920,height=1080,unit=px,dpi=160") // in pixels
@Preview(device = "spec:id=reference_desktop,shape=Normal,width=1920,height=1080,unit=dp,dpi=160") // in dp
...
If you are using Roborazzi, you can streamline the process by just calling
RobolectricDeviceQualifierBuilder.build(preview.previewInfo)?.run {
RuntimeEnvironment.setQualifiers(this)
}
before setting any other Robolectric 'cumulative qualifier' in your tests.
For further info on how to use them, see Roborazzi and Paparazzi sections in the README.md respectively.
Breaking Change
AndroidScreenshotIdBuilder
also uses the new DevicePreviewInfoParser.parse(device: String)
and therefore the screenshot file names might change when updating
0.3.2
Fix bugs introduced in 0.3.1
- scanAllPackages() working again
- some speed gain when finding Previews (alleged in 0.3.1)
Note
This build fixes issues introduced in 0.3.1, while also addressing 0.3.1 claims
0.3.1
0.3.0
0.2.0
Initial Compose Multiplatform support!
- Support
@Preview
s in common - Compose-Desktop
@Preview
s cannot be directly supported for now due to this issue. However, you can extra annotate Compose-Desktop Composables and useJvmAnnotationScanner
to get them. See README.md
Adressed issues: