Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor RoborazziComposeConfigBuilder #590

Merged
merged 1 commit into from
Dec 8, 2024

Conversation

takahirom
Copy link
Owner

No description provided.

@takahirom
Copy link
Owner Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@takahirom takahirom marked this pull request as ready for review December 5, 2024 09:20
@takahirom takahirom force-pushed the 12-05-refactor_roborazzicomposeconfigbuilder branch 2 times, most recently from 19832ae to 31ac20b Compare December 5, 2024 09:37
@takahirom
Copy link
Owner Author

takahirom commented Dec 5, 2024

The release note will be like this.


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.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.applyToRobolectricConfiguration()

As part of our changes to how composables are set up, the applyToRobolectricConfiguration() function is now deprecated and error. Instead, you can use the following:

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

We believe this migration can be done smoothly. However, if you encounter any issues, please don’t hesitate to reach out.

What's Changed

Full Changelog: 1.34.0...1.35.0

@takahirom takahirom force-pushed the 12-05-refactor_roborazzicomposeconfigbuilder branch from 31ac20b to c212768 Compare December 5, 2024 10:13
@@ -13,49 +13,52 @@ import sergio.sastre.composable.preview.scanner.core.preview.ComposablePreview
fun ComposablePreview<AndroidPreviewInfo>.captureRoboImage(
filePath: String,
roborazziOptions: RoborazziOptions = provideRoborazziContext().options,
configBuilder: RoborazziComposeConfigBuilder = this.toRoborazziComposeConfigBuilder()
roborazziComposeOptions: RoborazziComposeOptions = this.toRoborazziComposeOptions()
Copy link
Owner Author

@takahirom takahirom Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergio-sastre
Thank you for reviewing PRs. I was almost ready to release this, but while writing the release notes, I realized it might be a bit strange to pass a builder to the APIs. Additionally, the names RoborazziComposeConfig and RoborazziComposeConfigBuilder felt odd because RoborazziComposeConfig is not actually created by RoborazziComposeConfigBuilder.

I also think we don’t have a strong preference for using Config over Options, especially since we’re already using RoborazziOptions. Therefore, I renamed it to RoborazziComposeOptions.

I made some adjustments. Could you take a look?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergio-sastre This is going to block other tasks, so I'll merge this now. If you have any concerns, let me know. I think we can address them in a patch release.

@takahirom takahirom force-pushed the 12-05-refactor_roborazzicomposeconfigbuilder branch 3 times, most recently from 7e2ac43 to d451213 Compare December 5, 2024 10:51
Copy link

github-actions bot commented Dec 5, 2024

Snapshot diff report

File name Image
manual_compose_with_
compose_options_comp
are.png

@takahirom takahirom force-pushed the 12-05-refactor_roborazzicomposeconfigbuilder branch from d451213 to 7a4511d Compare December 6, 2024 03:45
@takahirom takahirom merged commit f282dcf into main Dec 8, 2024
7 checks passed
@takahirom takahirom deleted the 12-05-refactor_roborazzicomposeconfigbuilder branch December 8, 2024 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant