airbnb / Showkase

🔦 Showkase is an annotation-processor based Android library that helps you organize, discover, search and visualize Jetpack Compose UI elements
https://medium.com/airbnb-engineering/introducing-showkase-a-library-to-organize-discover-and-visualize-your-jetpack-compose-elements-d5c34ef01095
Apache License 2.0
2.11k stars 107 forks source link

Multi-modules project : how to avoid public visibility for @Preview? #271

Closed borsini closed 1 year ago

borsini commented 1 year ago

The documentation states that

The root module is the main module of your app that has a dependency on all other modules in the app. This is relevant because we generate the Showkase related classes in the package of the root module and we need to be able to access the UI elements across all the sub modules. This is only possible from the root module as it typically has a dependency on all the sub-modules.

Many thanks!

iamutkarshtiwari commented 1 year ago

HI @borsini, thanks for raising this! I mentioned something similar couple of days back.

To work this around I did two things:

@RequiresOptIn(
    level = RequiresOptIn.Level.WARNING,
    message = "This is internal preview for EGDS snapshot tests, please don't use it."
)
annotation class InternalEGDSPreview

and annotated all my public previews with it:

@InternalEGDSPreview
@Preview
@Composable
fun PreviewIconButton() { ... }

This deters consumers from using Preview methods because now they have to explicitly optin to be able to use them on their side.

borsini commented 1 year ago

Thanks @iamutkarshtiwari , that would be an alternative. We ended up excluding our Previews from the IDE autocompletion-list.

Regarding my first question, does anyone have a clue? maybe @vinaygaba ? Having multiple ShowkaseRoot would help isolate previews and keep them internal

Does it mean that we can only have one @ShowkaseRootModule per project?

elcolto commented 1 year ago

Also looking for a solution for this problem.

Would it be possible to add a configuration option to opt-out from auto including @Preview annotation from ShowkaseModule? To just include @ShowkaseComposable(skip = false) annotated functions?

vinaygaba commented 1 year ago

A recent change that I made now enables creating previews that are internal instead of public. It's part of the 1.0.0-beta17 release. I think this should fix the problem that you originally raised. What do you think @borsini?

vinaygaba commented 1 year ago

Does it mean that we can only have one @ShowkaseRootModule per project?

ShowkaseRootModule are essentially meant to represent a collection previews based on the dependencies of the module where its declared. So in theory, it's possible to have multiple ShowkaseRootModule in a project. However, for the purpose of the original issue, I don't think we will need this anymore as Showkase now supports internal previews and it doesn't force your previews to be public.

vinaygaba commented 1 year ago

Going to close this as the 1.0.0-beta17 release fixes this issue 🥳