Skip to content

fix(android): track camera interaction independently of map idle - #1

Open
RobJacobson wants to merge 1 commit into
KijongHan:fix/issue-with-isUserInteraction-always-returning-true-when-location-puck-is-pulsingfrom
RobJacobson:codex/fix-4222-camera-observer
Open

RobJacobson wants to merge 1 commit into
KijongHan:fix/issue-with-isUserInteraction-always-returning-true-when-location-puck-is-pulsingfrom
RobJacobson:codex/fix-4222-camera-observer

Conversation

@RobJacobson

Copy link
Copy Markdown

A pulsing location puck keeps the renderer active, so MapIdle cannot reliably clear camera interaction state. This follow-up to rnmapbox/maps#4222 completes the observer approach for issue #3805: programmatic camera changes report false while gestures and their inertia report true, independently of renderer idle.

This PR targets rnmapbox#4222's source branch, so merging it incorporates commit 865b670963c3dd3004fafea6d65b83f536e0c7f6 into the original PR.

Changes

  • Track active gestures by type and camera animators by identity, preserving interaction during overlapping gestures, inertia, cancellation, and replacement.
  • Remove every gesture/animation listener and camera subscription on detach, ignore late callbacks, and support repeated attachment.
  • Apply timing and subscription prop changes after attachment, and preserve timeout cancellation of the pending quiet check.
  • Use CameraGestureObserver.onCameraChanged and the existing MapState callback contract. gestures.isGestureActive reports touch gestures; gestures.isUserInteraction includes gesture-owned camera animations.
  • Document the new camera event as Android-only, update the example without the auto-recenter timer, and regenerate documentation. Existing MapView.onRegionIsChanging native behavior remains unchanged; applications migrate to the observer callback.
  • Add native lifecycle and JavaScript callback regression coverage. Correct two pre-existing invalid Kotlin string literals so the native test sources compile.

Validation

  • Android example build passed with Mapbox 11.23.1, arm64, and Fabric.
  • Seven native regression tests passed: gesture/animator overlap, replacement/cancellation, developer/location animation classification, 100 attach/detach cycles, timeout ordering, dynamic timing updates, and late callbacks.
  • All 23 JavaScript suites / 114 tests passed, including direct MapState delivery, callback replacement, and disabling the Android event on iOS.
  • Lint passed with existing formatting warnings; TypeScript passed; documentation was regenerated.

On the Android emulator, a fixed location provider kept the pulsing puck visible. After a manual pan, the saved run recorded:

Programmatic recenter cycles:          16
Correctly false observer updates:      77
Incorrectly true observer updates:     0
Stale true legacy-event updates:       7
MapIdle callbacks:                     0

The new event remains correct while the unchanged legacy event reproduces the stale flag and the renderer never reports idle. Manual gesture frames are excluded from the programmatic measurement window. The original PR's basic observer path already avoided the idle dependency; focused lifecycle probes reproduced the overlap and cleanup defects addressed here.

Reproducer

Use the following as an example screen after the app's existing access-token setup. CustomLocationProvider keeps the puck visible without device GPS. Pan the map, allow recentering to run, and inspect the counters. Pulsing and recentering can be toggled independently. Temporary app startup adjustments and measurement code are excluded from the commit.

Pulsing puck reproducer
import React, { useEffect, useRef, useState } from "react";
import { View, Text, Button } from "react-native";
import {
  MapView,
  Camera,
  LocationPuck,
  CustomLocationProvider,
  CameraGestureObserver,
} from "@rnmapbox/maps";
const HOME = [-74.00597, 40.71427];
export default function Repro() {
  const camera = useRef(null);
  const animation = useRef(false);
  const readyAt = useRef(0);
  const counts = useRef({
    legacyWrong: 0,
    observerWrong: 0,
    observerRight: 0,
    idle: 0,
    ticks: 0,
  });
  const [status, setStatus] = useState("Pan map, then wait for recenter");
  const [pulse, setPulse] = useState(true);
  const [run, setRun] = useState(true);
  const report = (name, flag) => {
    if (!animation.current) return;
    const key =
      name === "legacy"
        ? "legacyWrong"
        : flag
          ? "observerWrong"
          : "observerRight";
    if (name !== "legacy" || flag) counts.current[key]++;
    console.log("[3805]", name, flag, JSON.stringify(counts.current));
    setStatus(JSON.stringify(counts.current));
  };
  useEffect(() => {
    if (!run) return;
    const timer = setInterval(() => {
      if (Date.now() < readyAt.current) return;
      counts.current.ticks++;
      animation.current = true;
      console.log("[3805] RECENTER", counts.current.ticks);
      camera.current?.setCamera({
        centerCoordinate: HOME,
        animationDuration: 1000,
        animationMode: "linearTo",
      });
      setTimeout(() => {
        animation.current = false;
      }, 1200);
    }, 5000);
    return () => clearInterval(timer);
  }, [run]);
  return (
    <View style={{ flex: 1 }}>
      <MapView
        style={{ flex: 1 }}
        onRegionIsChanging={(e) =>
          report("legacy", e.properties.isUserInteraction)
        }
        onMapIdle={() => {
          counts.current.idle++;
          console.log("[3805] IDLE", counts.current.idle);
        }}
      >
        <Camera
          ref={camera}
          defaultSettings={{ centerCoordinate: HOME, zoomLevel: 14 }}
        />
        <CustomLocationProvider coordinate={HOME} />
        <LocationPuck pulsing={{ isEnabled: pulse }} />
        <CameraGestureObserver
          onCameraChanged={(state) => {
            if (state.gestures.isGestureActive) {
              animation.current = false;
              readyAt.current = Date.now() + 2000;
            } else if (!animation.current && state.gestures.isUserInteraction) {
              readyAt.current = Date.now() + 2000;
            }
            report("observer", state.gestures.isUserInteraction);
          }}
        />
      </MapView>
      <View style={{ padding: 18 }}>
        <Text testID="status">{status}</Text>
        <Button
          title={pulse ? "Pulse ON" : "Pulse OFF"}
          onPress={() => setPulse(!pulse)}
        />
        <Button title={run ? "Stop" : "Start"} onPress={() => setRun(!run)} />
      </View>
    </View>
  );
}

- Track overlapping gestures and animator instances through cancellation and replacement
- Remove SDK listeners on detach and apply observer prop changes after attachment
- Expose Android onCameraChanged with the shared MapState callback contract
- Preserve steady timeout behavior and regenerate public documentation and examples
- Add lifecycle and callback regression tests and repair existing Kotlin test literals
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