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

Feature request: support for limit argument in PreviewParameter #386

Open
ln-12 opened this issue May 27, 2024 · 0 comments
Open

Feature request: support for limit argument in PreviewParameter #386

ln-12 opened this issue May 27, 2024 · 0 comments

Comments

@ln-12
Copy link

ln-12 commented May 27, 2024

I am using Showkase in combination with the PreviewParameterProvider class. With that, we can also pass in a limit argument so that only a certain amount of items from the sequence is used. The code looks something like this:

@Composable
@Preview
fun SomePreview(
    @PreviewParameter(SomePreviewParameterProvider::class, limit = 3)
    state: SomeState,
) {
    ...
}

class SomePreviewParameterProvider : PreviewParameterProvider<SomeState> {

        override val values = sequenceOf(
            SomeState(...),
            SomeState(...),
            SomeState(...),
            SomeState(...),
            SomeState(...),
        )

}

After Showkase generated the module, I get the following code which does not respect this parameter but instead simply uses all values:

public val SomePreviewDefaultGroupSomePreview: List<ShowkaseBrowserComponent> = 
    SomePreviewParameterProvider()
        .values
        .iterator()
        .asSequence()
        .mapIndexed { index, previewParam ->
                ShowkaseBrowserComponent(
                    group = "Default Group",
                    componentName = "SomePreview",
                    componentKDoc = "",
                    componentKey =
                        """com.example.app.SomePreview_null_DefaultGroup_SomePreview_0_null_$index""",
                    isDefaultStyle = false,
                    component = @Composable { SomePreview(state = previewParam) }
                )
        }
        .toList()

Would it be possible to add support for the limit argument?

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

No branches or pull requests

1 participant