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

Add support for heightDp, widthDp, showBackground, backgroundColor #576

Conversation

sergio-sastre
Copy link
Contributor

This addresses #559

Still very open for discussion

ComponentActivity::class.java.name,
)
)
} catch (e: ClassNotFoundException) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious about this.

You are directly calling both robolectric and ComponentActivity. Wouldn't it fail with an error (NoClassDefFoundError , or similar) rather than a ClassNotFoundException? I normally assume ClassNotFoundException is for reflection usage with a checked exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree and haven’t realised that since I copy pasted it from the analogue method in RoborazziCompose.kt file.

worth checking 👍

@sergio-sastre sergio-sastre marked this pull request as ready for review November 26, 2024 16:55
Copy link
Contributor Author

@sergio-sastre sergio-sastre left a comment

Choose a reason for hiding this comment

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

@takahirom
Feel free to review in detail. It's likely you'd like to do something differently to allow users of the api to set the background and dimensions via the PreviewTester?

roborazzi/src/main/AndroidManifest.xml Outdated Show resolved Hide resolved
captureRoboImage(
filePath = filePath,
roborazziOptions = roborazziOptions,
content = { activityScenario ->
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it was practical to add such a captureRoboImage method to allow users to set properties through the activityScenario. Open to other opinions

Copy link
Owner

@takahirom takahirom Nov 28, 2024

Choose a reason for hiding this comment

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

Thank you. Designing these APIs is a bit challenging. I'm giving a talk at a technology conference this Saturday, so I'm a little busy at the moment. I apologize for the delay, but I’d like to take some time over the weekend to consider this. I’ll get back to you soon.

@sergio-sastre
Copy link
Contributor Author

I’m a bit unsure why the builds fail?

@takahirom
Copy link
Owner

I noticed that there was a shadow at the top in the comparison images, but it has now been removed. It looks great! I’ll review the changes tomorrow.

import org.robolectric.shadows.ShadowDisplay.getDefaultDisplay
import kotlin.math.roundToInt

fun ActivityScenario<out Activity>.setBackgroundColor(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These 2 Methods together with the captureRoboImageWithActivityScenarioSetup() would allow Roborazzi users to set the background and size of their Composables under tests also for non-preview tests.

maybe worth documenting a bit more about these options to arise awareness?

val activityScenario = ActivityScenario.launch(RoborazziTransparentActivity::class.java)

activityScenario.use {
val sizedPreview = content(activityScenario)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

better to name it "preview" instead of "sizedPreview". That is a leftover of the clean up...

widthDp: Int,
heightDp: Int
) {
if (widthDp <= 0 && heightDp <= 0) return
Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe desirable to log a warning or debug message if it returns here?

}

@Preview(
name = "Preview width & height",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Preview width & height small"?

@takahirom
Copy link
Owner

takahirom commented Dec 1, 2024

@sergio-sastre
Thank you for your patience while waiting. This might be over-engineering, but I made a change to make it pluggable. With this change, we can provide the same flexibility to captureRoboImage(composable) as the Preview functionality, without needing captureRoboImageWithActivityScenarioSetup(). Could you take a look?
https://github.com/sergio-sastre/roborazzi/compare/feature/support_previews_heightDp_widthDp_showBackgorund_backgroundColor...takahirom:roborazzi:takahirom/refactor-plugable/2024-12-01?diff=split&w=

@sergio-sastre
Copy link
Contributor Author

@sergio-sastre Thank you for your patience while waiting. This might be over-engineering, but I made a change to make it pluggable. With this change, we can provide the same flexibility to captureRoboImage(composable) as the Preview functionality, without needing captureRoboImageWithActivityScenarioSetup(). Could you take a look? https://github.com/sergio-sastre/roborazzi/compare/feature/support_previews_heightDp_widthDp_showBackgorund_backgroundColor...takahirom:roborazzi:takahirom/refactor-plugable/2024-12-01?diff=split&w=

I’ll do it either today or tomorrow when I find time😊

@takahirom takahirom merged commit a10f240 into takahirom:main Dec 5, 2024
7 checks passed
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.

3 participants