Skip to content

Respect @Preview size settings in NavGraph thumbnails #13

Description

@chandroidx

Is your feature request related to a problem?
Currently, NavGraph thumbnails appear to be rendered with a fixed phone-sized portrait canvas, regardless of the size configuration defined on the user's @Preview annotation.

For example, even when a preview is configured as landscape:

@Preview(
  widthDp = 1280,
  heightDp = 800,
)
@NavPreview(route = SomeRoute::class, primary = true)
@Composable
fun SomeScreenLandscapePreview() {
  SomeScreen()
}

the generated NavGraph thumbnail is still rendered as a portrait image.

From what I observed, the Layoutlib renderer seems to pass a fixed device spec such as spec:width=411dp,height=891dp,dpi=420, and the Robolectric renderer also seems to use a fixed qualifier like w411dp-h891dp-xhdpi. Because of this, @Preview values such as widthDp, heightDp, and device do not affect the generated thumbnail.

Also, the default functionality of the plugin distributed through JetBrains Marketplace did not appear to apply the selected device in the NavGraph Graph tool window. For example, selecting a Tablet Device still seemed to render or display the previews as the fixed portrait phone layout.

Describe the solution you'd like:
It would be great if NavGraph could respect the size-related configuration from the user's @Preview annotation when rendering thumbnails.

Ideally, values such as the following would be reflected in the generated NavGraph thumbnail:

widthDp
heightDp
device
possibly other preview configuration values if applicable
This would allow users to provide representative landscape, tablet, foldable, or custom-sized previews and have the NavGraph render match what Android Studio Preview shows.

Describe alternatives you've considered:
I tried marking a landscape preview as the primary @NavPreview, but only the selected preview function changed. The rendered thumbnail size still remained portrait.
I also tried replacing a custom preview annotation with a direct @Preview(widthDp = ..., heightDp = ...) or @Preview(device = ...), but the generated thumbnail still used the fixed portrait canvas.
A possible workaround is to use -Pnavgraph.export.device=WxH when exporting the final graph, but this only changes the exported graph frame/letterboxing behavior. It does not make each thumbnail respect its own @Preview configuration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions