Skip to content

fix(android): accept null lineMetrics, clusterProperties and hitbox on ShapeSource - #4454

Merged
mfazekas merged 1 commit into
rnmapbox:mainfrom
gadcam:fix/android-shapesource-null-map-bool-props
Nov 23, 2026
Merged

mfazekas merged 1 commit into
rnmapbox:mainfrom
gadcam:fix/android-shapesource-null-map-bool-props

Conversation

@gadcam

@gadcam gadcam commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Description

Follow-up to #4451, as suggested in its review. On Android, unsetting these props on a mounted ShapeSource still crashes, because React Native sends null and RNMBXShapeSourceManager calls Dynamic.asBoolean()/asMap() on it:

  • lineMetrics: Dynamic value from Object is not a boolean
  • clusterProperties: Dynamic value from Object is not a ReadableMap
  • hitbox: Dynamic value from Object is not a ReadableMap

lineMetrics now reads if (lineMetrics.isNull) null else lineMetrics.asBoolean(), and clusterProperties/hitbox check isNull before asMap(). (The existing mapValue == null guard after asMap() could never fire, because asMap() throws first.) The stored value is cleared, so the property goes back to the Mapbox default the next time the source is built: the builder already skips null fields. For hitbox, touchHitbox falls back to the default 44x44.

I also checked hasPressListener, which calls asBoolean() directly. It isn't affected: ShapeSource.tsx always sends isFunction(this.props.onPress), and unsetting onPress in the reproducer doesn't throw. With this change, every prop on ShapeSource can be unset safely.

VectorSourceManager.setHitbox uses the same asMap() pattern. I didn't reproduce it there, so it's left out of this PR. It already benefits from RNMBXSource.setHitbox accepting null.

Checklist

  • I've read CONTRIBUTING.md
  • I updated the doc/other generated code with running yarn generate in the root folder (no spec or doc change)
  • I have tested the new feature on /example app.
    • In V11 mode/ios
    • In New Architecture mode/ios
    • In V11 mode/android
    • In New Architecture mode/android
  • I added/updated a sample - if a new feature was implemented (/example)

Screenshot OR Video

Tested on an Android emulator (Pixel 9, API 37) with a debug build of /example, using the reproducer below in place of BugReportExample.js. For each prop, on a fresh load, I toggled unset/set 5 times.

Before (main):

prop unset
onPress (hasPressListener) OK
hitbox Dynamic value from Object is not a ReadableMap at DynamicFromObject.asMap ← RNMBXShapeSourceManager.setHitbox
lineMetrics Dynamic value from Object is not a boolean at DynamicFromObject.asBoolean ← RNMBXShapeSourceManager.setLineMetrics
clusterProperties Dynamic value from Object is not a ReadableMap at DynamicFromObject.asMap ← RNMBXShapeSourceManager.setClusterProperties
Dynamic value from Object is not a ReadableMap
  at asMap (DynamicFromObject.kt:62)
  at setHitbox (RNMBXShapeSourceManager.kt:202)
  at setHitbox (RNMBXShapeSourceManager.kt:28)
  at setProperty (RNMBXShapeSourceManagerDelegate.java:73)
  at updateProperties (ViewManager.java:102)
  at updateProps (SurfaceMountingManager.java:811)

After: all four props survive 5 toggles each, with no DynamicFromObject exception in logcat, and the layer still renders.

Component to reproduce the issue you're fixing

BugReportExample.js
import React, { useState } from 'react';
import { Button, Text, View } from 'react-native';
import { Camera, CircleLayer, MapView, ShapeSource } from '@rnmapbox/maps';

const shape = {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      properties: {},
      geometry: { type: 'Point', coordinates: [-74.00597, 40.71427] },
    },
  ],
};

const PROPS = {
  lineMetrics: { lineMetrics: true },
  clusterProperties: {
    clusterProperties: { sum: ['+', ['get', 'n']] },
  },
  hitbox: { hitbox: { width: 10, height: 10 } },
  onPress: { onPress: () => {} },
};

const BugReportExample = () => {
  const [unset, setUnset] = useState({});
  const [log, setLog] = useState('');
  let props = {};
  Object.keys(PROPS).forEach((k) => {
    if (!unset[k]) props = { ...props, ...PROPS[k] };
  });
  return (
    <View style={{ flex: 1 }}>
      {Object.keys(PROPS).map((k) => (
        <Button
          key={k}
          testID={`toggle-${k}`}
          title={`${unset[k] ? 'Set' : 'Unset'} ${k}`}
          onPress={() => {
            setUnset({ ...unset, [k]: !unset[k] });
            setLog(`${log} ${k}`);
          }}
        />
      ))}
      <Text>toggled:{log}</Text>
      <MapView style={{ flex: 1 }}>
        <Camera centerCoordinate={[-74.00597, 40.71427]} zoomLevel={14} />
        <ShapeSource id="shape" shape={shape} cluster {...props}>
          <CircleLayer
            id="circles"
            style={{ circleColor: 'red', circleRadius: 8 }}
          />
        </ShapeSource>
      </MapView>
    </View>
  );
};

export default BugReportExample;

🤖 Generated with Claude Code

…n ShapeSource

Unsetting these props sends null to the manager, which threw from
Dynamic.asBoolean()/asMap(). Null now clears the stored value so the
Mapbox default applies (default 44x44 hitbox for hitbox).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@mfazekas mfazekas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — verified on an Android release build: unsetting lineMetrics, clusterProperties and hitbox crashed on main and no longer does; remount applies defaults. Optional nit: lineMetrics.asBooleanOrNull() / map.asMapOrNull() from utils/extensions/Dynamic.kt would read a bit tighter.

@mfazekas
mfazekas merged commit bd1dd98 into rnmapbox:main Nov 23, 2026
19 of 20 checks passed
mfazekas added a commit that referenced this pull request Nov 27, 2026
Unsetting minZoomLevel, maxZoomLevel or tms on VectorSource/RasterSource,
or sdf on Image, made Fabric send null, which crashed in
DynamicFromObject.asX(). Follows up #4454/#4455, and drops the
"// unset" comments #4455 added that restate the code.

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants