@a16n/web-sim 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -2
- package/bin/cli.ts +255 -0
- package/bin/web-sim.js +39 -0
- package/overrides/@backpackapp-io/react-native-toast/overrides.ts +15 -0
- package/overrides/@react-native-firebase/app/overrides.ts +34 -0
- package/overrides/@tiktok-for-business/react-native-sdk/NativeTiktokSdk.ts +29 -0
- package/overrides/@tiktok-for-business/react-native-sdk/overrides.ts +9 -0
- package/overrides/expo-application/ExpoApplication.ts +81 -0
- package/overrides/expo-application/overrides.ts +16 -0
- package/overrides/expo-background-task/ExpoBackgroundTaskModule.ts +30 -0
- package/overrides/expo-background-task/overrides.ts +9 -0
- package/overrides/expo-constants/ExponentConstants.ts +66 -0
- package/overrides/expo-constants/overrides.ts +9 -0
- package/overrides/expo-device/ExpoDevice.ts +104 -0
- package/overrides/expo-device/overrides.ts +9 -0
- package/overrides/expo-glass-effect/GlassContainer.tsx +9 -0
- package/overrides/expo-glass-effect/GlassView.tsx +95 -0
- package/overrides/expo-glass-effect/availability.ts +14 -0
- package/overrides/expo-glass-effect/overrides.ts +14 -0
- package/overrides/expo-haptics/Haptics.ts +67 -0
- package/overrides/expo-haptics/overrides.ts +5 -0
- package/overrides/expo-mail-composer/ExpoMailComposer.ts +40 -0
- package/overrides/expo-mail-composer/overrides.ts +9 -0
- package/overrides/expo-mesh-gradient/MeshGradientView.tsx +44 -0
- package/overrides/expo-mesh-gradient/overrides.ts +9 -0
- package/overrides/expo-modules-core/overrides.ts +12 -0
- package/overrides/expo-navigation-bar/ExpoNavigationBar.ts +29 -0
- package/overrides/expo-navigation-bar/NavigationBar.ts +43 -0
- package/overrides/expo-navigation-bar/overrides.ts +12 -0
- package/overrides/expo-router/NativeStackView.tsx +74 -0
- package/overrides/expo-router/NativeTabsView.tsx +263 -0
- package/overrides/expo-router/SafeAreaProvider.ts +6 -0
- package/overrides/expo-router/overrides.ts +23 -0
- package/overrides/expo-router/statusBarRequests.ts +51 -0
- package/overrides/expo-screen-orientation/ExpoScreenOrientation.ts +173 -0
- package/overrides/expo-screen-orientation/overrides.ts +21 -0
- package/overrides/expo-sharing/SharingNativeModule.ts +21 -0
- package/overrides/expo-sharing/overrides.ts +9 -0
- package/overrides/expo-sms/ExpoSMS.ts +24 -0
- package/overrides/expo-sms/overrides.ts +9 -0
- package/overrides/expo-splash-screen/SplashScreen.ts +25 -0
- package/overrides/expo-splash-screen/overrides.ts +5 -0
- package/overrides/expo-status-bar/StatusBar.tsx +44 -0
- package/overrides/expo-status-bar/overrides.ts +5 -0
- package/overrides/expo-store-review/ExpoStoreReview.ts +18 -0
- package/overrides/expo-store-review/overrides.ts +9 -0
- package/overrides/expo-symbols/SymbolView.tsx +192 -0
- package/overrides/expo-symbols/overrides.ts +9 -0
- package/overrides/expo-system-ui/ExpoSystemUI.ts +34 -0
- package/overrides/expo-system-ui/overrides.ts +9 -0
- package/overrides/expo-task-manager/ExpoTaskManager.ts +39 -0
- package/overrides/expo-task-manager/overrides.ts +9 -0
- package/overrides/expo-tracking-transparency/ExpoTrackingTransparency.ts +30 -0
- package/overrides/expo-tracking-transparency/overrides.ts +11 -0
- package/overrides/expo-video/ExpoVideo.ts +16 -0
- package/overrides/expo-video/overrides.ts +9 -0
- package/overrides/lottie-react-native/LottieView.tsx +87 -0
- package/overrides/lottie-react-native/overrides.ts +9 -0
- package/overrides/react-native-pager-view/PagerViewNativeComponent.tsx +254 -0
- package/overrides/react-native-pager-view/overrides.ts +9 -0
- package/overrides/react-native-reanimated/overrides.ts +28 -0
- package/overrides/react-native-safe-area-context/NativeSafeAreaProvider.tsx +40 -0
- package/overrides/react-native-safe-area-context/overrides.ts +12 -0
- package/overrides/react-native-share/NativeRNShare.ts +22 -0
- package/overrides/react-native-share/overrides.ts +12 -0
- package/overrides/react-native-share/platform.ts +14 -0
- package/overrides/react-native-turbo-image/TurboImage.tsx +101 -0
- package/overrides/react-native-turbo-image/overrides.ts +9 -0
- package/overrides/react-native-web/RefreshControl.tsx +57 -0
- package/overrides/react-native-web/overrides.ts +157 -0
- package/overrides/react-native-web/useElementLayout.ts +152 -0
- package/package.json +80 -4
- package/plugins/battery/overrides/expo-battery/ExpoBattery.ts +57 -0
- package/plugins/battery/overrides/expo-battery/overrides.ts +9 -0
- package/plugins/battery/plugin.ts +8 -0
- package/plugins/battery/shell.tsx +56 -0
- package/plugins/battery/state.ts +11 -0
- package/plugins/biometrics/overrides/expo-local-authentication/ExpoLocalAuthentication.ts +90 -0
- package/plugins/biometrics/overrides/expo-local-authentication/overrides.ts +11 -0
- package/plugins/biometrics/plugin.ts +8 -0
- package/plugins/biometrics/shell.tsx +88 -0
- package/plugins/biometrics/state.ts +41 -0
- package/plugins/brightness/app.ts +5 -0
- package/plugins/brightness/overrides/expo-brightness/Brightness.ts +98 -0
- package/plugins/brightness/overrides/expo-brightness/overrides.ts +10 -0
- package/plugins/brightness/plugin.ts +9 -0
- package/plugins/brightness/shell.tsx +55 -0
- package/plugins/brightness/state.ts +19 -0
- package/plugins/calendar/calendar.ts +299 -0
- package/plugins/calendar/overrides/expo-calendar/ExpoCalendar.ts +358 -0
- package/plugins/calendar/overrides/expo-calendar/LegacyExpoCalendar.ts +163 -0
- package/plugins/calendar/overrides/expo-calendar/overrides.ts +14 -0
- package/plugins/calendar/plugin.ts +8 -0
- package/plugins/calendar/shell.tsx +123 -0
- package/plugins/camera/overrides/expo-camera/ExpoCamera.tsx +269 -0
- package/plugins/camera/overrides/expo-camera/ExpoCameraManager.ts +56 -0
- package/plugins/camera/overrides/expo-camera/overrides.ts +12 -0
- package/plugins/camera/plugin.ts +9 -0
- package/plugins/camera/shell.tsx +107 -0
- package/plugins/camera/state.ts +61 -0
- package/plugins/clipboard/overrides/expo-clipboard/ExpoClipboard.ts +138 -0
- package/plugins/clipboard/overrides/expo-clipboard/overrides.ts +9 -0
- package/plugins/clipboard/plugin.ts +8 -0
- package/plugins/clipboard/shell.tsx +122 -0
- package/plugins/clipboard/state.ts +93 -0
- package/plugins/clock/app.ts +25 -0
- package/plugins/clock/plugin.ts +8 -0
- package/plugins/clock/shell.tsx +225 -0
- package/plugins/clock/state.ts +12 -0
- package/plugins/contacts/contacts.ts +125 -0
- package/plugins/contacts/overrides/expo-contacts/ExpoContacts.ts +153 -0
- package/plugins/contacts/overrides/expo-contacts/ExpoContactsNext.ts +232 -0
- package/plugins/contacts/overrides/expo-contacts/overrides.ts +12 -0
- package/plugins/contacts/plugin.ts +8 -0
- package/plugins/contacts/shell.tsx +109 -0
- package/plugins/home-indicator/app.ts +5 -0
- package/plugins/home-indicator/plugin.ts +9 -0
- package/plugins/home-indicator/requests.ts +48 -0
- package/plugins/home-indicator/shell.tsx +68 -0
- package/plugins/home-indicator/state.ts +31 -0
- package/plugins/keep-awake/app.ts +5 -0
- package/plugins/keep-awake/overrides/expo-keep-awake/ExpoKeepAwake.ts +27 -0
- package/plugins/keep-awake/overrides/expo-keep-awake/overrides.ts +9 -0
- package/plugins/keep-awake/plugin.ts +9 -0
- package/plugins/keep-awake/shell.tsx +80 -0
- package/plugins/keep-awake/state.ts +12 -0
- package/plugins/keyboard/Keyboard.tsx +354 -0
- package/plugins/keyboard/app.ts +90 -0
- package/plugins/keyboard/controller.ts +384 -0
- package/plugins/keyboard/fields.ts +244 -0
- package/plugins/keyboard/icons.tsx +283 -0
- package/plugins/keyboard/keyboard.css +362 -0
- package/plugins/keyboard/layouts/android.ts +175 -0
- package/plugins/keyboard/layouts/index.ts +10 -0
- package/plugins/keyboard/layouts/ios.ts +219 -0
- package/plugins/keyboard/layouts/types.ts +80 -0
- package/plugins/keyboard/overrides/react-native-keyboard-controller/KeyboardController.tsx +470 -0
- package/plugins/keyboard/overrides/react-native-keyboard-controller/overrides.ts +9 -0
- package/plugins/keyboard/plugin.ts +13 -0
- package/plugins/keyboard/shell.tsx +133 -0
- package/plugins/keyboard/state.ts +92 -0
- package/plugins/keyboard/suggestions.ts +63 -0
- package/plugins/keyboard/taps.ts +77 -0
- package/plugins/keyboard/typing.ts +112 -0
- package/plugins/locale/app.ts +232 -0
- package/plugins/locale/locale.ts +143 -0
- package/plugins/locale/overrides/expo-localization/ExpoLocalization.ts +41 -0
- package/plugins/locale/overrides/expo-localization/overrides.ts +9 -0
- package/plugins/locale/plugin.ts +9 -0
- package/plugins/locale/shell.tsx +147 -0
- package/plugins/locale/state.ts +36 -0
- package/plugins/location/geo.ts +56 -0
- package/plugins/location/overrides/expo-location/ExpoLocation.ts +235 -0
- package/plugins/location/overrides/expo-location/overrides.ts +11 -0
- package/plugins/location/places.ts +38 -0
- package/plugins/location/plugin.ts +8 -0
- package/plugins/location/shell.tsx +188 -0
- package/plugins/location/state.ts +51 -0
- package/plugins/motion/overrides/expo-sensors/DeviceSensor.ts +169 -0
- package/plugins/motion/overrides/expo-sensors/ExponentPedometer.ts +54 -0
- package/plugins/motion/overrides/expo-sensors/overrides.ts +14 -0
- package/plugins/motion/plugin.ts +8 -0
- package/plugins/motion/sensors.ts +116 -0
- package/plugins/motion/shell.tsx +136 -0
- package/plugins/motion/state.ts +46 -0
- package/plugins/network/app.ts +400 -0
- package/plugins/network/overrides/expo-network/ExpoNetwork.ts +51 -0
- package/plugins/network/overrides/expo-network/overrides.ts +9 -0
- package/plugins/network/plugin.ts +8 -0
- package/plugins/network/shell.tsx +67 -0
- package/plugins/network/state.ts +29 -0
- package/plugins/notifications/center.ts +255 -0
- package/plugins/notifications/content.ts +36 -0
- package/plugins/notifications/overrides/expo-notifications/NotificationsModule.ts +175 -0
- package/plugins/notifications/overrides/expo-notifications/channels.ts +108 -0
- package/plugins/notifications/overrides/expo-notifications/getDevicePushTokenAsync.ts +19 -0
- package/plugins/notifications/overrides/expo-notifications/getExpoPushTokenAsync.ts +16 -0
- package/plugins/notifications/overrides/expo-notifications/overrides.ts +36 -0
- package/plugins/notifications/plugin.ts +8 -0
- package/plugins/notifications/shell.tsx +192 -0
- package/plugins/notifications/state.ts +56 -0
- package/plugins/notifications/tokens.ts +47 -0
- package/plugins/notifications/trigger.ts +107 -0
- package/plugins/permissions/plugin.ts +6 -0
- package/plugins/permissions/shell.tsx +50 -0
- package/plugins/permissions/state.ts +38 -0
- package/plugins/photos/appLibrary.ts +114 -0
- package/plugins/photos/library.ts +322 -0
- package/plugins/photos/overrides/expo-image-picker/ExponentImagePicker.ts +153 -0
- package/plugins/photos/overrides/expo-image-picker/overrides.ts +13 -0
- package/plugins/photos/overrides/expo-media-library/ExpoMediaLibrary.ts +235 -0
- package/plugins/photos/overrides/expo-media-library/NativeMediaLibraryModule.ts +318 -0
- package/plugins/photos/overrides/expo-media-library/overrides.ts +19 -0
- package/plugins/photos/plugin.ts +8 -0
- package/plugins/photos/samples.ts +367 -0
- package/plugins/photos/shell.tsx +164 -0
- package/plugins/photos/state.ts +88 -0
- package/plugins/storage/files.ts +351 -0
- package/plugins/storage/overrides/expo-file-system/ExpoFileSystem.ts +770 -0
- package/plugins/storage/overrides/expo-file-system/ExponentFileSystem.ts +196 -0
- package/plugins/storage/overrides/expo-file-system/overrides.ts +13 -0
- package/plugins/storage/overrides/expo-secure-store/ExpoSecureStore.ts +75 -0
- package/plugins/storage/overrides/expo-secure-store/overrides.ts +9 -0
- package/plugins/storage/plugin.ts +8 -0
- package/plugins/storage/reset.ts +136 -0
- package/plugins/storage/secure.ts +71 -0
- package/plugins/storage/shell.tsx +365 -0
- package/plugins/storage/state.ts +13 -0
- package/src/client/app/appDocument.ts +129 -0
- package/src/client/app/appFocus.ts +97 -0
- package/src/client/app/console.ts +118 -0
- package/src/client/app/fonts.ts +76 -0
- package/src/client/app/main.tsx +99 -0
- package/src/client/app/routeContext.ts +45 -0
- package/src/client/app/touch.ts +640 -0
- package/src/client/entry.ts +20 -0
- package/src/client/modules.d.ts +8 -0
- package/src/client/react-native/app.ts +57 -0
- package/src/client/react-native/deep.ts +13 -0
- package/src/client/react-native/keyboard.tsx +192 -0
- package/src/client/react-native/library.ts +256 -0
- package/src/client/shell/Cookies.tsx +95 -0
- package/src/client/shell/LogDrawer.tsx +415 -0
- package/src/client/shell/PhotoPicker.tsx +174 -0
- package/src/client/shell/PluginOverlays.tsx +42 -0
- package/src/client/shell/PluginPanels.tsx +82 -0
- package/src/client/shell/ResetApp.tsx +87 -0
- package/src/client/shell/Resizer.tsx +99 -0
- package/src/client/shell/Shell.tsx +531 -0
- package/src/client/shell/SystemBars.tsx +376 -0
- package/src/client/shell/SystemCamera.tsx +181 -0
- package/src/client/shell/SystemOverlay.tsx +422 -0
- package/src/client/shell/SystemSheets.tsx +462 -0
- package/src/client/shell/backdrop.ts +229 -0
- package/src/client/shell/control.ts +91 -0
- package/src/client/shell/events.ts +226 -0
- package/src/client/shell/geometry.ts +68 -0
- package/src/client/shell/host.ts +492 -0
- package/src/client/shell/icons.tsx +34 -0
- package/src/client/shell/logFeed.ts +102 -0
- package/src/client/shell/main.tsx +22 -0
- package/src/client/shell/permissionCopy.ts +169 -0
- package/src/client/shell/plugins.ts +266 -0
- package/src/client/shell/popout.ts +185 -0
- package/src/client/shell/popover.ts +27 -0
- package/src/client/shell/shell.css +878 -0
- package/src/client/shell/statusTime.ts +31 -0
- package/src/client/shell/tooltips.ts +104 -0
- package/src/client/virtual.d.ts +23 -0
- package/src/devices/catalog.ts +223 -0
- package/src/devices/types.ts +83 -0
- package/src/node/appInfo.ts +188 -0
- package/src/node/appSource.ts +140 -0
- package/src/node/config.ts +180 -0
- package/src/node/control.ts +144 -0
- package/src/node/doctor.ts +199 -0
- package/src/node/events/cli.ts +206 -0
- package/src/node/events/shared.ts +238 -0
- package/src/node/events/store.ts +266 -0
- package/src/node/fonts.ts +377 -0
- package/src/node/index.ts +5 -0
- package/src/node/overrides/define.ts +56 -0
- package/src/node/overrides/packages.ts +136 -0
- package/src/node/overrides/platformPatch.ts +56 -0
- package/src/node/overrides/plugin.ts +169 -0
- package/src/node/overrides/registry.ts +258 -0
- package/src/node/paths.ts +18 -0
- package/src/node/platform.ts +171 -0
- package/src/node/plugins.ts +98 -0
- package/src/node/proxy.ts +421 -0
- package/src/node/server.ts +254 -0
- package/src/node/worklets.ts +86 -0
- package/src/plugin/index.ts +33 -0
- package/src/plugin/types.ts +127 -0
- package/src/plugin/ui.tsx +562 -0
- package/src/runtime/clock.ts +112 -0
- package/src/runtime/draw.ts +196 -0
- package/src/runtime/index.ts +519 -0
- package/src/runtime/media.ts +379 -0
- package/src/runtime/records.ts +76 -0
- package/src/runtime/timezone.ts +81 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { CodedError } from 'expo'
|
|
2
|
+
import { getPermission, permissionResponse, platform, type PermissionResponse, plugin, realNow, requestPermission } from 'web-sim/runtime'
|
|
3
|
+
import { distance } from '../../geo.ts'
|
|
4
|
+
import { type Place, PLACES } from '../../places.ts'
|
|
5
|
+
import { currentPosition, INITIAL_LOCATION, type LocationState } from '../../state.ts'
|
|
6
|
+
// @ts-expect-error Resolved inside the package: its web event emitter, which the module's subscribers listen to.
|
|
7
|
+
import { LocationEventEmitter } from './LocationEventEmitter'
|
|
8
|
+
|
|
9
|
+
const location = () => plugin<LocationState>('location', INITIAL_LOCATION)
|
|
10
|
+
|
|
11
|
+
/** How far reverse geocoding looks for a preset place. */
|
|
12
|
+
const GEOCODE_RADIUS = 100_000
|
|
13
|
+
|
|
14
|
+
type Watches = Map<number, () => void>
|
|
15
|
+
|
|
16
|
+
/** Each watch's teardown, kept on the app's window so a second copy of this module sees them. */
|
|
17
|
+
function watches(): Watches {
|
|
18
|
+
const holder = window as unknown as { __webSimLocationWatches?: Watches }
|
|
19
|
+
holder.__webSimLocationWatches ??= new Map()
|
|
20
|
+
return holder.__webSimLocationWatches
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function removeWatch(watchId: number) {
|
|
24
|
+
watches().get(watchId)?.()
|
|
25
|
+
watches().delete(watchId)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function report(state: LocationState, age = 0) {
|
|
29
|
+
const position = currentPosition(state, platform())
|
|
30
|
+
const ios = platform() === 'ios'
|
|
31
|
+
const moving = position.speed > 0
|
|
32
|
+
return {
|
|
33
|
+
coords: {
|
|
34
|
+
latitude: position.latitude,
|
|
35
|
+
longitude: position.longitude,
|
|
36
|
+
altitude: position.altitude,
|
|
37
|
+
accuracy: position.accuracy,
|
|
38
|
+
altitudeAccuracy: ios ? 10 : 1,
|
|
39
|
+
// iOS has no course or speed while still: it reports -1 for both.
|
|
40
|
+
heading: ios && !moving ? -1 : position.heading,
|
|
41
|
+
speed: ios && !moving ? -1 : position.speed,
|
|
42
|
+
},
|
|
43
|
+
timestamp: Date.now() - age,
|
|
44
|
+
...(platform() === 'android' && { mocked: false }),
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function heading(state: LocationState) {
|
|
49
|
+
const { heading } = currentPosition(state, platform())
|
|
50
|
+
return { trueHeading: heading, magHeading: heading, accuracy: 3 }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function ensureAvailable() {
|
|
54
|
+
if (!location().get().servicesEnabled) {
|
|
55
|
+
throw platform() === 'ios'
|
|
56
|
+
? new CodedError('ERR_LOCATION_SERVICES_DISABLED', 'Location services are disabled')
|
|
57
|
+
: new CodedError('ERR_LOCATION_SETTINGS_UNSATISFIED', 'Location request failed due to unsatisfied device settings')
|
|
58
|
+
}
|
|
59
|
+
if (getPermission('location').status !== 'granted') {
|
|
60
|
+
throw new CodedError('ERR_LOCATION_UNAUTHORIZED', 'Not authorized to use location services')
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Whether a watch may hear a fix now: services on and permission held, as when it began. */
|
|
65
|
+
function canReport(state: LocationState) {
|
|
66
|
+
return state.servicesEnabled && getPermission('location').status === 'granted'
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function details(foreground: PermissionResponse, background: PermissionResponse) {
|
|
70
|
+
return platform() === 'ios'
|
|
71
|
+
? { ios: { scope: background.granted ? 'always' : foreground.granted ? 'whenInUse' : 'none', accuracy: 'full' } }
|
|
72
|
+
: { android: { accuracy: foreground.granted ? 'fine' : 'none' } }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function foregroundResponse() {
|
|
76
|
+
const foreground = getPermission('location')
|
|
77
|
+
return { ...foreground, ...details(foreground, getPermission('location-background')) }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function backgroundResponse() {
|
|
81
|
+
const background = getPermission('location-background')
|
|
82
|
+
return { ...background, ...details(getPermission('location'), background) }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function address(place: Place) {
|
|
86
|
+
const street = [place.streetNumber, place.street].filter(Boolean).join(' ')
|
|
87
|
+
return {
|
|
88
|
+
name: platform() === 'ios' ? place.name : street || place.name,
|
|
89
|
+
streetNumber: place.streetNumber,
|
|
90
|
+
street: place.street,
|
|
91
|
+
district: place.district,
|
|
92
|
+
city: place.city,
|
|
93
|
+
subregion: place.subregion,
|
|
94
|
+
region: place.region,
|
|
95
|
+
postalCode: place.postalCode,
|
|
96
|
+
country: place.country,
|
|
97
|
+
isoCountryCode: place.isoCountryCode,
|
|
98
|
+
timezone: platform() === 'ios' ? place.timezone : null,
|
|
99
|
+
formattedAddress: platform() === 'android' ? [street, `${place.city}, ${place.region} ${place.postalCode ?? ''}`.trim(), place.country].filter(Boolean).join(', ') : null,
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
type WatchOptions = { timeInterval?: number; distanceInterval?: number }
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* `expo-location` on the simulated phone: the location panel's position, which its routes move; its services
|
|
107
|
+
* switch; permissions from the simulator; and geocoding from the panel's preset places.
|
|
108
|
+
*/
|
|
109
|
+
export default {
|
|
110
|
+
async getProviderStatusAsync() {
|
|
111
|
+
const enabled = location().get().servicesEnabled
|
|
112
|
+
return {
|
|
113
|
+
locationServicesEnabled: enabled,
|
|
114
|
+
backgroundModeEnabled: getPermission('location-background').granted,
|
|
115
|
+
...(platform() === 'android' && { gpsAvailable: enabled, networkAvailable: enabled, passiveAvailable: true }),
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
async hasServicesEnabledAsync() {
|
|
119
|
+
return location().get().servicesEnabled
|
|
120
|
+
},
|
|
121
|
+
async enableNetworkProviderAsync() {},
|
|
122
|
+
|
|
123
|
+
async getLastKnownPositionAsync(options: { maxAge?: number } = {}) {
|
|
124
|
+
ensureAvailable()
|
|
125
|
+
const last = report(location().get(), 30_000)
|
|
126
|
+
return options.maxAge !== undefined && options.maxAge < 30_000 ? null : last
|
|
127
|
+
},
|
|
128
|
+
async getCurrentPositionAsync() {
|
|
129
|
+
ensureAvailable()
|
|
130
|
+
return report(location().get())
|
|
131
|
+
},
|
|
132
|
+
/**
|
|
133
|
+
* Reports at once, then as the position moves at least `distanceInterval` metres. Android's fused provider also
|
|
134
|
+
* keeps reporting every `timeInterval` (default 5 s) and never more often; iOS has no time interval.
|
|
135
|
+
*/
|
|
136
|
+
async watchPositionImplAsync(watchId: number, options: WatchOptions = {}) {
|
|
137
|
+
ensureAvailable()
|
|
138
|
+
const android = platform() === 'android'
|
|
139
|
+
const minDistance = options.distanceInterval ?? 0
|
|
140
|
+
const interval = Math.max(options.timeInterval ?? 5000, android ? 1000 : 0)
|
|
141
|
+
let last = { at: 0, position: currentPosition(location().get(), platform()) }
|
|
142
|
+
const emit = (state: LocationState) => {
|
|
143
|
+
last = { at: realNow(), position: currentPosition(state, platform()) }
|
|
144
|
+
LocationEventEmitter.emit('Expo.locationChanged', { watchId, location: report(state) })
|
|
145
|
+
}
|
|
146
|
+
const first = setTimeout(() => emit(location().get()), 0)
|
|
147
|
+
const stopWatching = location().watch((next) => {
|
|
148
|
+
const position = currentPosition(next, platform())
|
|
149
|
+
const moved = JSON.stringify(position) !== JSON.stringify(last.position) && distance(last.position, position) >= minDistance
|
|
150
|
+
const waited = !android || realNow() - last.at >= interval
|
|
151
|
+
if (canReport(next) && moved && waited) {
|
|
152
|
+
emit(next)
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
const repeat = android ? setInterval(() => canReport(location().get()) && realNow() - last.at >= interval && emit(location().get()), interval) : undefined
|
|
156
|
+
removeWatch(watchId)
|
|
157
|
+
watches().set(watchId, () => {
|
|
158
|
+
clearTimeout(first)
|
|
159
|
+
clearInterval(repeat)
|
|
160
|
+
stopWatching()
|
|
161
|
+
})
|
|
162
|
+
return watchId
|
|
163
|
+
},
|
|
164
|
+
async removeWatchAsync(watchId: number) {
|
|
165
|
+
removeWatch(watchId)
|
|
166
|
+
},
|
|
167
|
+
/** The compass follows the position's heading: at once, then as it turns. */
|
|
168
|
+
async watchDeviceHeading(headingId: number) {
|
|
169
|
+
const emit = (state: LocationState) => LocationEventEmitter.emit('Expo.headingChanged', { watchId: headingId, heading: heading(state) })
|
|
170
|
+
const first = setTimeout(() => emit(location().get()), 0)
|
|
171
|
+
const stopWatching = location().watch((next, previous) => {
|
|
172
|
+
if (currentPosition(next, platform()).heading !== currentPosition(previous, platform()).heading) {
|
|
173
|
+
emit(next)
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
removeWatch(headingId)
|
|
177
|
+
watches().set(headingId, () => {
|
|
178
|
+
clearTimeout(first)
|
|
179
|
+
stopWatching()
|
|
180
|
+
})
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
async geocodeAsync(query: string) {
|
|
184
|
+
const words = query.toLowerCase().split(/[\s,]+/).filter((word) => word.length > 2)
|
|
185
|
+
const match = PLACES.find((place) => {
|
|
186
|
+
const text = [place.name, place.street, place.city, place.region, place.country, place.postalCode].join(' ').toLowerCase()
|
|
187
|
+
return words.length > 0 && words.every((word) => text.includes(word))
|
|
188
|
+
})
|
|
189
|
+
return match === undefined ? [] : [{ latitude: match.latitude, longitude: match.longitude, altitude: match.altitude, accuracy: 50 }]
|
|
190
|
+
},
|
|
191
|
+
/** The nearest of the panel's preset places, within 100 km. */
|
|
192
|
+
async reverseGeocodeAsync(point: { latitude: number; longitude: number }) {
|
|
193
|
+
const nearest = [...PLACES].sort((a, b) => distance(a, point) - distance(b, point))[0]
|
|
194
|
+
return distance(nearest, point) < GEOCODE_RADIUS ? [address(nearest)] : []
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
async getForegroundPermissionsAsync() {
|
|
198
|
+
return foregroundResponse()
|
|
199
|
+
},
|
|
200
|
+
async requestForegroundPermissionsAsync() {
|
|
201
|
+
await requestPermission('location')
|
|
202
|
+
return foregroundResponse()
|
|
203
|
+
},
|
|
204
|
+
async getBackgroundPermissionsAsync() {
|
|
205
|
+
return backgroundResponse()
|
|
206
|
+
},
|
|
207
|
+
async requestBackgroundPermissionsAsync() {
|
|
208
|
+
// Background location is asked for once the app has it in the foreground.
|
|
209
|
+
const foreground = await requestPermission('location')
|
|
210
|
+
if (!foreground.granted) {
|
|
211
|
+
return { ...permissionResponse('denied'), ...details(foreground, permissionResponse('denied')) }
|
|
212
|
+
}
|
|
213
|
+
await requestPermission('location-background')
|
|
214
|
+
return backgroundResponse()
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
async getMotionActivityPermissionsAsync() {
|
|
218
|
+
return getPermission('motion')
|
|
219
|
+
},
|
|
220
|
+
async requestMotionActivityPermissionsAsync() {
|
|
221
|
+
return requestPermission('motion')
|
|
222
|
+
},
|
|
223
|
+
async watchMotionActivityImplAsync() {},
|
|
224
|
+
|
|
225
|
+
async startLocationUpdatesAsync() {},
|
|
226
|
+
async stopLocationUpdatesAsync() {},
|
|
227
|
+
async hasStartedLocationUpdatesAsync() {
|
|
228
|
+
return false
|
|
229
|
+
},
|
|
230
|
+
async startGeofencingAsync() {},
|
|
231
|
+
async stopGeofencingAsync() {},
|
|
232
|
+
async hasStartedGeofencingAsync() {
|
|
233
|
+
return false
|
|
234
|
+
},
|
|
235
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineOverrides } from '../../../../src/node/overrides/define.ts'
|
|
2
|
+
import { simulatedPlatform } from '../../../../src/node/overrides/platformPatch.ts'
|
|
3
|
+
|
|
4
|
+
export default defineOverrides('expo-location', [
|
|
5
|
+
{
|
|
6
|
+
versions: '>=58 <59',
|
|
7
|
+
note: "the location panel's position, routes and services switch; geocoding from its preset places; location permissions",
|
|
8
|
+
files: { 'build/ExpoLocation.web.js': './ExpoLocation.ts' },
|
|
9
|
+
patch: [simulatedPlatform('build/Location.js')],
|
|
10
|
+
},
|
|
11
|
+
])
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The panel's preset places, which geocoding also answers from, so an address the app looks up matches the panel.
|
|
3
|
+
* The first two are where the platform simulators put the phone: Apple Park in Xcode's Simulator, Google's
|
|
4
|
+
* headquarters in the Android emulator.
|
|
5
|
+
*/
|
|
6
|
+
export type Place = {
|
|
7
|
+
id: string
|
|
8
|
+
latitude: number
|
|
9
|
+
longitude: number
|
|
10
|
+
altitude: number
|
|
11
|
+
name: string
|
|
12
|
+
streetNumber: string | null
|
|
13
|
+
street: string | null
|
|
14
|
+
district: string | null
|
|
15
|
+
city: string
|
|
16
|
+
subregion: string | null
|
|
17
|
+
region: string
|
|
18
|
+
postalCode: string | null
|
|
19
|
+
country: string
|
|
20
|
+
isoCountryCode: string
|
|
21
|
+
timezone: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const PLACES: Place[] = [
|
|
25
|
+
{ id: 'apple-park', latitude: 37.3349, longitude: -122.009, altitude: 25, name: 'Apple Park', streetNumber: '1', street: 'Apple Park Way', district: null, city: 'Cupertino', subregion: 'Santa Clara County', region: 'CA', postalCode: '95014', country: 'United States', isoCountryCode: 'US', timezone: 'America/Los_Angeles' },
|
|
26
|
+
{ id: 'googleplex', latitude: 37.422, longitude: -122.0841, altitude: 5, name: 'Googleplex', streetNumber: '1600', street: 'Amphitheatre Parkway', district: null, city: 'Mountain View', subregion: 'Santa Clara County', region: 'CA', postalCode: '94043', country: 'United States', isoCountryCode: 'US', timezone: 'America/Los_Angeles' },
|
|
27
|
+
{ id: 'san-francisco', latitude: 37.7955, longitude: -122.3937, altitude: 4, name: 'Ferry Building', streetNumber: '1', street: 'Ferry Building', district: 'Embarcadero', city: 'San Francisco', subregion: 'San Francisco County', region: 'CA', postalCode: '94111', country: 'United States', isoCountryCode: 'US', timezone: 'America/Los_Angeles' },
|
|
28
|
+
{ id: 'new-york', latitude: 40.758, longitude: -73.9855, altitude: 15, name: 'Times Square', streetNumber: '1560', street: 'Broadway', district: 'Midtown', city: 'New York', subregion: 'New York County', region: 'NY', postalCode: '10036', country: 'United States', isoCountryCode: 'US', timezone: 'America/New_York' },
|
|
29
|
+
{ id: 'london', latitude: 51.5007, longitude: -0.1246, altitude: 10, name: 'Westminster', streetNumber: null, street: 'Bridge Street', district: 'Westminster', city: 'London', subregion: 'Greater London', region: 'England', postalCode: 'SW1A 0AA', country: 'United Kingdom', isoCountryCode: 'GB', timezone: 'Europe/London' },
|
|
30
|
+
{ id: 'paris', latitude: 48.8584, longitude: 2.2945, altitude: 35, name: 'Tour Eiffel', streetNumber: '5', street: 'Avenue Anatole France', district: '7e Arrondissement', city: 'Paris', subregion: 'Paris', region: 'Île-de-France', postalCode: '75007', country: 'France', isoCountryCode: 'FR', timezone: 'Europe/Paris' },
|
|
31
|
+
{ id: 'tokyo', latitude: 35.6586, longitude: 139.7454, altitude: 20, name: 'Tokyo Tower', streetNumber: '2-8', street: 'Shibakoen 4-chome', district: 'Minato', city: 'Tokyo', subregion: null, region: 'Tokyo', postalCode: '105-0011', country: 'Japan', isoCountryCode: 'JP', timezone: 'Asia/Tokyo' },
|
|
32
|
+
{ id: 'sydney', latitude: -33.8568, longitude: 151.2153, altitude: 5, name: 'Sydney Opera House', streetNumber: '2', street: 'Bennelong Point', district: null, city: 'Sydney', subregion: null, region: 'NSW', postalCode: '2000', country: 'Australia', isoCountryCode: 'AU', timezone: 'Australia/Sydney' },
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
/** Where the platform's simulator puts the phone. */
|
|
36
|
+
export function simulatorPlace(platform: 'ios' | 'android'): Place {
|
|
37
|
+
return PLACES[platform === 'ios' ? 0 : 1]
|
|
38
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { MapPinIcon } from '@phosphor-icons/react'
|
|
2
|
+
import { Button, defineShellPlugin, Field, NumberField, type PluginContext, Progress, Row, Select, Toggle } from 'web-sim/shell'
|
|
3
|
+
import { along, type Coordinates, distance, offset, pathLength } from './geo.ts'
|
|
4
|
+
import { PLACES, simulatorPlace } from './places.ts'
|
|
5
|
+
import { currentPosition, defaultAccuracy, INITIAL_LOCATION, type LocationState, type Position } from './state.ts'
|
|
6
|
+
|
|
7
|
+
/** How often a route moves the phone on: once a second, as a GPS fix. */
|
|
8
|
+
const TICK_MS = 1000
|
|
9
|
+
|
|
10
|
+
/** Route presets, as metres east and north of where the phone is, and the speed they go at. */
|
|
11
|
+
const PRESETS = {
|
|
12
|
+
walk: { name: 'Walk', speed: 1.4, legs: [[0, 0], [0, 150], [120, 150], [120, 320], [260, 320]] },
|
|
13
|
+
city: { name: 'City drive', speed: 12, legs: [[0, 0], [0, 500], [600, 500], [600, 1100], [1400, 1100], [1400, 600], [2000, 600]] },
|
|
14
|
+
freeway: { name: 'Freeway', speed: 30, legs: [[0, 0], [2000, 3000], [3000, 7000], [5500, 11000], [9000, 14000], [13000, 15500]] },
|
|
15
|
+
} as const
|
|
16
|
+
|
|
17
|
+
type PresetName = keyof typeof PRESETS
|
|
18
|
+
|
|
19
|
+
type RouteArgs = { points?: Coordinates[]; speed?: number; loop?: boolean; name?: string; preset?: PresetName }
|
|
20
|
+
type GoToArgs = Coordinates & { speed?: number }
|
|
21
|
+
|
|
22
|
+
type Context = PluginContext<LocationState>
|
|
23
|
+
|
|
24
|
+
function platform(context: Context) {
|
|
25
|
+
return context.sim().device.platform
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function startRoute(context: Context, points: Coordinates[], speed: number, loop: boolean, name: string) {
|
|
29
|
+
if (points.length < 2 || !(speed > 0)) {
|
|
30
|
+
throw new Error('A route needs two or more points and a speed above 0 m/s')
|
|
31
|
+
}
|
|
32
|
+
const here = currentPosition(context.state(), platform(context))
|
|
33
|
+
const start = along(points, 0)
|
|
34
|
+
context.set({
|
|
35
|
+
route: { name, points, speed, loop, travelled: 0, length: pathLength(points), paused: false },
|
|
36
|
+
position: { ...here, latitude: start.latitude, longitude: start.longitude, heading: start.heading, speed },
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Moves the phone along its route by one tick. At the end it loops, or stops there. */
|
|
41
|
+
function step(context: Context, seconds: number) {
|
|
42
|
+
const { route } = context.state()
|
|
43
|
+
if (route === null || route.paused) {
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
const here = currentPosition(context.state(), platform(context))
|
|
47
|
+
let travelled = route.travelled + route.speed * seconds
|
|
48
|
+
if (travelled >= route.length && !route.loop) {
|
|
49
|
+
const end = along(route.points, route.length)
|
|
50
|
+
context.set({ route: null, position: { ...here, latitude: end.latitude, longitude: end.longitude, heading: end.heading, speed: 0 } })
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
travelled = route.length > 0 ? travelled % route.length : 0
|
|
54
|
+
const point = along(route.points, travelled)
|
|
55
|
+
context.set({
|
|
56
|
+
route: { ...route, travelled },
|
|
57
|
+
position: { ...here, latitude: point.latitude, longitude: point.longitude, heading: point.heading, speed: route.speed },
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const km = (metres: number) => (metres < 1000 ? `${Math.round(metres)} m` : `${(metres / 1000).toFixed(1)} km`)
|
|
62
|
+
|
|
63
|
+
function nearestPlace(position: Coordinates) {
|
|
64
|
+
return PLACES.map((place) => ({ place, metres: distance(place, position) })).sort((a, b) => a.metres - b.metres)[0]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default defineShellPlugin<LocationState>({
|
|
68
|
+
id: 'location',
|
|
69
|
+
title: 'Location',
|
|
70
|
+
icon: MapPinIcon,
|
|
71
|
+
initialState: INITIAL_LOCATION,
|
|
72
|
+
actions: {
|
|
73
|
+
/** Moves to a point: at once, or at `speed` m/s in a straight line. */
|
|
74
|
+
goTo: (context, args) => {
|
|
75
|
+
const { latitude, longitude, speed } = args as GoToArgs
|
|
76
|
+
const here = currentPosition(context.state(), platform(context))
|
|
77
|
+
if (speed !== undefined && speed > 0) {
|
|
78
|
+
startRoute(context, [here, { latitude, longitude }], speed, false, 'Go to')
|
|
79
|
+
} else {
|
|
80
|
+
context.set({ route: null, position: { ...here, latitude, longitude, speed: 0 } })
|
|
81
|
+
}
|
|
82
|
+
return context.state()
|
|
83
|
+
},
|
|
84
|
+
/** Travels `points` at `speed` m/s, looping if `loop`; or a preset (`walk`, `city`, `freeway`) from here. */
|
|
85
|
+
route: (context, args) => {
|
|
86
|
+
const { points, speed, loop = false, name, preset } = (args ?? {}) as RouteArgs
|
|
87
|
+
if (preset !== undefined) {
|
|
88
|
+
const chosen = PRESETS[preset]
|
|
89
|
+
if (chosen === undefined) {
|
|
90
|
+
throw new Error(`No route preset '${preset}'. Presets: ${Object.keys(PRESETS).join(', ')}`)
|
|
91
|
+
}
|
|
92
|
+
const here = currentPosition(context.state(), platform(context))
|
|
93
|
+
startRoute(context, chosen.legs.map(([east, north]) => offset(here, east, north)), speed ?? chosen.speed, loop, chosen.name)
|
|
94
|
+
} else {
|
|
95
|
+
startRoute(context, points ?? [], speed ?? 1.4, loop, name ?? 'Route')
|
|
96
|
+
}
|
|
97
|
+
return context.state()
|
|
98
|
+
},
|
|
99
|
+
pause: (context) => {
|
|
100
|
+
const { route } = context.state()
|
|
101
|
+
if (route !== null) {
|
|
102
|
+
context.set({ route: { ...route, paused: true }, position: { ...currentPosition(context.state(), platform(context)), speed: 0 } })
|
|
103
|
+
}
|
|
104
|
+
return context.state()
|
|
105
|
+
},
|
|
106
|
+
resume: (context) => {
|
|
107
|
+
const { route } = context.state()
|
|
108
|
+
if (route !== null) {
|
|
109
|
+
context.set({ route: { ...route, paused: false }, position: { ...currentPosition(context.state(), platform(context)), speed: route.speed } })
|
|
110
|
+
}
|
|
111
|
+
return context.state()
|
|
112
|
+
},
|
|
113
|
+
/** Ends the route where the phone is. */
|
|
114
|
+
stop: (context) => {
|
|
115
|
+
if (context.state().route !== null) {
|
|
116
|
+
context.set({ route: null, position: { ...currentPosition(context.state(), platform(context)), speed: 0 } })
|
|
117
|
+
}
|
|
118
|
+
return context.state()
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
setup: (context) => {
|
|
122
|
+
const timer = setInterval(() => step(context, TICK_MS / 1000), TICK_MS)
|
|
123
|
+
return () => clearInterval(timer)
|
|
124
|
+
},
|
|
125
|
+
Panel: ({ state, set, run, sim }) => {
|
|
126
|
+
const os = sim.device.platform
|
|
127
|
+
const position = currentPosition(state, os)
|
|
128
|
+
const edit = (patch: Partial<Position>) => set({ position: { ...position, ...patch } })
|
|
129
|
+
const near = nearestPlace(position)
|
|
130
|
+
const preset = state.position === null ? simulatorPlace(os).id : (PLACES.find((place) => distance(place, position) < 1)?.id ?? 'custom')
|
|
131
|
+
const { route } = state
|
|
132
|
+
return (
|
|
133
|
+
<>
|
|
134
|
+
<Toggle label="Location services" checked={state.servicesEnabled} onChange={(servicesEnabled) => set({ servicesEnabled })} />
|
|
135
|
+
<Field label="Place" value={`${near.place.name} · ${km(near.metres)}`}>
|
|
136
|
+
<Select
|
|
137
|
+
label="Place"
|
|
138
|
+
value={preset}
|
|
139
|
+
options={[
|
|
140
|
+
...(preset === 'custom' ? [{ value: 'custom', label: 'Custom' }] : []),
|
|
141
|
+
...PLACES.map((place) => ({ value: place.id, label: `${place.name}, ${place.city}` })),
|
|
142
|
+
]}
|
|
143
|
+
onChange={(id) => {
|
|
144
|
+
const place = PLACES.find((candidate) => candidate.id === id)
|
|
145
|
+
if (place !== undefined) {
|
|
146
|
+
set({
|
|
147
|
+
route: null,
|
|
148
|
+
position: { latitude: place.latitude, longitude: place.longitude, altitude: place.altitude, accuracy: defaultAccuracy(os), heading: 0, speed: 0 },
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
}}
|
|
152
|
+
/>
|
|
153
|
+
</Field>
|
|
154
|
+
<Row>
|
|
155
|
+
<NumberField label="Lat" value={position.latitude} digits={5} onChange={(latitude) => edit({ latitude: Math.max(-90, Math.min(90, latitude)) })} />
|
|
156
|
+
<NumberField label="Lng" value={position.longitude} digits={5} onChange={(longitude) => edit({ longitude: Math.abs(longitude) <= 180 ? longitude : ((((longitude + 180) % 360) + 360) % 360) - 180 })} />
|
|
157
|
+
<NumberField label="Accuracy" unit="m" value={position.accuracy} onChange={(accuracy) => edit({ accuracy: Math.max(0, accuracy) })} />
|
|
158
|
+
<NumberField label="Altitude" unit="m" value={position.altitude} digits={0} onChange={(altitude) => edit({ altitude })} />
|
|
159
|
+
<NumberField label="Heading" unit="°" value={position.heading} digits={0} onChange={(heading) => edit({ heading: heading >= 0 && heading < 360 ? heading : ((heading % 360) + 360) % 360 })} />
|
|
160
|
+
<NumberField label="Speed" unit="m/s" value={position.speed} digits={1} onChange={(speed) => edit({ speed: Math.max(0, speed) })} />
|
|
161
|
+
</Row>
|
|
162
|
+
<Field label="Route" value={route === null ? 'None' : `${route.name} · ${km(route.travelled)} of ${km(route.length)}`}>
|
|
163
|
+
{route !== null && <Progress label="Route progress" value={route.length > 0 ? route.travelled / route.length : 0} />}
|
|
164
|
+
<Row>
|
|
165
|
+
{(Object.keys(PRESETS) as PresetName[]).map((name) => (
|
|
166
|
+
<Button key={name} title={`${PRESETS[name].name} from here`} pressed={route?.name === PRESETS[name].name} onClick={() => run('route', { preset: name })}>
|
|
167
|
+
{PRESETS[name].name}
|
|
168
|
+
</Button>
|
|
169
|
+
))}
|
|
170
|
+
</Row>
|
|
171
|
+
{route !== null && (
|
|
172
|
+
<Row>
|
|
173
|
+
<Button title={route.paused ? 'Resume the route' : 'Pause the route'} onClick={() => run(route.paused ? 'resume' : 'pause')}>
|
|
174
|
+
{route.paused ? 'Resume' : 'Pause'}
|
|
175
|
+
</Button>
|
|
176
|
+
<Button title="Stop the route here" onClick={() => run('stop')}>
|
|
177
|
+
Stop
|
|
178
|
+
</Button>
|
|
179
|
+
<Button title="Loop the route" pressed={route.loop} onClick={() => set({ route: { ...route, loop: !route.loop } })}>
|
|
180
|
+
Loop
|
|
181
|
+
</Button>
|
|
182
|
+
</Row>
|
|
183
|
+
)}
|
|
184
|
+
</Field>
|
|
185
|
+
</>
|
|
186
|
+
)
|
|
187
|
+
},
|
|
188
|
+
})
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Coordinates } from './geo.ts'
|
|
2
|
+
import { simulatorPlace } from './places.ts'
|
|
3
|
+
|
|
4
|
+
/** Where the phone is, what it reads in `coords`. */
|
|
5
|
+
export type Position = Coordinates & {
|
|
6
|
+
/** Metres. */
|
|
7
|
+
accuracy: number
|
|
8
|
+
/** Metres above sea level. */
|
|
9
|
+
altitude: number
|
|
10
|
+
/** Degrees from true north: the course, and where the compass points. */
|
|
11
|
+
heading: number
|
|
12
|
+
/** Metres a second. */
|
|
13
|
+
speed: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** A route the phone travels, a leg at a time. */
|
|
17
|
+
export type Route = {
|
|
18
|
+
name: string
|
|
19
|
+
points: Coordinates[]
|
|
20
|
+
/** Metres a second. */
|
|
21
|
+
speed: number
|
|
22
|
+
loop: boolean
|
|
23
|
+
/** Metres along the route so far. */
|
|
24
|
+
travelled: number
|
|
25
|
+
/** Metres from the first point to the last. */
|
|
26
|
+
length: number
|
|
27
|
+
paused: boolean
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The phone's location, set in the panel. `expo-location` reports it, and its watches hear it move. */
|
|
31
|
+
export type LocationState = {
|
|
32
|
+
servicesEnabled: boolean
|
|
33
|
+
/** Null until set: where the platform's simulator puts the phone. */
|
|
34
|
+
position: Position | null
|
|
35
|
+
route: Route | null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const INITIAL_LOCATION: LocationState = { servicesEnabled: true, position: null, route: null }
|
|
39
|
+
|
|
40
|
+
/** The accuracy a position fix reports, by platform, as the simulators do. */
|
|
41
|
+
export function defaultAccuracy(platform: 'ios' | 'android'): number {
|
|
42
|
+
return platform === 'ios' ? 5 : 13.4
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function currentPosition(state: LocationState, platform: 'ios' | 'android'): Position {
|
|
46
|
+
if (state.position !== null) {
|
|
47
|
+
return state.position
|
|
48
|
+
}
|
|
49
|
+
const place = simulatorPlace(platform)
|
|
50
|
+
return { latitude: place.latitude, longitude: place.longitude, altitude: place.altitude, accuracy: defaultAccuracy(platform), heading: 0, speed: 0 }
|
|
51
|
+
}
|