diff --git a/maps-compose/src/main/java/com/google/maps/android/compose/Marker.kt b/maps-compose/src/main/java/com/google/maps/android/compose/Marker.kt index 25ddab7e6..3617d286b 100644 --- a/maps-compose/src/main/java/com/google/maps/android/compose/Marker.kt +++ b/maps-compose/src/main/java/com/google/maps/android/compose/Marker.kt @@ -251,6 +251,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 @@ -272,6 +274,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 diff --git a/maps-compose/src/main/java/com/google/maps/android/compose/RememberComposeBitmapDescriptor.kt b/maps-compose/src/main/java/com/google/maps/android/compose/RememberComposeBitmapDescriptor.kt index 8946f1abf..b94e7cb12 100644 --- a/maps-compose/src/main/java/com/google/maps/android/compose/RememberComposeBitmapDescriptor.kt +++ b/maps-compose/src/main/java/com/google/maps/android/compose/RememberComposeBitmapDescriptor.kt @@ -30,6 +30,8 @@ internal fun rememberComposeBitmapDescriptor( } } +private val measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED) + private fun renderComposableToBitmapDescriptor( parent: ViewGroup, compositionContext: CompositionContext, @@ -39,6 +41,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) } @@ -46,10 +52,12 @@ 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), - ) + 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)