Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ public fun Marker(
/**
* Composable rendering the content passed as a marker.
*
* This composable must have a non-zero size in both dimensions
*
* @param keys unique keys representing the state of this Marker. Any changes to one of the key will
* trigger a rendering of the content composable and thus the rendering of an updated marker.
* @param state the [MarkerState] to be used to control or observe the marker
Expand All @@ -221,6 +223,9 @@ public fun Marker(
* @param onInfoWindowClose a lambda invoked when the marker's info window is closed
* @param onInfoWindowLongClick a lambda invoked when the marker's info window is long clicked
* @param content composable lambda expression used to customize the marker's content
*
* @throws IllegalStateException if the composable is measured to have a size of zero in either
* dimension
*/
@Composable
@GoogleMapComposable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ internal fun rememberComposeBitmapDescriptor(
}
}

private val measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)

private fun renderComposableToBitmapDescriptor(
parent: ViewGroup,
compositionContext: CompositionContext,
Expand All @@ -39,17 +41,23 @@ private fun renderComposableToBitmapDescriptor(
val composeView =
ComposeView(parent.context)
.apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
)
setParentCompositionContext(compositionContext)
setContent(content)
}
.also(parent::addView)

composeView.draw(fakeCanvas)

composeView.measure(
View.MeasureSpec.makeMeasureSpec(parent.width, View.MeasureSpec.AT_MOST),
View.MeasureSpec.makeMeasureSpec(parent.height, View.MeasureSpec.AT_MOST),
)
composeView.measure(measureSpec, measureSpec)

if (composeView.measuredWidth == 0 || composeView.measuredHeight == 0) {
throw IllegalStateException("The ComposeView was measured to have a width or height of " +
"zero. Make sure that the content has a non-zero size.")
}

composeView.layout(0, 0, composeView.measuredWidth, composeView.measuredHeight)

Expand Down