https://kotlinlang.org logo
#compose
Title
# compose
m

Marcin Wisniowski

12/02/2021, 6:06 PM
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

allan.conda

12/02/2021, 6:12 PM
Why can’t it run in preview?
You can try
LocalInspectionMode.current
which is similar to that Edit Mode
m

Marcin Wisniowski

12/02/2021, 6:22 PM
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

allan.conda

12/02/2021, 6:33 PM
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

Chris Sinco [G]

12/02/2021, 7:52 PM
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

Marcin Wisniowski

12/03/2021, 6:39 AM
The map Composable I am using is from a third party library, not from Google.
c

Chris Sinco [G]

12/03/2021, 7:26 AM
What errors are you getting from the Preview?
m

Marcin Wisniowski

12/03/2021, 7:40 AM
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
4 Views