Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap composables with a CompositionLocalProvider to set LocalInspectionMode to true #1017

Conversation

adamalyyan
Copy link
Collaborator

This addresses issue #709 where the GoogleMaps composable would crash when taking a snapshot. This was happening because the GoogleMaps composable was trying to initialize as it would when placed in an app. This doesn't happen in Android Studio's preview mode since the composable is wrapped with a CompositionLocalProvider which sets LocalInspectionMode to true. This is done in the ComposeViewAdpater. To mimic this behavior, before we set the composable to be snapshot on the ComposeView, we wrap it the same way the ComposeViewAdapter does.

The ComposeViewAdapter used by Preview does internally, but since we don't have a reference to the paparazzi ComposeViewAdapter when snapshot is called, we do the wrapping outside before the ComposeView is added to the ComposeViewAdapter. The end result and layout tree is identical, it just happens at slightly different times in Paparazzi vs Android Studio (both happen before any preview/snapshot is generated)

@jrodbx
Copy link
Collaborator

jrodbx commented Jul 27, 2023

This doesn't happen in Android Studio's preview mode since the composable is wrapped with a CompositionLocalProvider which sets LocalInspectionMode to true

IIUC, this is similar to View.isInEditMode where Preview sets this to true, but Paparazzi deliberately sets to true, to run production code paths. The original issue shows a NPE with respect to some missing "metadata" field; would it be possible to figure out how to resolve the NPE and see how much further along the execution flow would go?

@adamalyyan adamalyyan closed this Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants