fix: Android Fabric marker content view not measured/laid out#63
fix: Android Fabric marker content view not measured/laid out#63
Conversation
…ayout Agent-Logs-Url: https://github.com/dacoto/maps/sessions/bf453bb6-bc43-4f90-bd8f-49ade6ac8526 Co-authored-by: dacoto <16915053+dacoto@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes Android (React Native New Architecture/Fabric) custom marker views that weren’t being measured/la[id] out because the marker’s contentView was never attached to the native view hierarchy.
Changes:
- Add
ensureContentViewAttached()to lazily attachcontentViewto the view hierarchy. - Offset the attached
contentViewoff-screen via a large negativetranslationX. - Invoke
ensureContentViewAttached()when adding non-callout children.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Add contentView to the hierarchy so Fabric triggers measure/layout, | ||
| // but push it offscreen so it is never visually rendered on the map. | ||
| // createContentBitmap() calls contentView.draw(canvas) which draws | ||
| // relative to the view's own coordinate space, unaffected by translation. | ||
| contentView.translationX = OFFSCREEN_TRANSLATION_X | ||
| super.addView(contentView, 0, ViewGroup.LayoutParams( | ||
| ViewGroup.LayoutParams.WRAP_CONTENT, | ||
| ViewGroup.LayoutParams.WRAP_CONTENT | ||
| )) |
There was a problem hiding this comment.
contentView.translationX is set to an off-screen value, but createContentBitmap() calls contentView.draw(canvas), which applies the view's transform matrix (including translation) during drawing. This will shift the drawn content off the bitmap (often producing a blank/incorrect marker icon). Consider avoiding transforms for the off-screen hiding, or temporarily resetting/restoring translationX/translationY around bitmap rendering so rasterized markers render correctly.
|
Closes #61 |
Summary
Fixes custom marker views rendering incorrectly or not at all when using React Native's New Architecture (Fabric) on Android. In Fabric,
contentViewwas never attached to the view hierarchy, so Fabric skipped measure/layout passes on it and its children entirely.The fix lazily attaches
contentViewto the real view hierarchy viasuper.addView()on the first non-callout child addition. To avoid visually rendering it in the wrong position,translationXis set to-10000f(off-screen); this does not affectcreateContentBitmap(), which draws in the view's own coordinate space.Type of Change
Test Plan
contentViewis not visually rendered at an unexpected position on screen.Screenshots / Videos
Checklist