Skip to content

feat!: Android-only location button and getLocationButtonState() - #119

Open
ItsChaceD wants to merge 3 commits into
feat/RMET-5199/location-buttonfrom
feat/RMET-5585/location-button-state
Open

ItsChaceD wants to merge 3 commits into
feat/RMET-5199/location-buttonfrom
feat/RMET-5585/location-button-state

Conversation

@ItsChaceD

@ItsChaceD ItsChaceD commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ CLAUDE ASSISTED PR ⚠️

Description

  • os-location-button is Android only. On iOS and web the element is hidden (display: none), and the replica is removed.
  • getLocationButtonState() returns system (Android 17 and later), compat (older Android), or unavailable (iOS and web). It replaces the private nativeIslandsLocationButtonCapabilities call.
  • The UX defaults now apply: text-type use-precise-location, timeout 5000, maximum-age 3000, and width 100%.
  • On Android, the element shows nothing until the native button draws, and nothing if it can't show.
  • README: Android-only behaviour, attributes and defaults, label language, minimum size, and the onlyForLocationButton flag.
  • Native Islands Android library update: a component registered again now replaces its factory, so the button uses the new controller after the Activity is recreated (found while working on this ticket).

Context

RMET-5585, option B of [UX] Android location button. The OutSystems wrapper maps the three states to AVAILABLE_SYSTEM, AVAILABLE_COMPAT and UNAVAILABLE.

onlyForLocationButton needed no code changes. On Android 17:

  • The button still grants precise location.
  • The regular API gets approximate location until the button grants precise: coarseLocation reports granted and location reports denied. It doesn't prompt again on later calls.

Older versions ignore the flag.

Not covered by this PR:

  • The UX doc suggests a height of 40, but Android's minimum is 48.
  • The doc's transparent-background examples can't be built, because the native button only accepts #RRGGBB.

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

Lint, unit tests, build and Android lint pass. Example app checks:

  • API 37 emulator: system. The button returns a position with and without the flag. It still works after the element is removed and re-added (UX open item 2).
  • API 31 emulator: compat. The button returns a position with and without the flag.
  • iOS 26.3 simulator: unavailable, and nothing renders.
  • Chrome: unavailable. Nothing renders, even with a border and height set on the element.

MABS 13 sample (LocationSampleAppRMET5199 with this branch bundled in), API 37 emulator: system. The button shows with the OutSystems properties. Allow returns the position to the screen, Don't allow sends granted: false, and a text-type change updates the label.

@OS-pedrogustavobilro OS-pedrogustavobilro 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.

Leaving a few comments, several are non-blocker and technically don't need to be addressed here.

Did minor updates in the example app + updated geolocation library with ionic-team/ion-android-geolocation#20

Comment thread README.md
Comment on lines -55 to 60
Importing `@capacitor/geolocation` registers `<os-location-button>`. The plugin
Importing `@capacitor/geolocation` registers `<os-location-button>` on Android. The plugin
includes the Native Islands runtime, so applications do not install it separately.

```html
<os-location-button text-type="use-precise-location"></os-location-button>
```

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.

If this is documentation to show users how to declare the location button, it seems a bit confusing.

Comment thread src/location-button.ts
Comment on lines 197 to 206
textType: textType(element),
backgroundColor: colorStyle(style, STYLE_PROPERTIES.backgroundColor, '#0B57D0'),
textColor,
iconTint: colorStyle(style, STYLE_PROPERTIES.iconTint, textColor),
strokeColor: colorStyle(style, STYLE_PROPERTIES.strokeColor, '#000000'),
cornerRadius,
strokeWidth: pixelStyle(style, STYLE_PROPERTIES.strokeWidth, 0, 3, 0),
maximumAge: nonNegativeIntegerAttribute(element, 'maximum-age', 0),
timeout: nonNegativeIntegerAttribute(element, 'timeout', 10_000, 1),
maximumAge: nonNegativeIntegerAttribute(element, 'maximum-age', 3_000),
timeout: nonNegativeIntegerAttribute(element, 'timeout', 5_000, 1),
enableLocationFallback: booleanAttribute(element, 'enable-location-fallback', true),

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.

To me personally, this is one of those cases where OutSystems and Capacitor could diverge.

Currently for getCurrentPosition, OutSystems has 5_000 and 3_000 for timeout and maximumAge, while capacitor has 10_000 and 0. I don't see why we can't have that here too, to keep consistency with the default values that the existing plugin methods already have.

The same thing could even apply to having the os-location-button not be hidden in iOS and web here, as long as it was hidden for OutSystems. But that case I'm more leaning towards leaving as-is, because of the limitations around lack of localization, which we could aim at solving with additional properties that wouldn't apply to Android, but yeah in that case developers are better off having their own component to configure however they like. Plus it's simpler for us that way.

But I think the default values for timeout and maximumAge we could leave as before.

Does that make sense?

Comment thread src/location-button.ts

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.

Not a blocker for the PR or the task, but after this gets merged we can propagate to the cordova plugin's feature branch. Imo doesn't need a PR, a straight commit. Then again maybe that could be left to https://outsystemsrd.atlassian.net/browse/RMET-5587

Comment thread README.md
Comment on lines +67 to +70
Attributes: `text-type` (`use-precise-location` by default, or `share-precise-location`,
`near-my-precise-location`, `near-your-precise-location`, `precise-location`, `none`), `timeout`
(5000 ms), `maximum-age` (3000 ms) and `enable-location-fallback` (`true`). The system translates
the label, so it can differ from your app's language.

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.

Just a reminder that if you change the defaults in the TS code based on my other comment, change them here too.

Comment thread src/definitions.ts
/**
* Check which location button this device supports.
*
* The button is Android only. Use this to hide it, or to show your own control instead.

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.

"Use this to hide it" seems misleading, because it's not shown outside of Android.

Is there any visual difference from hiding it based on getLocationButtonState as opposed to how it already hides? Or it's more to not have the element declared in the first place?

Comment thread src/definitions.ts
Comment on lines +91 to +93
* `system` on Android 17 and later, where the system draws the button.
*
* `compat` on older Android versions, which show Google's compatibility button.

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.

Worth making the distinction that to comply with google play's location button requirements, you technically only need to use <os-location-button for system, not compat?

Although, maybe that's better served in the plugin documentation in README rather than API. And it doesn't need to be done in this PR necessarily, as I said before, we can touch up the docs after this PR is merged, before opening the "general" PR to next.

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.

Not needed to be done in this PR, but I might do after this PR is merged -> We probably don't need the iOS version of the app anymore. I mean what it would verify is that the button doesn't render, but don't think that's really worth it having 10 or 20 more files in the "final" PR. We can at least check that it doesn't appear on web, which is good enough for me.

But let me know if you agree / disagree. Might be thinking too much about small stuff here 😅

Maybe checking the visibility on iOS / web could be covered by a quick test?

Comment thread README.md
Comment on lines +81 to +83
On Android 17 and later, the regular API then gets approximate location until the button grants
precise location: after a request, `coarseLocation` is `granted` and `location` is `denied`. Older
versions ignore the flag.

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.

It wasn't clear to me initially that "regular API" included request/check permissions and getting actual position.

Added some code to the example app here to validate that it's just that.

Maybe this phrase could be made a bit clearer?

Comment thread src/location-button.ts
Comment on lines +262 to +265
void geolocationPlugin.getLocationButtonState().then(({ state }) => {
installStyles();
registerLocationButton(state === 'system');
});

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.

Claude pointed out that we should catch errors here. We're not returning any errors today. Even if we did, we'd just treat an error as the same as state being unavailable, right? Unsure if worth doing anything about 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.

2 participants