Skip to content

fix(android): accept null for unset tile source and Image props - #4453

Merged
mfazekas merged 1 commit into
mainfrom
fix/android-null-props-sweep
Nov 28, 2026
Merged

mfazekas merged 1 commit into
mainfrom
fix/android-null-props-sweep

Conversation

@mfazekas

@mfazekas mfazekas commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

Follow-up to #4454 and #4455. On Android, unsetting minZoomLevel, maxZoomLevel or tms on VectorSource/RasterSource, or sdf on Image, makes Fabric send null. That null crashed in DynamicFromObject.asX() (ClassCastException: Dynamic value from Object is not a number/boolean). These setters now treat null as unset. The PR also removes the // unset: ... comments #4455 added, which restate the code. The preferredFramesPerSecond comment stays, because the code can't show why null keeps the current cap.

followPadding is unchanged. Unsetting it already stores zero insets, which removes the padding. Storing null would fall back to cameraState.padding and keep the old padding, which I checked on the emulator.

Checklist

  • I've read CONTRIBUTING.md
  • I updated the doc/other generated code with running yarn generate in the root folder
  • 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

Release build on an Android emulator; each prop was unset after a fresh launch.

On main (09058de), all 7 crash:

  • VectorSource/RasterSource minZoomLevel: crash in RNMBXTileSourceManager.setMinZoomLevel
  • VectorSource/RasterSource maxZoomLevel: crash in RNMBXTileSourceManager.setMaxZoomLevel
  • VectorSource/RasterSource tms: crash in RNMBXTileSourceManager.setTms
  • Image sdf: crash in RNMBXImageManager.setSdf

With this PR there are no crashes. The run included unsetting every prop, setting them all again, and remounting. Unsetting followPadding recenters the puck, and setting it again moves the puck back down, both on main and with this PR.

Component to reproduce the issue you're fixing

Toggle reproducer (tap a button to unset or set that prop)
import React, { useState } from 'react';
import { Button, Text, View } from 'react-native';
import {
  Camera,
  Image,
  Images,
  LineLayer,
  LocationPuck,
  MapView,
  RasterLayer,
  RasterSource,
  ShapeSource,
  SymbolLayer,
  VectorSource,
} from '@rnmapbox/maps';

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

const PROPS = {
  vectorMinZoom: { minZoomLevel: 2 },
  vectorMaxZoom: { maxZoomLevel: 14 },
  vectorTms: { tms: false },
  rasterMinZoom: { minZoomLevel: 2 },
  rasterMaxZoom: { maxZoomLevel: 18 },
  rasterTms: { tms: false },
  imageSdf: { sdf: true },
  followPadding: { followPadding: { paddingTop: 600 } },
};

const NullPropsRepro = () => {
  const [on, setOn] = useState(
    Object.fromEntries(Object.keys(PROPS).map((k) => [k, true])),
  );
  const [key, setKey] = useState(0);
  const p = (k) => (on[k] ? PROPS[k] : {});

  const toggle = (k) => {
    console.log(`NULLREPRO ${on[k] ? 'unset' : 'set'} ${k}`);
    setOn({ ...on, [k]: !on[k] });
  };

  return (
    <View style={{ flex: 1 }}>
      <View style={{ flexDirection: 'row', flexWrap: 'wrap' }}>
        {Object.keys(PROPS).map((k) => (
          <Button
            key={k}
            title={`${on[k] ? 'set' : 'unset'} ${k}`}
            onPress={() => toggle(k)}
          />
        ))}
        <Button title="remount" onPress={() => setKey(key + 1)} />
      </View>
      <Text testID="nullrepro-state">
        {Object.keys(PROPS)
          .filter((k) => !on[k])
          .join(',') || 'all set'}
      </Text>
      <MapView key={key} style={{ flex: 1 }}>
        <Camera
          followUserLocation
          followZoomLevel={14}
          animationDuration={0}
          {...p('followPadding')}
        />
        <LocationPuck />
        <Images>
          <Image name="nullrepro-pin" {...p('imageSdf')}>
            <View style={{ width: 20, height: 20, backgroundColor: 'red' }} />
          </Image>
        </Images>
        <RasterSource
          id="nullrepro-raster"
          tileUrlTemplates={['https://tile.openstreetmap.org/{z}/{x}/{y}.png']}
          {...p('rasterMinZoom')}
          {...p('rasterMaxZoom')}
          {...p('rasterTms')}
        >
          <RasterLayer
            id="nullrepro-raster-layer"
            style={{ rasterOpacity: 0.3 }}
          />
        </RasterSource>
        <VectorSource
          id="nullrepro-vector"
          url="mapbox://mapbox.mapbox-streets-v8"
          {...p('vectorMinZoom')}
          {...p('vectorMaxZoom')}
          {...p('vectorTms')}
        >
          <LineLayer
            id="nullrepro-roads"
            sourceLayerID="road"
            style={{ lineColor: 'purple', lineWidth: 1 }}
          />
        </VectorSource>
        <ShapeSource id="nullrepro-shape" shape={shape}>
          <SymbolLayer
            id="nullrepro-symbol"
            style={{ iconImage: 'nullrepro-pin', iconAllowOverlap: true }}
          />
        </ShapeSource>
      </MapView>
    </View>
  );
};

export default NullPropsRepro;

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.
@mfazekas
mfazekas force-pushed the fix/android-null-props-sweep branch from 91accac to cdb9604 Compare November 27, 2026 05:16
@mfazekas mfazekas changed the title fix(android): accept null for unset props across view managers fix(android): accept null for unset tile source and Image props Nov 27, 2026
@mfazekas
mfazekas merged commit 642e0b2 into main Nov 28, 2026
19 of 20 checks passed
@mfazekas
mfazekas deleted the fix/android-null-props-sweep branch November 28, 2026 18:46

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.

1 participant