mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 21:11:14 +00:00
fix(native): GL maps load straight from their servers in the app, past the schemes they drew nothing through on iPadOS 26
This commit is contained in:
@@ -40,7 +40,10 @@ vi.mock('../../hooks/useNetworkMode', () => ({
|
||||
useNetworkMode: () => ({ offline: env.offline, forced: false, setForced: () => {} }),
|
||||
}));
|
||||
vi.mock('../../hooks/useIsDark', () => ({ useIsDark: () => env.dark }));
|
||||
vi.mock('../../native/tileCache', () => ({ tileCacheActive: () => env.tileStore }));
|
||||
vi.mock('../../native/tileCache', () => ({
|
||||
tileCacheActive: () => env.tileStore,
|
||||
glTileStoreActive: () => env.tileStore,
|
||||
}));
|
||||
vi.mock('../../native/platform', async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import('../../native/platform')>()),
|
||||
isNativeIos: () => false,
|
||||
|
||||
@@ -13,7 +13,7 @@ import { useNetworkMode } from '../../hooks/useNetworkMode'
|
||||
import { useIsDark } from '../../hooks/useIsDark'
|
||||
import { OFM_POSITRON } from '../../constants/mapDefaults'
|
||||
import { glWorksOffline, leafletWorksOffline, offlineStyleFor } from './offlineBasemap'
|
||||
import { tileCacheActive } from '../../native/tileCache'
|
||||
import { glTileStoreActive, tileCacheActive } from '../../native/tileCache'
|
||||
|
||||
// Auto-selects the map renderer based on user settings. Keeps the existing
|
||||
// Leaflet MapView untouched so the Mapbox GL variant can mature iteratively
|
||||
@@ -50,7 +50,7 @@ export function MapViewAuto(props: MapViewAutoProps) {
|
||||
// nothing stored is swapped for the stored one straight away.
|
||||
const nativeStore = tileCacheActive()
|
||||
const [preferStored, setPreferStored] = useState(false)
|
||||
const mapboxKept = configuredGl === 'mapbox-gl' && nativeStore
|
||||
const mapboxKept = configuredGl === 'mapbox-gl' && glTileStoreActive()
|
||||
const glFallback = !!configuredGl && offline && !glWorksOffline(configuredGl, maplibreStyle) && (!mapboxKept || preferStored)
|
||||
const glProvider = glFallback ? 'maplibre-gl' : configuredGl
|
||||
const leafletFallback = !configuredGl && offline && !leafletWorksOffline(mapProps.tileUrl ?? OFM_POSITRON, nativeIosWithoutStore(nativeStore))
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { hasNativeFeature } from './capabilities';
|
||||
import { GL_MAPS_THROUGH_APP_SCHEMES } from './glSchemes';
|
||||
import { installOfflineProtocol, offlineStyle } from './offlineTiles';
|
||||
import { isNativeApp, isNativeIos } from './platform';
|
||||
import { glTileStoreActive, mapboxTileCacheRequest, tileCacheActive } from './tileCache';
|
||||
|
||||
vi.mock('./platform', () => ({ isNativeIos: vi.fn(() => true), isNativeApp: vi.fn(() => true) }));
|
||||
vi.mock('./capabilities', () => ({ hasNativeFeature: vi.fn(() => true) }));
|
||||
|
||||
describe('GL maps and the app schemes', () => {
|
||||
it('FE-NATIVE-GLSCHEME-001: in the iOS app the GL maps load straight from their servers, the raster store stays', () => {
|
||||
expect(vi.mocked(isNativeIos)()).toBe(true);
|
||||
expect(vi.mocked(isNativeApp)()).toBe(true);
|
||||
expect(vi.mocked(hasNativeFeature)('tileCache')).toBe(true);
|
||||
expect(GL_MAPS_THROUGH_APP_SCHEMES).toBe(false);
|
||||
|
||||
const style = 'https://tiles.openfreemap.org/styles/positron';
|
||||
expect(offlineStyle(style)).toBe(style);
|
||||
const addProtocol = vi.fn();
|
||||
installOfflineProtocol({ addProtocol });
|
||||
expect(addProtocol).not.toHaveBeenCalled();
|
||||
|
||||
const tile = 'https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/1/1/1.vector.pbf';
|
||||
expect(mapboxTileCacheRequest(tile, 'Tile')).toEqual({ url: tile });
|
||||
expect(glTileStoreActive()).toBe(false);
|
||||
expect(tileCacheActive()).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Whether the GL maps (the Leaflet map's vector basemap and Mapbox GL) read
|
||||
* their style and tiles through the app's own URL schemes, trek-offline:// and
|
||||
* trek-tile://, for the offline copy.
|
||||
*
|
||||
* Off: on iPadOS 26 both drew nothing in the app (the vector basemap white,
|
||||
* Mapbox black) while the 3D map, the Mapbox preview in the settings and the
|
||||
* raster maps, which do not go through those schemes for a GL map, drew
|
||||
* normally. The same maps draw normally in a browser. Until that is traced on a
|
||||
* device, the GL maps load straight from their servers in the app, as they do
|
||||
* in a browser, and keep no offline copy; the raster maps (Topo, satellite, a
|
||||
* raster template of the user's) keep going through the tile store.
|
||||
*/
|
||||
export const GL_MAPS_THROUGH_APP_SCHEMES = false;
|
||||
@@ -10,6 +10,8 @@ import {
|
||||
import { isNativeIos } from './platform';
|
||||
|
||||
vi.mock('./platform', () => ({ isNativeIos: vi.fn() }));
|
||||
// The mechanism is what is tested here; whether the GL maps use it is glSchemes.ts's switch.
|
||||
vi.mock('./glSchemes', () => ({ GL_MAPS_THROUGH_APP_SCHEMES: true }));
|
||||
|
||||
const cached = new Map<string, Response>();
|
||||
const cache = { match: vi.fn(async (url: string) => cached.get(url)?.clone()) };
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { AddProtocolAction, GetResourceResponse, RequestParameters } from 'maplibre-gl';
|
||||
import { VECTOR_CACHE } from '../sync/glPrefetcher';
|
||||
import { GL_MAPS_THROUGH_APP_SCHEMES } from './glSchemes';
|
||||
import { isNativeIos } from './platform';
|
||||
|
||||
/**
|
||||
@@ -20,7 +21,7 @@ const OFFLINE_SCHEME = 'trek-offline';
|
||||
const PREFIX = `${OFFLINE_SCHEME}://`;
|
||||
|
||||
function offlineTilesActive(): boolean {
|
||||
return isNativeIos() && typeof caches !== 'undefined';
|
||||
return GL_MAPS_THROUGH_APP_SCHEMES && isNativeIos() && typeof caches !== 'undefined';
|
||||
}
|
||||
|
||||
export function toOfflineUrl(url: string): string {
|
||||
|
||||
@@ -5,6 +5,8 @@ import { mapboxTileCacheRequest, nativeRasterTemplate, tileCacheActive, toTileCa
|
||||
|
||||
vi.mock('./platform', () => ({ isNativeIos: vi.fn(), isNativeApp: vi.fn() }));
|
||||
vi.mock('./capabilities', () => ({ hasNativeFeature: vi.fn() }));
|
||||
// The mechanism is what is tested here; whether the GL maps use it is glSchemes.ts's switch.
|
||||
vi.mock('./glSchemes', () => ({ GL_MAPS_THROUGH_APP_SCHEMES: true }));
|
||||
|
||||
beforeEach(() => {
|
||||
vi.mocked(isNativeIos).mockReturnValue(true);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { hasNativeFeature } from './capabilities';
|
||||
import { GL_MAPS_THROUGH_APP_SCHEMES } from './glSchemes';
|
||||
import { isNativeApp, isNativeIos } from './platform';
|
||||
|
||||
/**
|
||||
@@ -27,6 +28,11 @@ export function tileCacheActive(): boolean {
|
||||
return isNativeApp() && hasNativeFeature('tileCache');
|
||||
}
|
||||
|
||||
/** Whether a GL map keeps what it showed in the store (see glSchemes.ts for why not, for now). */
|
||||
export function glTileStoreActive(): boolean {
|
||||
return GL_MAPS_THROUGH_APP_SCHEMES && tileSchemeActive();
|
||||
}
|
||||
|
||||
/** Whether URLs go through the trek-tile:// scheme: the iOS store only. */
|
||||
function tileSchemeActive(): boolean {
|
||||
return isNativeIos() && hasNativeFeature('tileCache');
|
||||
@@ -61,7 +67,7 @@ const CACHED_RESOURCES = new Set([
|
||||
* Mapbox's servers go through the store, events and sessions never do.
|
||||
*/
|
||||
export function mapboxTileCacheRequest(url: string, resourceType?: string): { url: string } {
|
||||
if (!tileSchemeActive() || !MAPBOX_HOST.test(url)) return { url };
|
||||
if (!glTileStoreActive() || !MAPBOX_HOST.test(url)) return { url };
|
||||
if (resourceType && !CACHED_RESOURCES.has(resourceType)) return { url };
|
||||
return { url: toTileCacheUrl(url) };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user