Skip to content

Conversation

@sleda
Copy link

@sleda sleda commented Dec 10, 2025

Description

Fixes crash on React Native 0.83+ related to AnimatedPoint.

In React Native 0.83, the underlying Animated nodes (inherited via AnimatedWithChildren) changed the internal _listeners storage from a plain Object to a Map.

The AnimatedPoint class was unconditionally overwriting this._listeners = {} in its constructor and accessing it using object notation (this._listeners[id]), which caused crashes on newer React Native versions when using AnimatedPoint or ShapeSource with animated coordinates.

Changes:

  • Constructor: Updated to preserve this._listeners if it has already been initialized (e.g., as a Map by the superclass in RN 0.83+). It falls back to {} only if uninitialized (RN < 0.83).
  • addListener / removeListener: Added logic to detect if _listeners is a Map or an Object and use the appropriate methods (.set()/.delete() vs object assignment).

Test Plan

I have successfully tested this fix on React Native 0.83.0-rc.5 with New Architecture (Fabric) enabled on iOS 26.2. The crash is resolved, and animated location updates work as expected.

Reproduction / Validation Steps

I utilized the following minimal reproduction component to isolate the issue:

import { AnimatedPoint } from '@rnmapbox/maps';
import { useEffect } from 'react';

// This component isolates the AnimatedPoint logic to verify listener attachment
export function TestCrash() {
  useEffect(() => {
    console.log('Testing AnimatedPoint listener...');
    try {
      const point = new AnimatedPoint({
        type: 'Point',
        coordinates: [0, 0],
      });
      
      // CRITICAL: This line triggers the crash on RN 0.83+ without this fix
      const id = point.addListener(() => {
        console.log('Point changed');
      });
      
      console.log('AnimatedPoint listener added successfully, ID:', id);
      point.removeListener(id);
    } catch (e) {
      console.error('AnimatedPoint crash test failed:', e);
    }
  }, []);
  return null;
}

Results:

  • Before Fix: App crashes immediately upon mounting TestCrash or using .
  • After Fix: Logs confirm success:
LOG Testing AnimatedPoint listener... LOG AnimatedPoint listener added successfully, ID: 1-1765381572236

And works smoothly.

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 V10 mode (Validated logic against known crash)
  • In New Architecture mode/ios
  • In V10 mode/android
  • In New Architecture mode/android
  • I added/updated a sample - if a new feature was implemented (/example)

@sleda sleda requested a deployment to CI with Mapbox Tokens December 10, 2025 15:54 — with GitHub Actions Waiting
@sleda sleda requested a deployment to CI with Mapbox Tokens December 10, 2025 15:54 — with GitHub Actions Waiting
@sleda sleda requested a deployment to CI with Mapbox Tokens December 10, 2025 15:54 — with GitHub Actions Waiting
@sleda sleda requested a deployment to CI with Mapbox Tokens December 10, 2025 15:54 — with GitHub Actions Waiting
@sleda sleda requested a deployment to CI with Mapbox Tokens December 10, 2025 15:54 — with GitHub Actions Waiting
@sleda sleda requested a deployment to CI with Mapbox Tokens December 10, 2025 15:54 — with GitHub Actions Waiting
@sleda sleda requested a deployment to CI with Mapbox Tokens December 10, 2025 15:54 — with GitHub Actions Waiting
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