Skip to content

fix(camera): reset maxBounds when the prop is removed - #4293

Open
benjilollebg wants to merge 1 commit into
rnmapbox:mainfrom
benjilollebg:fix/camera-clear-max-bounds
Open

fix(camera): reset maxBounds when the prop is removed#4293
benjilollebg wants to merge 1 commit into
rnmapbox:mainfrom
benjilollebg:fix/camera-clear-max-bounds

Conversation

@benjilollebg

Copy link
Copy Markdown

Description

Removing the Camera.maxBounds prop (setting it back to null/undefined) does not remove the bounds restriction from the map.

Both platforms pass a nil bounds into CameraBoundsOptions when the prop is cleared:

  • Android (RNMBXCamera.updateMaxBounds): builder.bounds(mMaxBounds?.toBounds())
  • iOS (RNMBXCamera._updateMaxBounds): options.bounds = nil

In the Mapbox SDKs, a nil field in CameraBoundsOptions means "leave this property unchanged", so the previous restriction silently stays active. The common userland workaround — passing {ne: [180, 90], sw: [-180, -90]} — is not equivalent to the default either: it creates a finite world bounds that blocks panning across the antimeridian (the map gets stuck at ±180°), because the SDK default is an infinite world bounds.

This PR resets the bounds to the SDK default when the prop is removed:

  • Android: CoordinateBounds.world() (the SDK's documented default, infiniteBounds = true)
  • iOS: CoordinateBounds(southwest:northeast:infiniteBounds: true)

This matches how minZoom/maxZoom already handle null in the same function (// Passing null does not reset this value.).

Checklist

  • I've read CONTRIBUTING.md
  • I updated the doc/other generated code with running yarn generate in the root folder (no generated code affected — native-only change + example)
  • 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)

Component to reproduce the issue you're fixing

The RestrictMapBounds example is updated in this PR to act as the reproducer: it now has a bubble button toggling maxBounds between the Cornwall bounds and null.

  • Before the fix: tap "Remove bounds" → the camera stays locked to the old bounds; you cannot pan away.
  • After the fix: tap "Remove bounds" → panning is unrestricted again, including across the antimeridian (no dateline lock, unlike the {ne:[180,90], sw:[-180,-90]} workaround).
const [restrictBounds, setRestrictBounds] = useState(true);
return (
  <MapView style={{ flex: 1 }}>
    <Camera
      maxBounds={restrictBounds ? { ne: [-4.265762, 51.054738], sw: [-5.760365, 49.947256] } : null}
      zoomLevel={7}
      centerCoordinate={[-4.744276, 50.361239]}
    />
  </MapView>
);

Honest verification note: this was diagnosed from the SDK behavior (nil CameraBoundsOptions fields are documented as no-ops) and the fix mirrors the existing null-handling of minZoom/maxZoom two lines below. I hit this in a real app (entering/leaving a floor view that sets/clears maxBounds), where clearing the prop demonstrably left the restriction active and the world-bounds workaround got stuck at the dateline. I have not yet been able to run the /example app builds for the four checklist configurations — happy to iterate if CI or maintainers spot anything.

🤖 Generated with Claude Code

Passing null bounds to CameraBoundsOptions leaves the previous value
unchanged in the Mapbox SDK, so removing the Camera maxBounds prop kept
the old restriction (and setting world bounds manually blocks panning
across the antimeridian). Reset to the SDK default (infinite world
bounds) instead, on both Android and iOS, matching the existing
null-reset handling of minZoom/maxZoom.

The RestrictMapBounds example now has a button toggling maxBounds
on/off to demonstrate/reproduce this.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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