diff --git a/README.md b/README.md index 5d36c67..df9dbd7 100644 --- a/README.md +++ b/README.md @@ -74,15 +74,12 @@ os-location-button { border-color: #000000; border-width: 1px; border-radius: 16px; - --os-location-button-pressed-corner-radius: 12px; - --os-location-button-clickable-padding: 6px; z-index: 2; } ``` The native button supports opaque hexadecimal and RGB colors. Border width supports -`0px` through `3px`; both corner radii support `0px` through `68px`. Clickable -padding is clamped to the Android-supported range of `4px` through `8px`. +`0px` through `3px`; the corner radius supports `0px` through `68px`. ## API @@ -290,3 +287,4 @@ The following table list all the plugin errors: | OS-PLUG-GLOC-0016 | Android | Location settings error. | | OS-PLUG-GLOC-0017 | Android | Unable to retrieve location because device has both Network and Location turned off. | | OS-PLUG-GLOC-0018 | Android | Location permissions are not declared in manifest. Make sure at least ACCESS_COARSE_LOCATION is declared in AndroidManifest.xml, and optionally ACCESS_FINE_LOCATION if you require precise location access. | +| OS-PLUG-GLOC-0019 | Android | The location button reported an error. | diff --git a/android/build.gradle b/android/build.gradle index 2ab6077..dcf0025 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -83,7 +83,10 @@ dependencies { implementation project(':capacitor-android') } - implementation 'androidx.core.locationbutton:locationbutton:1.0.0-alpha01' + // Using compose androidx library instead of views because Views has UI issues + // See https://issuetracker.google.com/issues/567953859 + implementation 'androidx.core.locationbutton:locationbutton-compose:1.0.0-alpha01' + implementation 'androidx.compose.foundation:foundation:1.12.1' compileOnly localRuntimeAars implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion" diff --git a/android/libs/IONGeolocationLib-debug.aar b/android/libs/IONGeolocationLib-debug.aar index 482cbee..57a852d 100644 Binary files a/android/libs/IONGeolocationLib-debug.aar and b/android/libs/IONGeolocationLib-debug.aar differ diff --git a/android/libs/IONGeolocationLibApi37-debug.aar b/android/libs/IONGeolocationLibApi37-debug.aar deleted file mode 100644 index ceac2ff..0000000 Binary files a/android/libs/IONGeolocationLibApi37-debug.aar and /dev/null differ diff --git a/android/src/main/kotlin/com/capacitorjs/plugins/geolocation/GeolocationErrors.kt b/android/src/main/kotlin/com/capacitorjs/plugins/geolocation/GeolocationErrors.kt index 258e6a5..0f53f26 100644 --- a/android/src/main/kotlin/com/capacitorjs/plugins/geolocation/GeolocationErrors.kt +++ b/android/src/main/kotlin/com/capacitorjs/plugins/geolocation/GeolocationErrors.kt @@ -74,6 +74,11 @@ object GeolocationErrors { message = "Unable to retrieve location because device has both Network and Location turned off." ) + val LOCATION_BUTTON_ERROR = ErrorInfo( + code = formatErrorCode(19), + message = "The location button reported an error." + ) + val LOCATION_MANIFEST_PERMISSIONS_MISSING = ErrorInfo( code = formatErrorCode(18), message = "Location permissions are not declared in manifest. Make sure at least ACCESS_COARSE_LOCATION is declared in AndroidManifest.xml, and optionally ACCESS_FINE_LOCATION if you require precise location access." diff --git a/android/src/main/kotlin/com/capacitorjs/plugins/geolocation/GeolocationPlugin.kt b/android/src/main/kotlin/com/capacitorjs/plugins/geolocation/GeolocationPlugin.kt index 7526cc1..aee36f4 100644 --- a/android/src/main/kotlin/com/capacitorjs/plugins/geolocation/GeolocationPlugin.kt +++ b/android/src/main/kotlin/com/capacitorjs/plugins/geolocation/GeolocationPlugin.kt @@ -2,9 +2,7 @@ package com.capacitorjs.plugins.geolocation import android.Manifest import android.os.Build -import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts -import androidx.core.content.ContextCompat import androidx.lifecycle.Lifecycle import com.getcapacitor.JSObject import com.getcapacitor.PermissionState @@ -19,7 +17,6 @@ import io.ionic.libs.iongeolocationlib.model.IONGLOCException import io.ionic.libs.iongeolocationlib.model.IONGLOCLocationOptions import io.ionic.libs.iongeolocationlib.model.IONGLOCLocationResult import io.ionic.libs.iongeolocationlib.view.IONGLOCLocationButtonRegistry -import io.ionic.libs.iongeolocationlib.view.IONGLOCLocationButtonPermissionRequester import io.ionic.libs.ionnativeislandslib.NativeIslandsController import io.ionic.libs.ionnativeislandslib.NativeIslandsScrollChannel import kotlinx.coroutines.CoroutineScope @@ -42,19 +39,10 @@ class GeolocationPlugin : Plugin() { private lateinit var controller: IONGLOCController private lateinit var coroutineScope: CoroutineScope - private lateinit var locationButtonPermissionLauncher: ActivityResultLauncher> private val nativeIslandsController = NativeIslandsController { event, payload -> notifyListeners("nativeIslands:$event", JSObject.fromJSONObject(payload)) } - private val pendingLocationButtonPermissionResults = mutableListOf<(Boolean) -> Unit>() - private var locationButtonPermissionRequestInFlight = false private val watchingCalls: MutableMap = mutableMapOf() - private val locationButtonPermissionRequester = - IONGLOCLocationButtonPermissionRequester { callback -> - activity.runOnUiThread { - requestLocationButtonPermission(callback) - } - } companion object { const val LOCATION_ALIAS: String = "location" @@ -74,17 +62,8 @@ class GeolocationPlugin : Plugin() { } this.controller = IONGLOCController(context, activityLauncher) - locationButtonPermissionLauncher = bridge.registerForActivityResult( - ActivityResultContracts.RequestMultiplePermissions(), - ) { results -> - completeLocationButtonPermissionRequest( - results[Manifest.permission.ACCESS_FINE_LOCATION] == true, - ) - } IONGLOCLocationButtonRegistry.register( - activity, controller, - locationButtonPermissionRequester, ::mapButtonErrorCode, ::mapButtonPosition, ) @@ -106,38 +85,6 @@ class GeolocationPlugin : Plugin() { } } - private fun requestLocationButtonPermission(callback: (Boolean) -> Unit) { - if ( - ContextCompat.checkSelfPermission( - context, - Manifest.permission.ACCESS_FINE_LOCATION, - ) == android.content.pm.PackageManager.PERMISSION_GRANTED - ) { - callback(true) - return - } - pendingLocationButtonPermissionResults += callback - if (locationButtonPermissionRequestInFlight) return - locationButtonPermissionRequestInFlight = true - try { - locationButtonPermissionLauncher.launch( - arrayOf( - Manifest.permission.ACCESS_FINE_LOCATION, - Manifest.permission.ACCESS_COARSE_LOCATION, - ), - ) - } catch (_: RuntimeException) { - completeLocationButtonPermissionRequest(false) - } - } - - private fun completeLocationButtonPermissionRequest(granted: Boolean) { - locationButtonPermissionRequestInFlight = false - val callbacks = pendingLocationButtonPermissionResults.toList() - pendingLocationButtonPermissionResults.clear() - callbacks.forEach { callback -> callback(granted) } - } - /** Native Islands carrier methods hosted by Geolocation. */ @PluginMethod fun nativeIslandsLocationButtonCapabilities(call: PluginCall) { @@ -180,13 +127,7 @@ class GeolocationPlugin : Plugin() { override fun handleOnDestroy() { super.handleOnDestroy() coroutineScope.cancel() - pendingLocationButtonPermissionResults.clear() - locationButtonPermissionRequestInFlight = false - if (::locationButtonPermissionLauncher.isInitialized) { - locationButtonPermissionLauncher.unregister() - } nativeIslandsController.dispose() - IONGLOCLocationButtonRegistry.unregister(activity) } override fun handleOnResume() { @@ -457,6 +398,7 @@ class GeolocationPlugin : Plugin() { GeolocationErrors.GOOGLE_SERVICES_ERROR } is IONGLOCException.IONGLOCLocationRetrievalTimeoutException -> GeolocationErrors.GET_LOCATION_TIMEOUT + is IONGLOCException.IONGLOCLocationButtonException -> GeolocationErrors.LOCATION_BUTTON_ERROR } /** @@ -466,7 +408,7 @@ class GeolocationPlugin : Plugin() { * @param exception Throwable to map */ private fun mapButtonErrorCode(exception: Throwable): String? = - (exception as? IONGLOCException)?.let { mapToErrorInfo(it).code } + ((exception as? IONGLOCException)?.let { mapToErrorInfo(it) } ?: GeolocationErrors.POSITION_UNAVAILABLE).code /** * Extension function to return a successful plugin result diff --git a/example-app-location-button/package-lock.json b/example-app-location-button/package-lock.json index cb8aeba..aaa3a5a 100644 --- a/example-app-location-button/package-lock.json +++ b/example-app-location-button/package-lock.json @@ -22,18 +22,18 @@ }, "..": { "name": "@capacitor/geolocation", - "version": "8.2.4", + "version": "9.0.0-next.5", "license": "MIT", "dependencies": { "@capacitor/synapse": "^1.0.4" }, "devDependencies": { - "@capacitor/android": "^8.0.0", - "@capacitor/core": "^8.0.0", - "@capacitor/docgen": "^0.3.0", - "@capacitor/ios": "^8.0.0", + "@capacitor/android": "next", + "@capacitor/core": "next", + "@capacitor/docgen": "^0.3.1", + "@capacitor/ios": "next", "@capacitor/native-islands": "file:vendor/capacitor-native-islands-1.0.0.tgz", - "@ionic/eslint-config": "^0.4.0", + "@ionic/eslint-config": "^0.5.0", "@ionic/prettier-config": "^4.0.0", "@ionic/swiftlint-config": "^2.0.0", "@semantic-release/changelog": "^6.0.3", @@ -42,7 +42,7 @@ "@semantic-release/github": "^12.0.2", "@semantic-release/npm": "^13.1.2", "@types/node": "^24.10.1", - "eslint": "^8.57.1", + "eslint": "^10.0.0", "prettier": "^3.6.2", "prettier-plugin-java": "^2.7.7", "rimraf": "^6.1.2", @@ -52,7 +52,7 @@ "typescript": "^5.9.3" }, "peerDependencies": { - "@capacitor/core": ">=8.4.1 <9" + "@capacitor/core": ">=9.0.0-beta.0" } }, "node_modules/@capacitor/android": { diff --git a/example-app-location-button/src/js/capacitor-welcome.js b/example-app-location-button/src/js/capacitor-welcome.js index fa1954b..49e3006 100644 --- a/example-app-location-button/src/js/capacitor-welcome.js +++ b/example-app-location-button/src/js/capacitor-welcome.js @@ -126,21 +126,13 @@ window.customElements.define(
- - -
-
- - + +
-
- - -
@@ -305,15 +297,9 @@ window.customElements.define( bindRange('lb-corner-radius', 'lb-corner-radius-value', (value) => { locationButton.style.borderRadius = `${value}px`; }); - bindRange('lb-pressed-corner-radius', 'lb-pressed-corner-radius-value', (value) => { - locationButton.style.setProperty('--os-location-button-pressed-corner-radius', `${value}px`); - }); bindRange('lb-stroke-width', 'lb-stroke-width-value', (value) => { locationButton.style.borderTopWidth = `${value}px`; }); - bindRange('lb-clickable-padding', 'lb-clickable-padding-value', (value) => { - locationButton.style.setProperty('--os-location-button-clickable-padding', `${value}px`); - }); customizePanel.querySelector('#lb-text-type').addEventListener('change', (event) => { locationButton.setAttribute('text-type', event.target.value); diff --git a/src/location-button.ts b/src/location-button.ts index 948bbbd..be5bd1a 100644 --- a/src/location-button.ts +++ b/src/location-button.ts @@ -42,8 +42,6 @@ const STYLE_PROPERTIES = { iconTint: '--os-location-button-icon-color', strokeColor: 'border-top-color', strokeWidth: 'border-top-width', - pressedCornerRadius: '--os-location-button-pressed-corner-radius', - clickablePadding: '--os-location-button-clickable-padding', } as const; const OBSERVED_ATTRIBUTES = ['text-type', 'maximum-age', 'timeout', 'enable-location-fallback']; const OBSERVED_STYLES = [ @@ -52,8 +50,6 @@ const OBSERVED_STYLES = [ STYLE_PROPERTIES.iconTint, STYLE_PROPERTIES.strokeColor, STYLE_PROPERTIES.strokeWidth, - STYLE_PROPERTIES.pressedCornerRadius, - STYLE_PROPERTIES.clickablePadding, 'border-top-left-radius', ]; @@ -95,19 +91,6 @@ function pixelStyle( return Number.isFinite(number) && number >= minimum && number <= maximum ? number : fallback; } -function clampedPixelStyle( - style: CSSStyleDeclaration, - name: string, - minimum: number, - maximum: number, - fallback: number, -): number { - const value = style.getPropertyValue(name).trim(); - if (!value.endsWith('px')) return fallback; - const number = Number.parseFloat(value); - return Number.isFinite(number) ? Math.min(maximum, Math.max(minimum, number)) : fallback; -} - function nonNegativeIntegerAttribute(element: HTMLElement, name: string, fallback: number, minimum = 0): number { const value = element.getAttribute(name); if (value === null) return fallback; @@ -314,7 +297,7 @@ function installFallbackStyles(root: Document | ShadowRoot = document): void { block-size: 100%; min-inline-size: 3rem; min-block-size: 3rem; - padding-inline: calc(1rem + clamp(4px, var(--os-location-button-clickable-padding, 6px), 8px)); + padding-inline: 1rem; border: inherit; border-image-source: linear-gradient(transparent, transparent); border-image-slice: 1; @@ -329,7 +312,7 @@ function installFallbackStyles(root: Document | ShadowRoot = document): void { .os-location-button-fallback::before { content: ''; position: absolute; - inset: clamp(4px, var(--os-location-button-clickable-padding, 6px), 8px); + inset: 0; z-index: 0; box-sizing: border-box; border-width: inherit; @@ -339,10 +322,6 @@ function installFallbackStyles(root: Document | ShadowRoot = document): void { background-color: inherit; } - .os-location-button-fallback:active::before { - border-radius: clamp(0px, var(--os-location-button-pressed-corner-radius, 12px), 68px); - } - .os-location-button-fallback > * { position: relative; z-index: 1; @@ -460,9 +439,7 @@ function registerLocationButton(geolocationPlugin: GeolocationPlugin, protectedS iconTint: colorStyle(style, STYLE_PROPERTIES.iconTint, textColor), strokeColor: colorStyle(style, STYLE_PROPERTIES.strokeColor, '#000000'), cornerRadius, - pressedCornerRadius: pixelStyle(style, STYLE_PROPERTIES.pressedCornerRadius, 0, 68, 12), strokeWidth: pixelStyle(style, STYLE_PROPERTIES.strokeWidth, 0, 3, 0), - clickablePadding: clampedPixelStyle(style, STYLE_PROPERTIES.clickablePadding, 4, 8, 6), maximumAge: nonNegativeIntegerAttribute(element, 'maximum-age', 0), timeout: nonNegativeIntegerAttribute(element, 'timeout', 10_000, 1), enableLocationFallback: booleanAttribute(element, 'enable-location-fallback', true), diff --git a/vendor/capacitor-native-islands-1.0.0.tgz b/vendor/capacitor-native-islands-1.0.0.tgz index ed0e1d6..6fcd875 100644 Binary files a/vendor/capacitor-native-islands-1.0.0.tgz and b/vendor/capacitor-native-islands-1.0.0.tgz differ