-
Notifications
You must be signed in to change notification settings - Fork 42
Add automatic land/port qualifier when both widthDp and heightDp are set #711
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 automatic land/port qualifier when both widthDp and heightDp are set #711
Conversation
val currentHdp = (dm.heightPixels / dm.density).toInt() | ||
val w = if (widthDp > 0) widthDp else currentWdp | ||
val h = if (heightDp > 0) heightDp else currentHdp | ||
qualifiers.add(if (w > h) "land" else "port") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sergio-sastre!
I've implemented a workaround in this PR that automatically adds -land/-port qualifiers based on dimensions. This should handle the 2000x1000 case you mentioned.
Could you take a look and let me know if it addresses your use cases?
Thanks! 🙏
#711 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@takahirom
Sure! I’m just thinking it could intercept with the device
property of the previews, where one can also set the orientation… I’ll create an extra preview for that and see how it behaves 🧐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@takahirom
So I've tested it and when combined with device
, it does not work.
I've added the following previews:
@Preview(
name = "Preview width and height large pixel5",
device = "spec:parent=pixel_5",
widthDp = 2000,
heightDp = 1000,
)
@Composable
fun PreviewWithWidthAndHeightPixel5() {
Card(
Modifier.fillMaxSize()
) {
Text(
modifier = Modifier.padding(8.dp),
text = "Hello, World in portrait pixel 5"
)
}
}
@Preview(
name = "Preview width and height large in portrait",
device = "spec:parent=pixel_5,orientation=portrait",
widthDp = 2000,
heightDp = 1000,
)
@Composable
fun PreviewWithWidthAndHeightInportrait() {
Card(
Modifier.fillMaxSize()
) {
Text(
modifier = Modifier.padding(8.dp),
text = "Hello, World in portrait"
)
}
}
@Preview(
name = "Preview width and height large in landscape",
device = "spec:parent=pixel_5,orientation=landscape",
widthDp = 2000,
heightDp = 1000,
)
@Composable
fun PreviewWithWidthAndHeightInLandscape() {
Card(
Modifier.fillMaxSize()
) {
Text(
modifier = Modifier.padding(8.dp),
text = "Hello, World in Landscape!"
)
}
}
All these 3 Previews in Android studio differ by a lot from the screenshots generated by Roborazzi. Moreover, the image sizes are 1078dp x 2337dp. There is no factor that makes 1000 -> 1078 and 2000-> 2337...
So it's like sth looks fishy... but I'm unsure if it has to do with width
and height
or with device
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I also put these previews in the 1.45.1 branch and they look fine, exactly like in the Previews in Android Studio. This means, this approach with the setQualifiers
does not fully work...
I am starting to think that the shadowDisplay
approach is the only valid one...
I'd gladly add these Previews to confirm we do not have regressions in the future once we fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, let's add the previews you provided. I can commit them directly, or if you prefer, you can open a PR against this branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to do it. I think our best bet is to add them, record the screenshots in version 1.45.1 since they look right, and then whenever we make changes for the size option, check what breaks.
I can help you from Wednesday evening on, today I’ll not be able to find some time for this 🙏
Let’s make this work reliably 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I've introduced them. I've changed the order of the Qualifiers. While it's not ideal because it relies on Robolectric's implementation, it does the job.
606a1cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! I've also tested it locally, I think this is ready!! :)
Thanks for fixing it!
…th-widthdp-and-heightdp-are-set/2025-06-30
No description provided.