feat(native): the app's own location on iOS, and a status bar tap scrolls to top

WKWebView asks for the location per server origin, under the server's name,
and again across launches. Binaries with the geolocation feature answer
navigator.geolocation from CoreLocation instead: one When-In-Use prompt as
the app, a stream that runs only while something listens, at the accuracy
the most demanding caller asked for. Every caller keeps the browser API.

A tap on the status bar now scrolls the list in the middle of the screen
back to the top, as in every iOS app.
This commit is contained in:
Maurice
2026-11-06 13:23:49 +01:00
parent 017f229cfc
commit 56f9a92054
6 changed files with 354 additions and 5 deletions
+22 -1
View File
@@ -4,7 +4,8 @@ import { SplashScreen } from '@capacitor/splash-screen';
import { StatusBar, Style } from '@capacitor/status-bar';
import { closeTopOverlay } from '../mobile/overlayStack';
import { isEffectivelyOffline } from '../sync/networkMode';
import { checkAppUpdate } from './capabilities';
import { checkAppUpdate, loadNativeCapabilities } from './capabilities';
import { installNativeGeolocation } from './geolocation';
import { keepOfflineShellFresh } from './offlineShell';
import { isNativeApp, isNativeIos } from './platform';
import { reportNativeFailure } from './reportFailure';
@@ -24,6 +25,12 @@ export function startNativeApp(): void {
// What this binary can do, and whether this server's UI needs a newer one.
void checkAppUpdate(fetchServerFeatures);
// The app's own location under navigator.geolocation, where the binary has it.
void loadNativeCapabilities().then(() => installNativeGeolocation());
// A tap on the status bar scrolls the list under it back to the top, as in
// every iOS app (the status-bar plugin fires statusTap on iOS).
window.addEventListener('statusTap', scrollToTop);
// Android's back gesture: through the app's own history first, and only
// then out of the app, the way a browser tab would behave.
@@ -72,3 +79,17 @@ async function fetchServerFeatures(): Promise<{ minNativeShellApi?: unknown }> {
if (!res.ok) return {};
return (await res.json()) as { minNativeShellApi?: unknown };
}
/** The scrolled list in the middle of the screen, else the page, back to its top. */
export function scrollToTop(): void {
let el = document.elementFromPoint(window.innerWidth / 2, window.innerHeight / 2) as HTMLElement | null;
while (el && el !== document.body) {
const overflow = getComputedStyle(el).overflowY;
if ((overflow === 'auto' || overflow === 'scroll') && el.scrollTop > 0) {
el.scrollTo({ top: 0, behavior: 'smooth' });
return;
}
el = el.parentElement;
}
window.scrollTo({ top: 0, behavior: 'smooth' });
}