Skip to content

1.35.0

Compare
Choose a tag to compare
@takahirom takahirom released this 08 Dec 02:18
· 96 commits to main since this release
f282dcf

Add support for heightDp, widthDp, showBackground, and backgroundColor of Compose Preview parameters

We have introduced Experimental Compose Preview Support in 1.22.0, but it does not yet support all parameters of the @Preview annotation. Thanks to @sergio-sastre 's pull request, the Experimental Compose Preview Support now includes support for heightDp, widthDp, showBackground, and backgroundColor.

Introduce RoborazziComposeOptions

To accommodate the changes in preview parameters, we’ve made the API more flexible.

We’ve added the RoborazziComposeOptions parameter to ComposablePreview<AndroidPreviewInfo>.captureRoboImage() and the composable function version, captureRoboImage{}. Previously, the API was limited; for example, you couldn’t access the ActivityScenario or the composable function directly. Now, you have full control over these components. Thank you for your code review @sergio-sastre

Here’s an example of a custom option:

    captureRoboImage(
      roborazziComposeOptions = RoborazziComposeOptions {
        // We have several options to configure the test environment.
        fontScale(2f)
        // We can also configure the activity scenario and the composable content.
        addOption(
          object : RoborazziComposeComposableOption,
            RoborazziComposeActivityScenarioOption {
            override fun configureWithActivityScenario(scenario: ActivityScenario<out Activity>) {
              scenario.onActivity {
                it.window.decorView.setBackgroundColor(Color.BLUE)
              }
            }

            override fun configureWithComposable(content: @Composable () -> Unit): @Composable () -> Unit {
              return {
                Box(Modifier
                  .padding(10.dp)
                  .background(color = androidx.compose.ui.graphics.Color.Red)
                  .padding(10.dp)
                ) {
                  content()
                }
              }
            }
          }
        )
      },
    ) {
      Text("Hello Compose!")
    }

image

Breaking Change: fun ComposablePreview<AndroidPreviewInfo>.applyToRobolectricConfiguration() is now deprecated and marked as an error

As part of our updates to how composables are configured, the applyToRobolectricConfiguration() function is now deprecated and marked as an error. Instead, you can use one of the following alternatives:

  • previewInfo.toRoborazziComposeOptions().apply(scenario, composeContent)
  • ComposablePreview<AndroidPreviewInfo>.captureRoboImage(roborazziComposeOptions)

We believe this feature is not widely used, and the migration should be straightforward. However, if you encounter any issues, please don’t hesitate to reach out.

Breaking Change: Composable captureRoboImage{} Behavior Change

We intended to use a transparent background for the Compose captureRoboImage function, but it was not applied due to Robolectric's resource merging mechanism. We have fixed this behavior; however, this change will result in altered screenshots. You can now specify the background in the new RoborazziComposeOptions as we had previously.

@Test
fun captureComposeLambdaImage() {
    captureRoboImage(
        roborazziComposeOptions = RoborazziComposeOptions {
            background(
                showBackground = true
            )
        }
    ) {
        Text("Hello Compose!")
    }
}

What's Changed

  • [Not Library dependency Update] Update dependency androidx.compose.runtime:runtime to v1.7.5 by @renovate in #548
  • Add .gitignore by @takahirom in #578
  • Refactor Add support for heightDp, widthDp, showBackground, backgroundColor by @takahirom in #577
  • Add support for heightDp, widthDp, showBackground, backgroundColor by @sergio-sastre in #576
  • Rename Applier to Config by @takahirom in #579
  • Refactor naming by @takahirom in #582
  • Add Assertion for minus or zero fontScale by @takahirom in #584
  • Add a deprecated method of ComposablePreview.applyToRobolectricConfiguration() as it was a ExperimentalApi by @takahirom in #585
  • Adjustment for compose preview config by @takahirom in #586
  • Refactor RoborazziComposeConfigBuilder by @takahirom in #590

Full Changelog: 1.34.0...1.35.0