Search code examples
kotlinintellij-ideacompose-desktop

Compose Desktop preview with parameters


Is there any way to use Compose Desktop preview in Idea for functions that have parameters? It works for me with functions without parameters only. And it looks like neither @Preview annotation have any parameters nor there are @PreviewParameter annotation for desktop.


Solution

  • You can create a separate Composable function specifically for preview purposes that calls the Composable function you're interested in with arguments.

    Like

    @Preview
    @Composable
    fun MyComposablePreview() {
        MyTheme {
            MyComposable("arg1", "arg2")
        }
    }