Skip to content

[New Architecture][iOS] Polygon/Geojson overlays never render with Google Maps (Fabric) #5928

Description

@ThomasPonzoVisma

Summary

With the New Architecture (Fabric) enabled and provider="google" on iOS, <Polygon> and <Geojson> overlays never render. Markers in the same map render fine. The GMSPolygon is created but never attached to the map.

Environment

  • react-native-maps: 1.27.2
  • Platform: iOS, provider="google" (Google Maps SDK)
  • New Architecture (Fabric): enabled
  • React Native 0.83.x / Expo SDK 55

Reproduction

Minimal map with New Architecture enabled:

<MapView
  provider="google"
  style={{ flex: 1 }}
  initialRegion={{ latitude: 52.09, longitude: 5.12, latitudeDelta: 0.05, longitudeDelta: 0.05 }}
>
  <Polygon
    coordinates={[
      { latitude: 52.10, longitude: 5.10 },
      { latitude: 52.10, longitude: 5.14 },
      { latitude: 52.08, longitude: 5.12 },
    ]}
    fillColor="rgba(0,128,255,0.4)"
    strokeColor="#0066ff"
    strokeWidth={2}
  />
</MapView>

Expected: a filled triangle. Actual: nothing renders. (A <Marker> added to the same map does render.)

Root cause

In ios/AirGoogleMaps/AIRGoogleMap.mm, the New-Arch Google polygon branch of insertReactSubview: / removeReactSubview: leaves the attach/detach calls commented out, so the GMSPolygon is never assigned to the map:

} else if ([NSStringFromClass([subview class]) isEqualToString:@"RNMapsGooglePolygonView"]) {
//      RNMapsGooglePolygonView *polygon = (RNMapsGooglePolygonView*)subview;
//      [polygon didInsertInMap:self];   // <-- never attached → never renders
    [self.polygons addObject:subview];
}

RNMapsGooglePolygonView didInsertInMap: (which sets _view.map = map) is never invoked, and didRemoveFromMap is likewise never called on removal.

Note: attaching unconditionally is also unsafe under Fabric — coordinates can arrive via updateProps after mount, and attaching a GMSPolygon whose path has < 3 points crashes Google Maps (null-deref in gmssdk::CoordsToPoints during setMap:). So the attach must be deferred until the path is renderable.

Suggested fix

Invoke didInsertInMap: / didRemoveFromMap for the New-Arch polygon view, and defer the actual attach until the path is valid (≥ 3 points), re-checking from updateProps:

// AIRGoogleMap.mm — insertReactSubview: (and the mirror in removeReactSubview: → didRemoveFromMap)
if ([subview respondsToSelector:@selector(didInsertInMap:)]) {
    [subview performSelector:@selector(didInsertInMap:) withObject:self];
}
// RNMapsGooglePolygonView.mm
- (void)didInsertInMap:(AIRGoogleMap *)map { _pendingMap = map; [self attachIfReady]; }

- (void)attachIfReady {
    if (_view != nil && _view.map == nil && _pendingMap != nil
        && _view.path != nil && _view.path.count >= 3) {
        _view.map = _pendingMap;   // safe: path is renderable
    }
}
// ...and call [self attachIfReady] at the end of updateProps:, after coordinates are applied.

I have a complete, working patch-package patch against 1.27.2 for this (and several related New-Arch overlay issues) and am happy to open a PR if that's preferred.

Related: #5355 (Fabric support tracking), #5457.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions