Skip to content

feat: Android location button and getLocationButtonState() - #122

Open
OS-pedrogustavobilro wants to merge 5 commits into
nextfrom
feat/RMET-5199/location-button-plugin
Open

OS-pedrogustavobilro wants to merge 5 commits into
nextfrom
feat/RMET-5199/location-button-plugin

Conversation

@OS-pedrogustavobilro

@OS-pedrogustavobilro OS-pedrogustavobilro commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ 🤖 AI-assisted development with Claude Code.

Co-authored with @ItsChaceD

Description

  • Adds <os-location-button>, Android's system location button, registered when the plugin is imported. It is Android only: on iOS and web the element is hidden. It uses Native Islands project for the native component to be embedded into the web app.
  • Adds getLocationButtonState(), which returns system (Android 17+), compat (older Android) or unavailable (iOS and web).
  • README: when the button is needed, how to use it in a new integration or migrate an existing app, and its styling rules and limits.
  • TypeScript tests for the element registration and the state API, run in CI by a new test-typescript job.

Context

  • RMET-5199 (Android 17 location button) and RMET-5585 (Android-only button and state API, with no replica on iOS and web).
  • Google Play requires the button for apps that target Android 17 (API 37) and only need momentary precise location, or a declaration explaining why it isn't enough (policy). Apps that don't need it keep working unchanged.
  • The native side was implemented on ion-android-geolocation#20.

Type of changes

  • Fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Refactor (cosmetic changes)
  • Breaking change (change that would cause existing functionality to not work as expected)

Platforms affected

  • Android
  • iOS
  • JavaScript

Tests

  • New TypeScript tests (npm test): the element is hidden and the native state isn't queried outside Android, the web state is unavailable, and the native element registers for system and compat. A failed state read hides the element instead of leaving it undefined.
  • Manual, in the example app (available over at chore(android): example app to test location button #123 if you'd like to test yourself), on an Android 17 device (system) and an Android 12 device (compat), here's a list of some of the tests made:
    • the button renders, and grant, deny and position events work;
    • scrolling, and the keyboard opening with the button in flow or fixed;
    • web content over the button: the button is hidden by an opaque overlay, an opaque modal backdrop or a moving overlay, stays under a translucent backdrop, and comes back afterwards;
    • backgrounding the app while the location dialog is open, and Activity recreation;
    • an R8 release build, and the plugin installed from its packed tarball into a copy of the example app.

@OS-pedrogustavobilro
OS-pedrogustavobilro force-pushed the feat/RMET-5199/location-button-plugin branch from 38443c0 to b186fe6 Compare November 26, 2026 18:36

@alexgerardojacinto alexgerardojacinto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review from my AI agent, take it with a grain of salt:

  • GeolocationPlugin.kt: handleOnDestroy() cleanup order

    • coroutineScope.cancel() runs before nativeIslandsController.dispose(). If cancel() throws (for example the lateinit var coroutineScope was never initialised because load() failed early), dispose() is skipped and the native views leak.
    • Fix: call dispose() first, or wrap both calls in try/finally.
  • GeolocationPlugin.kt: IONGLOCLocationButtonRegistry.register(...) has no matching unregister

    • The registry is process-global and captures controller and ::mapButtonErrorCode. After Activity recreation, a new plugin instance registers again. I couldn't tell from the diff whether register replaces or stacks entries, or whether the old controller is released. The PR notes cover Activity recreation, so this is probably fine.
    • Fix: unregister in handleOnDestroy() if the library offers it, or confirm that register replaces the previous entry.
  • GeolocationPlugin.kt: mapToErrorInfo() is an exhaustive when with no else

    • If a new IONGLOCException subtype appears in a future ion-android-geolocation bump, compilation fails. That is useful, but it breaks anyone who resolves a different library version.
    • Fix: keep it exhaustive and keep the 4.0.0 pin strict.

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.

3 participants