[New Architecture][iOS] Polygon does not update when a vertex is moved (path only rebuilt on coordinate COUNT change)
Summary
On Fabric / iOS with provider="google", updating a <Polygon>'s coordinates to the same number of points but different positions (i.e. moving a vertex) does not update the rendered shape. Adding or removing a point (a count change) does update it.
Environment
- react-native-maps: 1.27.2
- Platform: iOS,
provider="google" - New Architecture (Fabric): enabled
- React Native 0.83.x / Expo SDK 55
Reproduction
const [coords, setCoords] = useState([
{ latitude: 52.10, longitude: 5.10 },
{ latitude: 52.10, longitude: 5.14 },
{ latitude: 52.08, longitude: 5.12 },
]);
// ...
<MapView provider="google" style={{ flex: 1 }} initialRegion={/* ... */}>
<Polygon coordinates={coords} fillColor="rgba(0,128,255,0.4)" strokeColor="#0066ff" strokeWidth={2} />
</MapView>
// Move one vertex (same point count):
setCoords(c => [{ ...c[0], latitude: 52.11 }, c[1], c[2]]);Expected: the polygon edge follows the moved vertex. Actual: the shape stays put.
Root cause
ios/AirGoogleMaps/RNMapsGooglePolygonView.mm rebuilds the GMSMutablePath only when the coordinate count changes:
if (newViewProps.coordinates.size() != oldViewProps.coordinates.size()) {
// build GMSMutablePath and assign _view.path
}When the count is unchanged but values differ (a moved vertex), the path is never rebuilt.
Suggested fix
Rebuild when the coordinates differ in count or value (element-wise compare):
bool coordsChanged = newViewProps.coordinates.size() != oldViewProps.coordinates.size();
if (!coordsChanged) {
for (size_t i = 0; i < newViewProps.coordinates.size(); i++) {
if (newViewProps.coordinates.at(i).latitude != oldViewProps.coordinates.at(i).latitude ||
newViewProps.coordinates.at(i).longitude != oldViewProps.coordinates.at(i).longitude) {
coordsChanged = true;
break;
}
}
}
if (coordsChanged) {
// build GMSMutablePath and assign _view.path (unchanged)
}Note: holes likely has the same issue — areHolesEqual compares only sizes, so editing a hole vertex wouldn't update either.
A working patch-package patch for 1.27.2 is available; PR can follow.
Source: react-native-maps/react-native-maps