Skip to content

feat!: Android Location Button with Native Islands - #20

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

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

Conversation

@OS-pedrogustavobilro

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

Copy link
Copy Markdown
Contributor

Description

⚠️ 🤖 AI-assisted development with Claude Code.

Adds the Android 17 Location Button as a Native Islands component, and makes the library use compileSdk 37.

Location Button (view/)

  • IONGLOCLocationButtonRegistry registers the os.locationButton native island. The host plugin passes its IONGLOCController, and optional error-code and position mappers.
  • IONGLOCLocationButtonIsland hosts the Jetpack Compose LocationButton (androidx.core.locationbutton:locationbutton-compose) in a ComposeView:
    • On Android 17+ it is the system button, with the unobscured-surface requirement enforced and the surface clipped via NativeIslandSurfaceClip. Below 17 it is a compatibility button from Google with the default permission flow for location permission.
    • It has a 48dp minimum size.
    • It is configurable through text type, colors, corner radius and stroke, plus timeout, maximumAge and enableLocationFallback. Invalid values are rejected before anything is applied.
  • IONGLOCLocationButtonDelegate handles the permission result and buffers it until the host resumes. It fetches the position with the existing getCurrentPosition (single shot, high accuracy), cancels on destroy (a result that arrives while the host is paused, for example while the "turn on location" dialog is shown, is held and delivered on resume), and emits grant, position and buttonError.
  • New IONGLOCLocationButtonException, so errors from the button session get a code. The plugins map it to OS-PLUG-GLOC-0019, and unmapped errors default to OS-PLUG-GLOC-0002.
  • The USE_LOCATION_BUTTON permission (named as required in the android docs) is added to the manifest.

Native Islands runtime

  • Vendored libs/ionnativeislands-android-release.aar is compileOnly (and testImplementation). With SHOULD_PUBLISH=true the library depends on io.ionic.libs:ionnativeislands-android:1.0.0, which is not on Maven Central yet. Hosts that vendor the AAR must provide the runtime.

Build and packaging

  • One AAR: compileSdk and targetSdk 37, minSdk 26, and aarMetadata { minCompileSdk = 37 }.
  • Toolchain: AGP 9.2.1 (built-in Kotlin 2.2, Compose compiler plugin 2.2.10) and Gradle 9.4.1. Plugin updates: nexus publish 2.0.0, SonarQube 7.6.0. Removed kotlin-android, Jetifier and the vector-drawable support flag.
  • Gradle 9 publishing fixes: dropped -b from the publish script and archives from publish-module.gradle.
  • New dependencies: locationbutton-compose:1.0.0-alpha01 and compose.foundation:1.12.1. The button artifact is still alpha, and the library pins both versions.
  • pom.xml version is 4.0.0-alpha.2. TDC on when will the stable version for this library be released, but is out of scope from this PR
  • Minor cleanups: removed an unused FlowPreview opt-in and added a NewApi suppression in the extensions.
  • README Requirements and CHANGELOG updated.

Context

  • RMET-5199: Android 17 Location Button in the Geolocation plugins.
  • The Compose button is used because the Views LocationButton can show Google's compat button next to the system button on Android 17 (issue tracker).
  • Single AAR and minSdk 26: RMET-5586.
  • Going into next branch because of breaking changes involved; in case we need to do a hotfix in the current stable version in the mean time.

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)

Breaking for consumers:

  • They must build with compileSdk 37 or higher, so MABS 12 apps (compileSdk 36) cannot use this version, including for the existing geolocation methods.
  • They need AGP 9.1+ and Kotlin 2.1+, and minSdk 26+.
  • The host Activity must be a ComponentActivity.
  • Not necessarily a breaking change, but a meaningful one: The library brings Jetpack Compose (foundation, ui and runtime 1.12.1, activity-compose 1.13.0 and material3 1.5.0-alpha21, which is alpha). That is about 1 MB more in an APK built with R8, and several MB more without it.

Tests

  • Unit tests added for the delegate (permission buffering, fetch, errors, lifecycle) and the island's property helpers; ./gradlew testDebugUnitTest passes.
  • Manually tested through the Capacitor and OutSystems example apps (click in the links if you want to test yourself):
    • Android 17 (Pixel 6): system button, scrolling, grant and deny permission, background/foreground.
    • The pause scenario: the "turn on location" dialog pauses the Activity while a fetch is in flight, and the result is delivered after resume.
    • Android below 17: local button and permission flow.
    • A Cordova app combined with OSBarcodeLib to confirm .
    • R8 release builds of both plugin apps.

Checklist

  • Code follows code style of this project
  • CHANGELOG.md file is correctly updated
  • Changes require an update to the documentation
    • Documentation has been updated accordingly

ItsChaceD and others added 24 commits July 21, 2026 14:29
Currently with default values for input parameters, in a future commit we will configure that as well
* refactor: remove clickablePadding and pressedCornerRadius

