Wrap composables with a CompositionLocalProvider to set LocalInspectionMode to true #1017
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This addresses issue #709 where the
GoogleMap
s composable would crash when taking a snapshot. This was happening because theGoogleMap
s 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 aCompositionLocalProvider
which setsLocalInspectionMode
totrue
. This is done in theComposeViewAdpater
. 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 paparazziComposeViewAdapter
when snapshot is called, we do the wrapping outside before theComposeView
is added to theComposeViewAdapter
. 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)