Reputation: 3748
What is the recommended safety measure to prevent @Preview
composables from reaching release? This question answered by using proguard but what if:
Can / should I move the preview into /debug
sources? Are there other safety mechanisms?
Upvotes: 2
Views: 1922
Reputation: 36
You can mark Preview functions with annotation @RestrictTo(RestrictTo.Scope.TESTS)
so no one could use your function even within the actual code. The same you could do with the Preview-data variables to prevent access in production code.
Upvotes: 2
Reputation: 2706
One of the thing you can do is make your preview composable as a private function.
So, now you will have two functions, one is the actual composable, which you can use in your codebase. And, one is the preview composable, which will be private.
By keeping this preview as private, no one can be able to access your Preview composable, this way you can prevent the misuse.
Also, since there is no one referring to this private function, proguard can mark this function as unused
and remove it.
Upvotes: 2