Is there any way to mark a composable so that it c...
# compose
e
Is there any way to mark a composable so that it can only be used from a preview?
z
I don't think there is anything to do it in compile time. You could have a common preview function that checks LocalInspectionMode and throws an error if it's not being used in a preview
t
Maybe you could create you own annotation. Than you have to optin when you use it. At least the other developers see a warning when using it. But it will not automatically allow this for previews.
Copy code
@RequiresOptIn(message = "Only use this in previews please!")
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.FUNCTION)
annotation class PreviewComposable

@Composable
@PreviewComposable
private fun Preview1() {
    Box() {

    }
}