Skip to content

Releases: sergio-sastre/ComposablePreviewScanner

0.5.1

12 Feb 16:14
12dd2f6
Compare
Choose a tag to compare

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

0.5.0

12 Jan 13:44
ff65503
Compare
Choose a tag to compare

NEW: Scanning Previews in different Source Sets
Add support to scan @Previews located in sourceSets different from 'main', like 'screenshotTest' or 'androidTest'

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

30 Oct 20:41
149ceaf
Compare
Choose a tag to compare

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

30 Sep 00:44
77d6c4b
Compare
Choose a tag to compare

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

29 Sep 10:44
c25ea29
Compare
Choose a tag to compare
  • Fix #27
  • Improve speed of Finding Composables by avoiding unnecessary class loading

Warning

This build broke some functionality that was fixed in the next version 0.3.2

0.3.0

17 Aug 21:59
31159e9
Compare
Choose a tag to compare

What's new

✅ Exclude subpackages inside a package when scanning @𝘗𝘳𝘦𝘷𝘪𝘦𝘸𝘴 -> #24
✅ Scan @𝘗𝘳𝘦𝘷𝘪𝘦𝘸𝘴 inside public classes -> #4

0.2.0

02 Aug 21:29
9811d74
Compare
Choose a tag to compare

Initial Compose Multiplatform support!

  • Support @Previews in common
  • Compose-Desktop @Previews cannot be directly supported for now due to this issue. However, you can extra annotate Compose-Desktop Composables and use JvmAnnotationScanner to get them. See README.md

Adressed issues:

0.1.3

12 Jul 23:26
949c875
Compare
Choose a tag to compare

This release resolves issues #14 & #15:

  • Add support for private @ Previews via .includePrivatePreviews()
  • Decrease required minSdk from 23 to 21, since many Android TVs still run on SDK 21

0.1.2

18 Jun 15:43
01fa383
Compare
Choose a tag to compare

Improvements in the AndroidPreviewScreenshotIdBuilder:

  • Fix issues with "device" and "uiMode" #9
  • Let ignore className and methodName to avoid duplication in Paparazzi Tests #8

0.1.1

12 Jun 16:21
3f7424c
Compare
Choose a tag to compare
  1. Fixes bug #1 - No such method error, so you can now use ComposablePreviewScanner in Android projects
  2. Compose-Desktop support requires you to copy the :core and :jvm folders into your project as a workaround, as described in #3