Skip to content

fix(android): accept null anchors in hand-written layer managers - #4421

Merged
mfazekas merged 1 commit into
mainfrom
fix/android-null-layer-anchor-handwritten
Oct 27, 2026
Merged

mfazekas merged 1 commit into
mainfrom
fix/android-null-layer-anchor-handwritten

Conversation

@mfazekas

@mfazekas mfazekas commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

Follow-up to #4362. RNMBXBackgroundLayerManager, RNMBXFillExtrusionLayerManager and RNMBXSkyLayerManager are hand-written (they don't use the LayerManagerCommonProps codepart), so they still call Dynamic.asString() on aboveLayerID/belowLayerID (and sourceLayerID for fill-extrusion). These now use asStringOrNull().

With that alone, unsetting sourceLayerID on a mounted FillExtrusionLayer moved the crash to an NPE in RNMBXFillExtrusionLayer.setSourceLayerID (mSourceLayerID!!), so a null is now ignored there and the current source layer is kept.

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

Tested on an Android emulator (API 34, debug build). Each button toggles that layer's anchor props to undefined.

Before, each toggle throws:

java.lang.ClassCastException: Dynamic value from Object is not a string
  at com.facebook.react.bridge.DynamicFromObject.asString(DynamicFromObject.kt:48)
  at ...RNMBXFillExtrusionLayerManager.setSourceLayerID(RNMBXFillExtrusionLayerManager.kt:72)
  at ...RNMBXFillExtrusionLayerManagerDelegate.setProperty(RNMBXFillExtrusionLayerManagerDelegate.java:58)
  at com.facebook.react.uimanager.ViewManager.updateProperties(ViewManager.java:102)
  at com.facebook.react.fabric.mounting.SurfaceMountingManager.updateProps(SurfaceMountingManager.java:811)

  at ...RNMBXBackgroundLayerManager.setBelowLayerID(RNMBXBackgroundLayerManager.kt:47)
  at ...RNMBXSkyLayerManager.setBelowLayerID(RNMBXSkyLayerManager.kt:47)

With only the manager change, fill-extrusion then fails with:

java.lang.NullPointerException
  at ...RNMBXFillExtrusionLayer.setSourceLayerID(RNMBXFillExtrusionLayer.kt:45)

After: I toggled all three layers off and on through 3 rounds. There were no exceptions in logcat and the app stayed up.

Component to reproduce the issue you're fixing

import React, { useState } from 'react';
import { Button, SafeAreaView, Text, View } from 'react-native';
import Mapbox, {
  BackgroundLayer,
  Camera,
  FillExtrusionLayer,
  MapView,
  SkyLayer,
} from '@rnmapbox/maps';

const ANCHOR = 'water';

export default function NullAnchorRepro() {
  const [anchored, setAnchored] = useState({
    background: true,
    extrusion: true,
    sky: true,
  });
  const toggle = (key) => setAnchored((s) => ({ ...s, [key]: !s[key] }));
  return (
    <SafeAreaView style={{ flex: 1 }}>
      <View style={{ flexDirection: 'row', justifyContent: 'space-around' }}>
        <Button title="Background" onPress={() => toggle('background')} />
        <Button title="FillExtrusion" onPress={() => toggle('extrusion')} />
        <Button title="Sky" onPress={() => toggle('sky')} />
      </View>
      <Text>{JSON.stringify(anchored)}</Text>
      <MapView style={{ flex: 1 }} styleURL={Mapbox.StyleURL.Street}>
        <Camera zoomLevel={15} pitch={60} centerCoordinate={[-74.006, 40.7128]} />
        <BackgroundLayer
          id="repro-background"
          belowLayerID={anchored.background ? ANCHOR : undefined}
          style={{ backgroundColor: '#fde' }}
        />
        <FillExtrusionLayer
          id="repro-extrusion"
          sourceID="composite"
          sourceLayerID={anchored.extrusion ? 'building' : undefined}
          aboveLayerID={anchored.extrusion ? ANCHOR : undefined}
          style={{
            fillExtrusionColor: '#a6c',
            fillExtrusionHeight: ['get', 'height'],
            fillExtrusionOpacity: 0.7,
          }}
        />
        <SkyLayer
          id="repro-sky"
          belowLayerID={anchored.sky ? ANCHOR : undefined}
          style={{ skyType: 'atmosphere' }}
        />
      </MapView>
    </SafeAreaView>
  );
}

BackgroundLayer, FillExtrusionLayer and SkyLayer managers don't use the
LayerManagerCommonProps codepart, so they still called Dynamic.asString()
on aboveLayerID/belowLayerID/sourceLayerID, which throws when a prop goes
from a value to undefined. Follow-up to #4362.
@mfazekas
mfazekas merged commit 81ee3d2 into main Oct 27, 2026
10 checks passed
@mfazekas
mfazekas deleted the fix/android-null-layer-anchor-handwritten branch October 27, 2026 20:29

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