Skip to content

Commit

Permalink
fix: Don't throw IllegalArgumentException when parent of marker compo…
Browse files Browse the repository at this point in the history
…sable is zero sized
  • Loading branch information
ln-12 committed May 17, 2024
1 parent d5533b4 commit 62c313d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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 @@ -39,6 +39,10 @@ private fun renderComposableToBitmapDescriptor(
val composeView =
ComposeView(parent.context)
.apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
)
setParentCompositionContext(compositionContext)
setContent(content)
}
Expand All @@ -47,10 +51,15 @@ private fun renderComposableToBitmapDescriptor(
composeView.draw(fakeCanvas)

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

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

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

val bitmap =
Expand Down

0 comments on commit 62c313d

Please sign in to comment.