These were very specific properties

According to https://outsystemsrd.atlassian.net/wiki/spaces/RDMBLVS/pages/6901825608/UX+Android+location+button, and what was aligned with UX team, better to keep it simpler and do not allow configuring such properties.

* refactor: Make library use SDK 37 and Gradle 9

Per UX alignment, we're not interested on API < 37 compatibility, especially given limitations like no localization. Users that use this native library with location button need MABS 13 / Capacitor 9.

References:

- https://outsystemsrd.atlassian.net/browse/RMET-5586
- https://outsystemsrd.atlassian.net/wiki/spaces/RDMBLVS/pages/6901825608/UX+Android+location+button

* chore: remove unused drawable

* chore: update native islands

* chore: release 3.0.0-alpha.1

* tmp: Comment native islands from maven central

To try this library's publish to maven central

* Revert "tmp: Comment native islands from maven central"

This reverts commit 05baba6.

* chore: bump alpha version (unreleased)

* chore: include additional error mapping

@alexgerardojacinto alexgerardojacinto left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Question: When using the Location Button, after I allow the one-time location access and I close the app, when I open the app again and try to obtain the location, should I be prompted for the location access again?

@alexgerardojacinto alexgerardojacinto self-assigned this Nov 19, 2026
@OS-pedrogustavobilro

OS-pedrogustavobilro commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

That is controlled by the system. I found it to work similar to the allow one time that happens in Android < 17. If I close the app and open it after a few seconds, it doesn't prompt. If I wait some minutes before re-opening, I get the prompt.

But yeah, that is controlled by the system, not by us.

@alexgerardojacinto

Copy link
Copy Markdown
Collaborator

Ok yeah I just got the same experience, that makes sense.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.USE_LOCATION_BUTTON" />

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we need to always declare the permissions? Can't we delegate this to the plugins that consume the library?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Both these permissions don't require granting at runtime.

USE_LOCATION_BUTTON can be moved to the plugins I suppose, and mimic what we do in Capacitor OSS where the plugin doesn't declare it but the consuming app does.

Do you have a particular concern with the permission staying here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No no, in this case, if this new permission doesn't require granting at runtime, I think it's totally ok to keep it here. If we're confident that it won't cause warnings in play store submissions (which I think it won't), then it's fine to keep here IMO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we're confident that it won't cause warnings in play store submissions (which I think it won't)

I'd say it won't yeah, at least this permission is to combat restrictions in the play store for location access, doesn't make much sense if they're gonna restrict it in the future.

@alexgerardojacinto alexgerardojacinto left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tested in Pixel 9 Pro XL (Android 17) and Pixel 3 XL (Android 12) and it seems to work properly.

@ItsChaceD

ItsChaceD commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

I tested this PR in the MABS 13 sample app while implementing RMET-5585. Everything seems to be working good!

My review agent found these minor issues to look at:

1. The layout listener isn't removed on destroy
Native Islands removes the view before calling onDestroy() (NIMountedIslands). Once the button is detached, button.viewTreeObserver is a new, empty observer, so removeOnGlobalLayoutListener does nothing and the listener stays on the window.
Suggestion: remove it from the observer you added it to, or add and remove it in the host's onAttachedToWindow / onDetachedFromWindow.

2. A fetch cancelled by a pause never reports back
With enableLocationFallback: false, the "turn on location" dialog pauses the Activity, and onPause() cancels the fetch while getCurrentPosition waits for the dialog's result. Nothing restarts it, so the page gets grant: true and then no position or buttonError.
Suggestion: start the fetch again on resume, or send a buttonError when it's cancelled.

Smaller things

  • IONGLOCLocationButtonIsland could be internal, since consumers only use the registry.
  • versionName "2.2.2" doesn't match 3.0.0-alpha.2 in pom.xml.
  • The "see Decisions" comment in IONGLOCLocationButtonDelegate points to nothing.

@OS-pedrogustavobilro

Copy link
Copy Markdown
Contributor Author

@ItsChaceD thanks for the review.

The comments are pertinent, especially the A fetch cancelled by a pause never reports back, I've reproduced it, I had written down in some notes that it made sense for backgrounding to cancel location fetch because it's tied to a native UI element tap, but it doesn't make that much sense, the other location requests outside of the location button aren't (and it's essentially the same code), plus it creates bugs when app gets minimized e.g. when user is prompted to grant location.

Addressed that and other things you mentioned in the latest commits.

The versionName commenting I'm not addressing, because technically we don't even need to have those lines, they're specific to applications, and I will review which libraries have those and remove them in a later date.

Because you approved the PR, I'm set to merge it Monday, but if you find anything else wrong with these changes let me know (or even if after it's merged, we can open new PRs to tweak it).

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