Skip to content

Restore last viewport on launch; skip auto-fly when restored#7

Merged
dfalling merged 2 commits into
mainfrom
map-restore-viewport
May 26, 2026
Merged

Restore last viewport on launch; skip auto-fly when restored#7
dfalling merged 2 commits into
mainfrom
map-restore-viewport

Conversation

@dfalling
Copy link
Copy Markdown
Owner

Summary

  • Persist map center + zoom to EncryptedStorage on each region change (debounced 500ms) via a small viewportStore.
  • On launch, hydrate the saved viewport and pass it to Camera.initialViewState so element fetches happen immediately for the restored region — no more zoom-1 world view + fly-to-user round trip.
  • When a saved viewport exists, the auto-fly-to-user branch is skipped. The recenter button is the explicit way to jump to your current location.
  • First-launch users (no saved viewport) keep the fly-to-user behavior so they don't see a blank world.
  • Refactored the off-center check into a useMemo driven by position + last viewportState, so the recenter button can appear as soon as position arrives — even before any pan.

Reviewer notes

  • The 4th bullet in the request ("keep the zoom until the first batch of elements is loaded") is currently implemented as "never auto-change zoom when a saved viewport exists." Easy to revert if it feels wrong in practice.
  • Storage uses the existing react-native-encrypted-storage for consistency with tokenStore. Bounds aren't sensitive, but adding a second storage dep felt like more churn than it's worth.

Test plan

  • First-ever launch (clear app data): map lands at world view, then flies to user when GPS arrives. After a pan, kill + relaunch: lands at last-panned viewport, no fly.
  • Panned away from user: recenter button appears; tapping it flies to user.
  • Open app while physically far from last saved viewport: recenter button appears as soon as GPS resolves.
  • Element pins fetch and render immediately on launch for the restored region, no flicker through world view.

🤖 Generated with Claude Code

dfalling and others added 2 commits May 26, 2026 18:58
Persist the map center+zoom (debounced) on each region change via a
small viewport store backed by the same EncryptedStorage we use for
auth. On launch, hydrate the saved viewport and use it as the camera's
initialViewState so elements fetch immediately for that region instead
of going through a zoom-1 world view and the fly-to-user dance.

When a saved viewport exists, the recenter button is the user's way to
jump to their current location; we no longer auto-fly there on first
position fix. First-launch users (no saved viewport) still get the fly
to user behavior so they don't open the app to a blank world.

The off-center check now also runs from a useMemo so the recenter
button can appear as soon as position arrives, even if the user hasn't
moved the map yet.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Remove both the GPS-wait overlay and the viewport-hydration spinner.
The hydration read is fast enough that the brief blank frame is less
distracting than a flashed spinner, and the GPS-wait overlay only ever
appeared on first-ever launch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@dfalling dfalling merged commit 2a0303a into main May 26, 2026
2 checks passed
@dfalling dfalling deleted the map-restore-viewport branch May 26, 2026 20:28
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