Is this possible to check if a function has been run in preview mode in Jetpack compose? I have a function that returns a proper string to use in the app but this function uses some objects which disable preview mode for @Composable components. What I could do is to pass val isPreview: Boolean = false flag to every component and then run a simplified function if the flag is true but this adds some boilerplate code to every composable.
I usually do this by calling LocalInspectionMode.current to know if I'm in preview mode. It returns true if in preview mode.
Here's what the documentation says about LocalInspectionMode:
Inspectable mode CompositionLocal. True if the composition is composed inside an Inspectable component.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With