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

fix: null pointer exception in ClusterRenderer when continuously updating cluster item values #623

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 2 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 @@ -168,26 +168,35 @@ internal class ComposeUiClusterRenderer<T : ClusterItem>(
}
}

private fun renderViewToBitmapDescriptor(view: AbstractComposeView): BitmapDescriptor {
private fun renderViewToBitmapDescriptor(view: AbstractComposeView?): BitmapDescriptor {
mohammad-firmansyah marked this conversation as resolved.
Show resolved Hide resolved
/* AndroidComposeView triggers LayoutNode's layout phase in the View draw phase,
so trigger a draw to an empty canvas to force that */
view.draw(fakeCanvas)
val viewParent = (view.parent as ViewGroup)
view.measure(
View.MeasureSpec.makeMeasureSpec(viewParent.width, View.MeasureSpec.AT_MOST),
View.MeasureSpec.makeMeasureSpec(viewParent.height, View.MeasureSpec.AT_MOST),
)
view.layout(0, 0, view.measuredWidth, view.measuredHeight)
val bitmap = Bitmap.createBitmap(
view.measuredWidth.takeIf { it > 0 } ?: 1,
view.measuredHeight.takeIf { it > 0 } ?: 1,
Bitmap.Config.ARGB_8888
)
bitmap.applyCanvas {
view.draw(this)
view?.draw(fakeCanvas)
if (view?.parent != null) {
val viewParent = (view.parent as ViewGroup)

view.measure(
View.MeasureSpec.makeMeasureSpec(viewParent.width, View.MeasureSpec.AT_MOST),
View.MeasureSpec.makeMeasureSpec(viewParent.height, View.MeasureSpec.AT_MOST),
)
view.layout(0, 0, view.measuredWidth, view.measuredHeight)
val bitmap = Bitmap.createBitmap(
view.measuredWidth.takeIf { it > 0 } ?: 1,
view.measuredHeight.takeIf { it > 0 } ?: 1,
Bitmap.Config.ARGB_8888
)
bitmap.applyCanvas {
view.draw(this)
}
return BitmapDescriptorFactory.fromBitmap(bitmap)
} else {
val bitmap = Bitmap.createBitmap(
20,
20,
Bitmap.Config.ARGB_8888
)
return BitmapDescriptorFactory.fromBitmap(bitmap)
}
mohammad-firmansyah marked this conversation as resolved.
Show resolved Hide resolved

return BitmapDescriptorFactory.fromBitmap(bitmap)
}

private sealed class ViewKey<T : ClusterItem> {
Expand Down