How do people handle full screen `@Preview`s? I ha...
# compose
m
How do people handle full screen `@Preview`s? I have seen opinions previews should only be used for individual composables, not screens, but I also think the XML layout previews were useful and I would like a preview of an entire screen.
1
I have a screen that contains a composable that cannot run in a preview. In the View world I would use
isInEditMode()
in it to correctly handle that, but with Compose it just prevents my entire screen from being previewable?
a
Why can’t it run in preview?
You can try
LocalInspectionMode.current
which is similar to that Edit Mode
m
Why can’t it run in preview?
It's a map view (think Google Maps), there would need to be a lot of mocking just for it to display nothing in the end. I'd rather just not display it.
👍 1
You can try 
LocalInspectionMode.current
  which is similar to that Edit Mode
I haven't seen that, thanks!
a
Preview is nice, but don’t you want to test your Screen as well? How about refactoring that map subcomponent into a Slot, you can test the rest.
👍 2
c
I’m not sure if MapView is supported in Compose preview - @nosuid can comment
But as far as previewing a “screen”, it’s really a Composable with a device set in the Preview parameters, e.g. Pixel3
You can also change height and width of the Preview with individual parameters
m
The map Composable I am using is from a third party library, not from Google.
c
What errors are you getting from the Preview?
m
No errors, my question was just about the problem of having a Composable that has complex dependencies, that would require a lot of code in the @Preview function to stub in a way where it wouldn't crash.
LocalInspectionMode.current
solves this because I can disable the Composable to prevent it from crashing. In this case the Composable takes a function that produces an
InputStream
for a map tile that it then draws. Unless I can produce `InputStream`s in the @Preview function that can be read as valid PNG's the Composable won't work.
🆗 1