@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.
Files changed (281) hide show
  1. package/README.md +13 -2
  2. package/bin/cli.ts +255 -0
  3. package/bin/web-sim.js +39 -0
  4. package/overrides/@backpackapp-io/react-native-toast/overrides.ts +15 -0
  5. package/overrides/@react-native-firebase/app/overrides.ts +34 -0
  6. package/overrides/@tiktok-for-business/react-native-sdk/NativeTiktokSdk.ts +29 -0
  7. package/overrides/@tiktok-for-business/react-native-sdk/overrides.ts +9 -0
  8. package/overrides/expo-application/ExpoApplication.ts +81 -0
  9. package/overrides/expo-application/overrides.ts +16 -0
  10. package/overrides/expo-background-task/ExpoBackgroundTaskModule.ts +30 -0
  11. package/overrides/expo-background-task/overrides.ts +9 -0
  12. package/overrides/expo-constants/ExponentConstants.ts +66 -0
  13. package/overrides/expo-constants/overrides.ts +9 -0
  14. package/overrides/expo-device/ExpoDevice.ts +104 -0
  15. package/overrides/expo-device/overrides.ts +9 -0
  16. package/overrides/expo-glass-effect/GlassContainer.tsx +9 -0
  17. package/overrides/expo-glass-effect/GlassView.tsx +95 -0
  18. package/overrides/expo-glass-effect/availability.ts +14 -0
  19. package/overrides/expo-glass-effect/overrides.ts +14 -0
  20. package/overrides/expo-haptics/Haptics.ts +67 -0
  21. package/overrides/expo-haptics/overrides.ts +5 -0
  22. package/overrides/expo-mail-composer/ExpoMailComposer.ts +40 -0
  23. package/overrides/expo-mail-composer/overrides.ts +9 -0
  24. package/overrides/expo-mesh-gradient/MeshGradientView.tsx +44 -0
  25. package/overrides/expo-mesh-gradient/overrides.ts +9 -0
  26. package/overrides/expo-modules-core/overrides.ts +12 -0
  27. package/overrides/expo-navigation-bar/ExpoNavigationBar.ts +29 -0
  28. package/overrides/expo-navigation-bar/NavigationBar.ts +43 -0
  29. package/overrides/expo-navigation-bar/overrides.ts +12 -0
  30. package/overrides/expo-router/NativeStackView.tsx +74 -0
  31. package/overrides/expo-router/NativeTabsView.tsx +263 -0
  32. package/overrides/expo-router/SafeAreaProvider.ts +6 -0
  33. package/overrides/expo-router/overrides.ts +23 -0
  34. package/overrides/expo-router/statusBarRequests.ts +51 -0
  35. package/overrides/expo-screen-orientation/ExpoScreenOrientation.ts +173 -0
  36. package/overrides/expo-screen-orientation/overrides.ts +21 -0
  37. package/overrides/expo-sharing/SharingNativeModule.ts +21 -0
  38. package/overrides/expo-sharing/overrides.ts +9 -0
  39. package/overrides/expo-sms/ExpoSMS.ts +24 -0
  40. package/overrides/expo-sms/overrides.ts +9 -0
  41. package/overrides/expo-splash-screen/SplashScreen.ts +25 -0
  42. package/overrides/expo-splash-screen/overrides.ts +5 -0
  43. package/overrides/expo-status-bar/StatusBar.tsx +44 -0
  44. package/overrides/expo-status-bar/overrides.ts +5 -0
  45. package/overrides/expo-store-review/ExpoStoreReview.ts +18 -0
  46. package/overrides/expo-store-review/overrides.ts +9 -0
  47. package/overrides/expo-symbols/SymbolView.tsx +192 -0
  48. package/overrides/expo-symbols/overrides.ts +9 -0
  49. package/overrides/expo-system-ui/ExpoSystemUI.ts +34 -0
  50. package/overrides/expo-system-ui/overrides.ts +9 -0
  51. package/overrides/expo-task-manager/ExpoTaskManager.ts +39 -0
  52. package/overrides/expo-task-manager/overrides.ts +9 -0
  53. package/overrides/expo-tracking-transparency/ExpoTrackingTransparency.ts +30 -0
  54. package/overrides/expo-tracking-transparency/overrides.ts +11 -0
  55. package/overrides/expo-video/ExpoVideo.ts +16 -0
  56. package/overrides/expo-video/overrides.ts +9 -0
  57. package/overrides/lottie-react-native/LottieView.tsx +87 -0
  58. package/overrides/lottie-react-native/overrides.ts +9 -0
  59. package/overrides/react-native-pager-view/PagerViewNativeComponent.tsx +254 -0
  60. package/overrides/react-native-pager-view/overrides.ts +9 -0
  61. package/overrides/react-native-reanimated/overrides.ts +28 -0
  62. package/overrides/react-native-safe-area-context/NativeSafeAreaProvider.tsx +40 -0
  63. package/overrides/react-native-safe-area-context/overrides.ts +12 -0
  64. package/overrides/react-native-share/NativeRNShare.ts +22 -0
  65. package/overrides/react-native-share/overrides.ts +12 -0
  66. package/overrides/react-native-share/platform.ts +14 -0
  67. package/overrides/react-native-turbo-image/TurboImage.tsx +101 -0
  68. package/overrides/react-native-turbo-image/overrides.ts +9 -0
  69. package/overrides/react-native-web/RefreshControl.tsx +57 -0
  70. package/overrides/react-native-web/overrides.ts +157 -0
  71. package/overrides/react-native-web/useElementLayout.ts +152 -0
  72. package/package.json +80 -4
  73. package/plugins/battery/overrides/expo-battery/ExpoBattery.ts +57 -0
  74. package/plugins/battery/overrides/expo-battery/overrides.ts +9 -0
  75. package/plugins/battery/plugin.ts +8 -0
  76. package/plugins/battery/shell.tsx +56 -0
  77. package/plugins/battery/state.ts +11 -0
  78. package/plugins/biometrics/overrides/expo-local-authentication/ExpoLocalAuthentication.ts +90 -0
  79. package/plugins/biometrics/overrides/expo-local-authentication/overrides.ts +11 -0
  80. package/plugins/biometrics/plugin.ts +8 -0
  81. package/plugins/biometrics/shell.tsx +88 -0
  82. package/plugins/biometrics/state.ts +41 -0
  83. package/plugins/brightness/app.ts +5 -0
  84. package/plugins/brightness/overrides/expo-brightness/Brightness.ts +98 -0
  85. package/plugins/brightness/overrides/expo-brightness/overrides.ts +10 -0
  86. package/plugins/brightness/plugin.ts +9 -0
  87. package/plugins/brightness/shell.tsx +55 -0
  88. package/plugins/brightness/state.ts +19 -0
  89. package/plugins/calendar/calendar.ts +299 -0
  90. package/plugins/calendar/overrides/expo-calendar/ExpoCalendar.ts +358 -0
  91. package/plugins/calendar/overrides/expo-calendar/LegacyExpoCalendar.ts +163 -0
  92. package/plugins/calendar/overrides/expo-calendar/overrides.ts +14 -0
  93. package/plugins/calendar/plugin.ts +8 -0
  94. package/plugins/calendar/shell.tsx +123 -0
  95. package/plugins/camera/overrides/expo-camera/ExpoCamera.tsx +269 -0
  96. package/plugins/camera/overrides/expo-camera/ExpoCameraManager.ts +56 -0
  97. package/plugins/camera/overrides/expo-camera/overrides.ts +12 -0
  98. package/plugins/camera/plugin.ts +9 -0
  99. package/plugins/camera/shell.tsx +107 -0
  100. package/plugins/camera/state.ts +61 -0
  101. package/plugins/clipboard/overrides/expo-clipboard/ExpoClipboard.ts +138 -0
  102. package/plugins/clipboard/overrides/expo-clipboard/overrides.ts +9 -0
  103. package/plugins/clipboard/plugin.ts +8 -0
  104. package/plugins/clipboard/shell.tsx +122 -0
  105. package/plugins/clipboard/state.ts +93 -0
  106. package/plugins/clock/app.ts +25 -0
  107. package/plugins/clock/plugin.ts +8 -0
  108. package/plugins/clock/shell.tsx +225 -0
  109. package/plugins/clock/state.ts +12 -0
  110. package/plugins/contacts/contacts.ts +125 -0
  111. package/plugins/contacts/overrides/expo-contacts/ExpoContacts.ts +153 -0
  112. package/plugins/contacts/overrides/expo-contacts/ExpoContactsNext.ts +232 -0
  113. package/plugins/contacts/overrides/expo-contacts/overrides.ts +12 -0
  114. package/plugins/contacts/plugin.ts +8 -0
  115. package/plugins/contacts/shell.tsx +109 -0
  116. package/plugins/home-indicator/app.ts +5 -0
  117. package/plugins/home-indicator/plugin.ts +9 -0
  118. package/plugins/home-indicator/requests.ts +48 -0
  119. package/plugins/home-indicator/shell.tsx +68 -0
  120. package/plugins/home-indicator/state.ts +31 -0
  121. package/plugins/keep-awake/app.ts +5 -0
  122. package/plugins/keep-awake/overrides/expo-keep-awake/ExpoKeepAwake.ts +27 -0
  123. package/plugins/keep-awake/overrides/expo-keep-awake/overrides.ts +9 -0
  124. package/plugins/keep-awake/plugin.ts +9 -0
  125. package/plugins/keep-awake/shell.tsx +80 -0
  126. package/plugins/keep-awake/state.ts +12 -0
  127. package/plugins/keyboard/Keyboard.tsx +354 -0
  128. package/plugins/keyboard/app.ts +90 -0
  129. package/plugins/keyboard/controller.ts +384 -0
  130. package/plugins/keyboard/fields.ts +244 -0
  131. package/plugins/keyboard/icons.tsx +283 -0
  132. package/plugins/keyboard/keyboard.css +362 -0
  133. package/plugins/keyboard/layouts/android.ts +175 -0
  134. package/plugins/keyboard/layouts/index.ts +10 -0
  135. package/plugins/keyboard/layouts/ios.ts +219 -0
  136. package/plugins/keyboard/layouts/types.ts +80 -0
  137. package/plugins/keyboard/overrides/react-native-keyboard-controller/KeyboardController.tsx +470 -0
  138. package/plugins/keyboard/overrides/react-native-keyboard-controller/overrides.ts +9 -0
  139. package/plugins/keyboard/plugin.ts +13 -0
  140. package/plugins/keyboard/shell.tsx +133 -0
  141. package/plugins/keyboard/state.ts +92 -0
  142. package/plugins/keyboard/suggestions.ts +63 -0
  143. package/plugins/keyboard/taps.ts +77 -0
  144. package/plugins/keyboard/typing.ts +112 -0
  145. package/plugins/locale/app.ts +232 -0
  146. package/plugins/locale/locale.ts +143 -0
  147. package/plugins/locale/overrides/expo-localization/ExpoLocalization.ts +41 -0
  148. package/plugins/locale/overrides/expo-localization/overrides.ts +9 -0
  149. package/plugins/locale/plugin.ts +9 -0
  150. package/plugins/locale/shell.tsx +147 -0
  151. package/plugins/locale/state.ts +36 -0
  152. package/plugins/location/geo.ts +56 -0
  153. package/plugins/location/overrides/expo-location/ExpoLocation.ts +235 -0
  154. package/plugins/location/overrides/expo-location/overrides.ts +11 -0
  155. package/plugins/location/places.ts +38 -0
  156. package/plugins/location/plugin.ts +8 -0
  157. package/plugins/location/shell.tsx +188 -0
  158. package/plugins/location/state.ts +51 -0
  159. package/plugins/motion/overrides/expo-sensors/DeviceSensor.ts +169 -0
  160. package/plugins/motion/overrides/expo-sensors/ExponentPedometer.ts +54 -0
  161. package/plugins/motion/overrides/expo-sensors/overrides.ts +14 -0
  162. package/plugins/motion/plugin.ts +8 -0
  163. package/plugins/motion/sensors.ts +116 -0
  164. package/plugins/motion/shell.tsx +136 -0
  165. package/plugins/motion/state.ts +46 -0
  166. package/plugins/network/app.ts +400 -0
  167. package/plugins/network/overrides/expo-network/ExpoNetwork.ts +51 -0
  168. package/plugins/network/overrides/expo-network/overrides.ts +9 -0
  169. package/plugins/network/plugin.ts +8 -0
  170. package/plugins/network/shell.tsx +67 -0
  171. package/plugins/network/state.ts +29 -0
  172. package/plugins/notifications/center.ts +255 -0
  173. package/plugins/notifications/content.ts +36 -0
  174. package/plugins/notifications/overrides/expo-notifications/NotificationsModule.ts +175 -0
  175. package/plugins/notifications/overrides/expo-notifications/channels.ts +108 -0
  176. package/plugins/notifications/overrides/expo-notifications/getDevicePushTokenAsync.ts +19 -0
  177. package/plugins/notifications/overrides/expo-notifications/getExpoPushTokenAsync.ts +16 -0
  178. package/plugins/notifications/overrides/expo-notifications/overrides.ts +36 -0
  179. package/plugins/notifications/plugin.ts +8 -0
  180. package/plugins/notifications/shell.tsx +192 -0
  181. package/plugins/notifications/state.ts +56 -0
  182. package/plugins/notifications/tokens.ts +47 -0
  183. package/plugins/notifications/trigger.ts +107 -0
  184. package/plugins/permissions/plugin.ts +6 -0
  185. package/plugins/permissions/shell.tsx +50 -0
  186. package/plugins/permissions/state.ts +38 -0
  187. package/plugins/photos/appLibrary.ts +114 -0
  188. package/plugins/photos/library.ts +322 -0
  189. package/plugins/photos/overrides/expo-image-picker/ExponentImagePicker.ts +153 -0
  190. package/plugins/photos/overrides/expo-image-picker/overrides.ts +13 -0
  191. package/plugins/photos/overrides/expo-media-library/ExpoMediaLibrary.ts +235 -0
  192. package/plugins/photos/overrides/expo-media-library/NativeMediaLibraryModule.ts +318 -0
  193. package/plugins/photos/overrides/expo-media-library/overrides.ts +19 -0
  194. package/plugins/photos/plugin.ts +8 -0
  195. package/plugins/photos/samples.ts +367 -0
  196. package/plugins/photos/shell.tsx +164 -0
  197. package/plugins/photos/state.ts +88 -0
  198. package/plugins/storage/files.ts +351 -0
  199. package/plugins/storage/overrides/expo-file-system/ExpoFileSystem.ts +770 -0
  200. package/plugins/storage/overrides/expo-file-system/ExponentFileSystem.ts +196 -0
  201. package/plugins/storage/overrides/expo-file-system/overrides.ts +13 -0
  202. package/plugins/storage/overrides/expo-secure-store/ExpoSecureStore.ts +75 -0
  203. package/plugins/storage/overrides/expo-secure-store/overrides.ts +9 -0
  204. package/plugins/storage/plugin.ts +8 -0
  205. package/plugins/storage/reset.ts +136 -0
  206. package/plugins/storage/secure.ts +71 -0
  207. package/plugins/storage/shell.tsx +365 -0
  208. package/plugins/storage/state.ts +13 -0
  209. package/src/client/app/appDocument.ts +129 -0
  210. package/src/client/app/appFocus.ts +97 -0
  211. package/src/client/app/console.ts +118 -0
  212. package/src/client/app/fonts.ts +76 -0
  213. package/src/client/app/main.tsx +99 -0
  214. package/src/client/app/routeContext.ts +45 -0
  215. package/src/client/app/touch.ts +640 -0
  216. package/src/client/entry.ts +20 -0
  217. package/src/client/modules.d.ts +8 -0
  218. package/src/client/react-native/app.ts +57 -0
  219. package/src/client/react-native/deep.ts +13 -0
  220. package/src/client/react-native/keyboard.tsx +192 -0
  221. package/src/client/react-native/library.ts +256 -0
  222. package/src/client/shell/Cookies.tsx +95 -0
  223. package/src/client/shell/LogDrawer.tsx +415 -0
  224. package/src/client/shell/PhotoPicker.tsx +174 -0
  225. package/src/client/shell/PluginOverlays.tsx +42 -0
  226. package/src/client/shell/PluginPanels.tsx +82 -0
  227. package/src/client/shell/ResetApp.tsx +87 -0
  228. package/src/client/shell/Resizer.tsx +99 -0
  229. package/src/client/shell/Shell.tsx +531 -0
  230. package/src/client/shell/SystemBars.tsx +376 -0
  231. package/src/client/shell/SystemCamera.tsx +181 -0
  232. package/src/client/shell/SystemOverlay.tsx +422 -0
  233. package/src/client/shell/SystemSheets.tsx +462 -0
  234. package/src/client/shell/backdrop.ts +229 -0
  235. package/src/client/shell/control.ts +91 -0
  236. package/src/client/shell/events.ts +226 -0
  237. package/src/client/shell/geometry.ts +68 -0
  238. package/src/client/shell/host.ts +492 -0
  239. package/src/client/shell/icons.tsx +34 -0
  240. package/src/client/shell/logFeed.ts +102 -0
  241. package/src/client/shell/main.tsx +22 -0
  242. package/src/client/shell/permissionCopy.ts +169 -0
  243. package/src/client/shell/plugins.ts +266 -0
  244. package/src/client/shell/popout.ts +185 -0
  245. package/src/client/shell/popover.ts +27 -0
  246. package/src/client/shell/shell.css +878 -0
  247. package/src/client/shell/statusTime.ts +31 -0
  248. package/src/client/shell/tooltips.ts +104 -0
  249. package/src/client/virtual.d.ts +23 -0
  250. package/src/devices/catalog.ts +223 -0
  251. package/src/devices/types.ts +83 -0
  252. package/src/node/appInfo.ts +188 -0
  253. package/src/node/appSource.ts +140 -0
  254. package/src/node/config.ts +180 -0
  255. package/src/node/control.ts +144 -0
  256. package/src/node/doctor.ts +199 -0
  257. package/src/node/events/cli.ts +206 -0
  258. package/src/node/events/shared.ts +238 -0
  259. package/src/node/events/store.ts +266 -0
  260. package/src/node/fonts.ts +377 -0
  261. package/src/node/index.ts +5 -0
  262. package/src/node/overrides/define.ts +56 -0
  263. package/src/node/overrides/packages.ts +136 -0
  264. package/src/node/overrides/platformPatch.ts +56 -0
  265. package/src/node/overrides/plugin.ts +169 -0
  266. package/src/node/overrides/registry.ts +258 -0
  267. package/src/node/paths.ts +18 -0
  268. package/src/node/platform.ts +171 -0
  269. package/src/node/plugins.ts +98 -0
  270. package/src/node/proxy.ts +421 -0
  271. package/src/node/server.ts +254 -0
  272. package/src/node/worklets.ts +86 -0
  273. package/src/plugin/index.ts +33 -0
  274. package/src/plugin/types.ts +127 -0
  275. package/src/plugin/ui.tsx +562 -0
  276. package/src/runtime/clock.ts +112 -0
  277. package/src/runtime/draw.ts +196 -0
  278. package/src/runtime/index.ts +519 -0
  279. package/src/runtime/media.ts +379 -0
  280. package/src/runtime/records.ts +76 -0
  281. package/src/runtime/timezone.ts +81 -0
@@ -0,0 +1,153 @@
1
+ import { getPermission, platform, requestPermission, showDialog } from 'web-sim/runtime'
2
+ // @ts-expect-error Resolved inside the package, to the current module's replacement: the same address book.
3
+ import { contactRecords, ensurePermission, fullName } from '../ExpoContactsNext'
4
+ import type { ContactRecord } from './ExpoContactsNext.ts'
5
+
6
+ type Records = { all(): ContactRecord[]; get(id: string): ContactRecord | null; put(record: ContactRecord): void; remove(id: string): void; newId(): string }
7
+ const records = (): Records => contactRecords()
8
+
9
+ type LegacyContact = {
10
+ id?: string
11
+ firstName?: string
12
+ middleName?: string
13
+ lastName?: string
14
+ nickname?: string
15
+ company?: string
16
+ jobTitle?: string
17
+ department?: string
18
+ note?: string
19
+ phoneNumbers?: { id?: string; label: string; number?: string }[]
20
+ emails?: { id?: string; label: string; email?: string }[]
21
+ birthday?: { day: number; month: number; year?: number }
22
+ }
23
+
24
+ /** A contact in the legacy shape: `firstName`, `phoneNumbers`, and a birthday whose month counts from 0. */
25
+ function legacy(record: ContactRecord, fields?: string[]) {
26
+ const contact: Record<string, unknown> = {
27
+ id: record.id,
28
+ contactType: record.company && !record.givenName ? 'company' : 'person',
29
+ name: fullName(record),
30
+ firstName: record.givenName ?? undefined,
31
+ middleName: record.middleName ?? undefined,
32
+ lastName: record.familyName ?? undefined,
33
+ nickname: record.nickname ?? undefined,
34
+ company: record.company ?? undefined,
35
+ jobTitle: record.jobTitle ?? undefined,
36
+ department: record.department ?? undefined,
37
+ note: record.note ?? undefined,
38
+ imageAvailable: record.image !== null,
39
+ phoneNumbers: record.phones.map((phone, index) => ({
40
+ id: phone.id,
41
+ label: phone.label ?? 'mobile',
42
+ number: phone.number,
43
+ digits: String(phone.number ?? '').replace(/[^\d+]/g, ''),
44
+ countryCode: String(phone.number ?? '').startsWith('+49') ? 'de' : 'us',
45
+ isPrimary: index === 0,
46
+ })),
47
+ emails: record.emails.map((email, index) => ({ id: email.id, label: email.label ?? 'home', email: email.address, isPrimary: index === 0 })),
48
+ ...(record.birthday && { birthday: { ...record.birthday, month: record.birthday.month - 1 } }),
49
+ }
50
+ if (fields === undefined || fields.length === 0) {
51
+ return contact
52
+ }
53
+ const always = ['id', 'contactType', 'name', 'firstName', 'middleName', 'lastName', 'imageAvailable']
54
+ return Object.fromEntries(Object.entries(contact).filter(([key]) => always.includes(key) || fields.includes(key)))
55
+ }
56
+
57
+ function fromLegacy(contact: LegacyContact, id: string, existing?: ContactRecord): ContactRecord {
58
+ const base = existing ?? contactRecords().get(id) ?? ({} as ContactRecord)
59
+ return {
60
+ ...base,
61
+ id,
62
+ isFavourite: base.isFavourite ?? false,
63
+ givenName: contact.firstName ?? base.givenName ?? null,
64
+ middleName: contact.middleName ?? base.middleName ?? null,
65
+ familyName: contact.lastName ?? base.familyName ?? null,
66
+ nickname: contact.nickname ?? base.nickname ?? null,
67
+ company: contact.company ?? base.company ?? null,
68
+ jobTitle: contact.jobTitle ?? base.jobTitle ?? null,
69
+ department: contact.department ?? base.department ?? null,
70
+ note: contact.note ?? base.note ?? null,
71
+ birthday: contact.birthday ? { ...contact.birthday, month: contact.birthday.month + 1 } : (base.birthday ?? null),
72
+ phones: contact.phoneNumbers?.map((phone) => ({ id: phone.id ?? crypto.randomUUID(), label: phone.label, number: phone.number })) ?? base.phones ?? [],
73
+ emails: contact.emails?.map((email) => ({ id: email.id ?? crypto.randomUUID(), label: email.label, address: email.email })) ?? base.emails ?? [],
74
+ } as ContactRecord
75
+ }
76
+
77
+ /**
78
+ * The legacy `expo-contacts` API (`expo-contacts/legacy`) over the same made-up address book as the current one.
79
+ */
80
+ export default {
81
+ async getPermissionsAsync() {
82
+ return getPermission('contacts')
83
+ },
84
+ async requestPermissionsAsync() {
85
+ return requestPermission('contacts')
86
+ },
87
+ async hasContactsAsync() {
88
+ ensurePermission()
89
+ return records().all().length > 0
90
+ },
91
+ async getContactsAsync(query: { pageSize?: number; pageOffset?: number; fields?: string[]; sort?: string; name?: string; id?: string | string[] } = {}) {
92
+ ensurePermission()
93
+ let all = records().all()
94
+ if (query.id !== undefined) {
95
+ const ids = Array.isArray(query.id) ? query.id : [query.id]
96
+ all = all.filter((record) => ids.includes(record.id))
97
+ }
98
+ if (query.name) {
99
+ const name = query.name.toLowerCase()
100
+ all = all.filter((record) => fullName(record).toLowerCase().includes(name))
101
+ }
102
+ const key = query.sort === 'lastName' ? 'familyName' : 'givenName'
103
+ all = [...all].sort((a, b) => (a[key] ?? '').localeCompare(b[key] ?? ''))
104
+ const offset = query.pageOffset ?? 0
105
+ const page = query.pageSize ? all.slice(offset, offset + query.pageSize) : all.slice(offset)
106
+ return {
107
+ data: page.map((record) => legacy(record, query.fields)),
108
+ hasNextPage: offset + page.length < all.length,
109
+ hasPreviousPage: offset > 0,
110
+ total: all.length,
111
+ }
112
+ },
113
+ async addContactAsync(contact: LegacyContact) {
114
+ ensurePermission()
115
+ const id = platform() === 'ios' ? `${crypto.randomUUID().toUpperCase()}:ABPerson` : records().newId()
116
+ records().put(fromLegacy(contact, id, { id, phones: [], emails: [], dates: [], extraNames: [], addresses: [], relations: [], urlAddresses: [], socialProfiles: [], imAddresses: [] } as unknown as ContactRecord))
117
+ return id
118
+ },
119
+ async updateContactAsync(contact: LegacyContact & { id: string }) {
120
+ ensurePermission()
121
+ records().put(fromLegacy(contact, contact.id))
122
+ return contact.id
123
+ },
124
+ async removeContactAsync(id: string) {
125
+ ensurePermission()
126
+ records().remove(id)
127
+ },
128
+ async presentContactPickerAsync() {
129
+ const list = records().all().sort((a, b) => fullName(a).localeCompare(fullName(b)))
130
+ const { button } = await showDialog({
131
+ kind: 'action-sheet',
132
+ title: 'Contacts',
133
+ buttons: [...list.map((record) => ({ text: fullName(record) })), { text: 'Cancel', style: 'cancel' }],
134
+ })
135
+ return button >= 0 && button < list.length ? legacy(list[button]) : null
136
+ },
137
+ async getDefaultContainerIdentifierAsync() {
138
+ return platform() === 'ios' ? 'C0NTA1NER-0000-4000-8000-000000000001' : 'local'
139
+ },
140
+ async getContainersAsync() {
141
+ return [{ id: 'C0NTA1NER-0000-4000-8000-000000000001', name: 'iCloud', type: 'cardDAV' }]
142
+ },
143
+ async getGroupsAsync() {
144
+ return []
145
+ },
146
+ async presentFormAsync() {},
147
+ async presentAccessPickerAsync() {
148
+ return []
149
+ },
150
+ addListener() {
151
+ return { remove: () => undefined }
152
+ },
153
+ }
@@ -0,0 +1,232 @@
1
+ import { CodedError } from 'expo'
2
+ import { appendLog, getPermission, platform, plugin, requestPermission, showDialog } from 'web-sim/runtime'
3
+ import { contactBook, type ContactRecord, type ContactsState, empty, fullName, INITIAL_CONTACTS, type Item } from '../../contacts.ts'
4
+
5
+ export type { ContactRecord }
6
+
7
+ const contacts = () => plugin<ContactsState>('contacts', INITIAL_CONTACTS)
8
+
9
+ /**
10
+ * `expo-contacts`' native module over the contacts panel's address book: a few made-up people, and the changes the
11
+ * app and the panel make.
12
+ * Reading or changing it needs the contacts permission, as on the device; the system contact picker does not.
13
+ */
14
+
15
+ const SCALARS = [
16
+ 'givenName', 'middleName', 'familyName', 'maidenName', 'nickname', 'prefix', 'suffix', 'phoneticGivenName',
17
+ 'phoneticMiddleName', 'phoneticFamilyName', 'company', 'department', 'jobTitle', 'phoneticCompanyName', 'note',
18
+ 'image', 'birthday', 'nonGregorianBirthday',
19
+ ] as const
20
+
21
+ /** Each list field, by the name its methods use: `addEmail`, `getEmails`, `updateEmail`, `deleteEmail`. */
22
+ const LISTS = {
23
+ Email: 'emails',
24
+ Phone: 'phones',
25
+ Date: 'dates',
26
+ ExtraName: 'extraNames',
27
+ Address: 'addresses',
28
+ Relation: 'relations',
29
+ UrlAddress: 'urlAddresses',
30
+ SocialProfile: 'socialProfiles',
31
+ ImAddress: 'imAddresses',
32
+ } as const
33
+
34
+ type ListField = (typeof LISTS)[keyof typeof LISTS]
35
+
36
+ /** The address book, shared with the legacy module. App changes are logged for the panel. */
37
+ export function contactRecords() {
38
+ return contactBook(contacts(), platform(), (text) => contacts().set({ log: appendLog(contacts().get().log, text) }))
39
+ }
40
+
41
+ export { fullName }
42
+
43
+ export function ensurePermission() {
44
+ if (!getPermission('contacts').granted) {
45
+ throw new CodedError('ERR_MISSING_PERMISSION', 'Missing contacts permission.')
46
+ }
47
+ }
48
+
49
+ function withIds(items: Item[] | undefined): Item[] {
50
+ return (items ?? []).map((item) => ({ ...item, id: item.id ?? crypto.randomUUID() }))
51
+ }
52
+
53
+ function details(record: ContactRecord, fields?: readonly string[]) {
54
+ const all = { ...record, fullName: fullName(record), thumbnail: record.image }
55
+ if (fields === undefined) {
56
+ return all
57
+ }
58
+ return Object.fromEntries([['id', record.id], ...fields.map((field) => [field, all[field as keyof typeof all] ?? null])])
59
+ }
60
+
61
+ function query(options: { limit?: number; offset?: number; sortOrder?: string; name?: string } = {}): ContactRecord[] {
62
+ ensurePermission()
63
+ let records = contactRecords().all()
64
+ if (options.name) {
65
+ const name = options.name.toLowerCase()
66
+ records = records.filter((record) => fullName(record).toLowerCase().includes(name))
67
+ }
68
+ if (options.sortOrder !== 'none') {
69
+ const key = options.sortOrder === 'familyName' ? 'familyName' : 'givenName'
70
+ records = [...records].sort((a, b) => (a[key] ?? '').localeCompare(b[key] ?? ''))
71
+ }
72
+ const offset = options.offset ?? 0
73
+ return records.slice(offset, options.limit === undefined ? undefined : offset + options.limit)
74
+ }
75
+
76
+ class Contact {
77
+ id: string
78
+ constructor(id: string) {
79
+ this.id = id
80
+ }
81
+ protected record(): ContactRecord {
82
+ ensurePermission()
83
+ const record = contactRecords().get(this.id)
84
+ if (record === null) {
85
+ throw new CodedError('ERR_CONTACT_NOT_FOUND', `Contact ${this.id} not found`)
86
+ }
87
+ return record
88
+ }
89
+ protected save(change: Partial<ContactRecord>) {
90
+ contactRecords().put({ ...this.record(), ...change, id: this.id })
91
+ }
92
+ async delete() {
93
+ this.record()
94
+ contactRecords().remove(this.id)
95
+ }
96
+ async patch(patch: Partial<ContactRecord>) {
97
+ const change: Partial<ContactRecord> = { ...patch }
98
+ for (const field of Object.values(LISTS)) {
99
+ if (patch[field] !== undefined) {
100
+ change[field] = withIds(patch[field])
101
+ }
102
+ }
103
+ this.save(change)
104
+ }
105
+ async update(contact: Partial<ContactRecord>) {
106
+ this.record()
107
+ const next = { ...empty(this.id), ...contact, id: this.id }
108
+ for (const field of Object.values(LISTS)) {
109
+ next[field] = withIds(contact[field])
110
+ }
111
+ contactRecords().put(next)
112
+ }
113
+ async getDetails(fields?: readonly string[]) {
114
+ return details(this.record(), fields)
115
+ }
116
+ async editWithForm() {
117
+ this.record()
118
+ return false
119
+ }
120
+ async getFullName() {
121
+ return fullName(this.record())
122
+ }
123
+ async getIsFavourite() {
124
+ return this.record().isFavourite
125
+ }
126
+ async setIsFavourite(isFavourite: boolean) {
127
+ this.save({ isFavourite })
128
+ return true
129
+ }
130
+ async getThumbnail() {
131
+ return this.record().image
132
+ }
133
+
134
+ static async getAll(this: new (id: string) => Contact, options?: Parameters<typeof query>[0]) {
135
+ return query(options).map((record) => new this(record.id))
136
+ }
137
+ static async getAllDetails(fields: readonly string[], options?: Parameters<typeof query>[0]) {
138
+ return query(options).map((record) => details(record, fields))
139
+ }
140
+ static async getCount() {
141
+ return query().length
142
+ }
143
+ static async hasAny() {
144
+ return query().length > 0
145
+ }
146
+ static async create(this: new (id: string) => Contact, contact: Partial<ContactRecord>) {
147
+ ensurePermission()
148
+ const records = contactRecords()
149
+ const id = platform() === 'ios' ? `${crypto.randomUUID().toUpperCase()}:ABPerson` : records.newId()
150
+ const record = { ...empty(id), ...contact, id }
151
+ for (const field of Object.values(LISTS)) {
152
+ record[field] = withIds(contact[field])
153
+ }
154
+ records.put(record)
155
+ return new this(id)
156
+ }
157
+ static async presentCreateForm() {
158
+ return false
159
+ }
160
+ /** The system contact picker, which needs no permission: drawn as a sheet of the address book's names. */
161
+ static async presentPicker(this: new (id: string) => Contact) {
162
+ const records = contactRecords().all().sort((a, b) => fullName(a).localeCompare(fullName(b)))
163
+ const { button } = await showDialog({
164
+ kind: 'action-sheet',
165
+ title: 'Contacts',
166
+ buttons: [...records.map((record) => ({ text: fullName(record) })), { text: 'Cancel', style: 'cancel' }],
167
+ })
168
+ return button >= 0 && button < records.length ? new this(records[button].id) : null
169
+ }
170
+ static async presentAccessPicker() {
171
+ return []
172
+ }
173
+ }
174
+
175
+ // The scalar getters and setters, and the list methods, made from the field names.
176
+ const prototype = Contact.prototype as unknown as Record<string, unknown>
177
+ for (const field of SCALARS) {
178
+ const name = field[0].toUpperCase() + field.slice(1)
179
+ prototype[`get${name}`] = async function (this: Contact) {
180
+ return (this as unknown as { record(): ContactRecord }).record()[field] ?? null
181
+ }
182
+ prototype[`set${name}`] = async function (this: Contact, value: unknown) {
183
+ ;(this as unknown as { save(change: Partial<ContactRecord>): void }).save({ [field]: value ?? null })
184
+ return true
185
+ }
186
+ }
187
+ for (const [name, field] of Object.entries(LISTS) as [string, ListField][]) {
188
+ const access = (contact: Contact) => contact as unknown as { record(): ContactRecord; save(change: Partial<ContactRecord>): void }
189
+ prototype[`add${name}`] = async function (this: Contact, item: Omit<Item, 'id'>) {
190
+ const id = crypto.randomUUID()
191
+ access(this).save({ [field]: [...access(this).record()[field], { ...item, id }] })
192
+ return id
193
+ }
194
+ prototype[`get${name}s`] = async function (this: Contact) {
195
+ return access(this).record()[field]
196
+ }
197
+ prototype[`update${name}`] = async function (this: Contact, item: Item) {
198
+ access(this).save({ [field]: access(this).record()[field].map((existing) => (existing.id === item.id ? item : existing)) })
199
+ }
200
+ prototype[`delete${name}`] = async function (this: Contact, item: Item | string) {
201
+ const id = typeof item === 'string' ? item : item.id
202
+ access(this).save({ [field]: access(this).record()[field].filter((existing) => existing.id !== id) })
203
+ }
204
+ }
205
+
206
+ export default {
207
+ Contact,
208
+ async getPermissionsAsync() {
209
+ return { ...getPermission('contacts'), accessPrivileges: getPermission('contacts').granted ? 'all' : 'none' }
210
+ },
211
+ async requestPermissionsAsync() {
212
+ const response = await requestPermission('contacts')
213
+ return { ...response, accessPrivileges: response.granted ? 'all' : 'none' }
214
+ },
215
+ addListener(eventName: string, listener: () => void) {
216
+ if (eventName !== 'contactsDidChange') {
217
+ return { remove: () => undefined }
218
+ }
219
+ // Any change to the address book, from the app or the panel.
220
+ const remove = contacts().watch((next, previous) => {
221
+ const os = platform()
222
+ if (next[os] !== previous[os]) {
223
+ listener()
224
+ }
225
+ })
226
+ return { remove }
227
+ },
228
+ removeListener() {},
229
+ removeAllListeners() {},
230
+ emit() {},
231
+ listenerCount: () => 0,
232
+ }
@@ -0,0 +1,12 @@
1
+ import { defineOverrides } from '../../../../src/node/overrides/define.ts'
2
+
3
+ export default defineOverrides('expo-contacts', [
4
+ {
5
+ versions: '>=58 <59',
6
+ note: "the contacts permission, and the contacts panel's address book; the app's changes show in the panel",
7
+ files: {
8
+ 'build/ExpoContactsNext.web.js': './ExpoContactsNext.ts',
9
+ 'build/legacy/ExpoContacts.web.js': './ExpoContacts.ts',
10
+ },
11
+ },
12
+ ])
@@ -0,0 +1,8 @@
1
+ import { definePlugin } from '../../src/node/plugins.ts'
2
+
3
+ export default definePlugin({
4
+ name: 'contacts',
5
+ packages: ['expo-contacts'],
6
+ overrides: './overrides',
7
+ shell: './shell.tsx',
8
+ })
@@ -0,0 +1,109 @@
1
+ import { AddressBookIcon, TrashIcon } from '@phosphor-icons/react'
2
+ import { useState } from 'react'
3
+ import { Button, defineShellPlugin, Field, IconButton, List, ListItem, Log, Row, TextField, type PluginContext } from 'web-sim/shell'
4
+ import { contactBook, type ContactRecord, type ContactsState, empty, fullName, INITIAL_CONTACTS, primary } from './contacts.ts'
5
+
6
+ /** What the panel and the CLI set on a contact. */
7
+ type Edit = { givenName?: string; familyName?: string; phone?: string; email?: string }
8
+
9
+ function book(context: PluginContext<ContactsState>) {
10
+ return contactBook({ get: context.state, set: context.set }, context.sim().device.platform)
11
+ }
12
+
13
+ function apply(record: ContactRecord, edit: Edit): ContactRecord {
14
+ const next = { ...record }
15
+ if (edit.givenName !== undefined) {
16
+ next.givenName = edit.givenName || null
17
+ }
18
+ if (edit.familyName !== undefined) {
19
+ next.familyName = edit.familyName || null
20
+ }
21
+ if (edit.phone !== undefined) {
22
+ const [first, ...rest] = record.phones
23
+ next.phones = edit.phone === '' ? rest : [{ label: 'mobile', ...first, id: first?.id ?? `${record.id}-phone`, number: edit.phone }, ...rest]
24
+ }
25
+ if (edit.email !== undefined) {
26
+ const [first, ...rest] = record.emails
27
+ next.emails = edit.email === '' ? rest : [{ label: 'home', ...first, id: first?.id ?? `${record.id}-email`, address: edit.email }, ...rest]
28
+ }
29
+ return next
30
+ }
31
+
32
+ function Editor({ record, run }: { record: ContactRecord; run: (action: string, args?: unknown) => unknown }) {
33
+ const { phone, email } = primary(record)
34
+ const update = (edit: Edit) => run('update', { id: record.id, ...edit })
35
+ return (
36
+ <>
37
+ <Row>
38
+ <div style={{ flex: 1 }}>
39
+ <TextField label="First name" placeholder="First" value={record.givenName ?? ''} onChange={(givenName) => update({ givenName })} />
40
+ </div>
41
+ <div style={{ flex: 1 }}>
42
+ <TextField label="Last name" placeholder="Last" value={record.familyName ?? ''} onChange={(familyName) => update({ familyName })} />
43
+ </div>
44
+ </Row>
45
+ <TextField label="Phone" placeholder="Phone" value={phone} onChange={(value) => update({ phone: value })} />
46
+ <TextField label="Email" placeholder="Email" value={email} onChange={(value) => update({ email: value })} />
47
+ </>
48
+ )
49
+ }
50
+
51
+ export default defineShellPlugin<ContactsState>({
52
+ id: 'contacts',
53
+ title: 'Contacts',
54
+ icon: AddressBookIcon,
55
+ initialState: INITIAL_CONTACTS,
56
+ actions: {
57
+ /** Adds a contact; returns its id. */
58
+ add: (context, args) => {
59
+ const records = book(context)
60
+ const id = context.sim().device.platform === 'ios' ? `${crypto.randomUUID().toUpperCase()}:ABPerson` : records.newId()
61
+ records.put(apply(empty(id), (args ?? {}) as Edit))
62
+ return { id }
63
+ },
64
+ update: (context, args) => {
65
+ const { id, ...edit } = args as Edit & { id: string }
66
+ const records = book(context)
67
+ const record = records.get(id)
68
+ if (record === null) {
69
+ throw new Error(`No contact '${id}'`)
70
+ }
71
+ records.put(apply(record, edit))
72
+ },
73
+ remove: (context, args) => {
74
+ book(context).remove((args as { id: string }).id)
75
+ },
76
+ },
77
+ Panel: ({ state, set, run, sim }) => {
78
+ const [open, setOpen] = useState<string | null>(null)
79
+ const records = contactBook({ get: () => state, set }, sim.device.platform)
80
+ .all()
81
+ .sort((a, b) => fullName(a).localeCompare(fullName(b)))
82
+ return (
83
+ <>
84
+ <Field label="Contacts" value={records.length}>
85
+ <List>
86
+ {records.map((record) => (
87
+ <ListItem
88
+ key={record.id}
89
+ title={fullName(record) || 'No name'}
90
+ detail={primary(record).phone || primary(record).email || undefined}
91
+ selected={open === record.id}
92
+ onPress={() => setOpen(open === record.id ? null : record.id)}
93
+ actions={<IconButton icon={TrashIcon} title={`Delete ${fullName(record) || 'contact'}`} onClick={() => run('remove', { id: record.id })} />}
94
+ >
95
+ {open === record.id && <Editor record={record} run={run} />}
96
+ </ListItem>
97
+ ))}
98
+ </List>
99
+ <Row>
100
+ <Button onClick={() => setOpen((run('add', { givenName: 'New', familyName: 'Contact' }) as { id: string }).id)}>Add contact</Button>
101
+ </Row>
102
+ </Field>
103
+ <Field label="App">
104
+ <Log entries={state.log} />
105
+ </Field>
106
+ </>
107
+ )
108
+ },
109
+ })
@@ -0,0 +1,5 @@
1
+ import { plugin } from 'web-sim/runtime'
2
+ import { type HomeIndicatorState, INITIAL_HOME_INDICATOR } from './state.ts'
3
+
4
+ // A new run starts with no screen asking for auto-hide: the last run's screens went with its process.
5
+ plugin<HomeIndicatorState>('home-indicator', INITIAL_HOME_INDICATOR).set({ appAutoHidden: false })
@@ -0,0 +1,9 @@
1
+ import { definePlugin } from '../../src/node/plugins.ts'
2
+
3
+ // Without `packages`: every iPhone without a home button has the indicator. The app asks for it auto-hidden through
4
+ // its navigation library (expo-router's and React Navigation's native stack, `autoHideHomeIndicator`).
5
+ export default definePlugin({
6
+ name: 'home-indicator',
7
+ shell: './shell.tsx',
8
+ app: './app.ts',
9
+ })
@@ -0,0 +1,48 @@
1
+ import { plugin } from 'web-sim/runtime'
2
+ import { type HomeIndicatorState, INITIAL_HOME_INDICATOR } from './state.ts'
3
+
4
+ /**
5
+ * What the app's navigators ask of the home indicator. On iOS the deepest focused view controller decides
6
+ * (`childForHomeIndicatorAutoHidden`), so each navigator reports how deep it is, whether it is on the focused path, and
7
+ * what its focused screen asks; the deepest focused one wins.
8
+ */
9
+ type Request = { depth: number; focused: boolean; autoHidden: boolean | undefined; source: string }
10
+
11
+ const requests = new Map<string, Request>()
12
+ let scheduled = false
13
+
14
+ const homeIndicator = () => plugin<HomeIndicatorState>('home-indicator', INITIAL_HOME_INDICATOR)
15
+
16
+ /** Sets (or, with null, drops) one navigator's request. */
17
+ export function requestAutoHidden(id: string, request: Request | null): void {
18
+ if (request === null) {
19
+ requests.delete(id)
20
+ } else {
21
+ requests.set(id, request)
22
+ }
23
+ // Once per batch of changes: a navigation commits several navigators at once.
24
+ if (!scheduled) {
25
+ scheduled = true
26
+ queueMicrotask(apply)
27
+ }
28
+ }
29
+
30
+ function apply(): void {
31
+ scheduled = false
32
+ let winner: Request | null = null
33
+ for (const request of requests.values()) {
34
+ if (request.focused && (winner === null || request.depth >= winner.depth)) {
35
+ winner = request
36
+ }
37
+ }
38
+ const autoHidden = winner?.autoHidden ?? false
39
+ if (autoHidden !== homeIndicator().get().appAutoHidden) {
40
+ homeIndicator().set({ appAutoHidden: autoHidden })
41
+ homeIndicator().log(
42
+ 'autoHide',
43
+ autoHidden ? `App prefers the home indicator auto-hidden (${winner?.source})` : 'App lets the home indicator show',
44
+ { autoHidden, source: winner?.source ?? null },
45
+ { level: 'info' },
46
+ )
47
+ }
48
+ }
@@ -0,0 +1,68 @@
1
+ import { LineSegmentIcon } from '@phosphor-icons/react'
2
+ import { defineShellPlugin, Field, Select } from 'web-sim/shell'
3
+ import { autoHides, HIDE_AFTER_MS, type HomeIndicatorState, indicatorShown, INITIAL_HOME_INDICATOR } from './state.ts'
4
+
5
+ const MODES = [
6
+ { value: 'app', label: 'As the app asks' },
7
+ { value: 'visible', label: 'Always visible' },
8
+ { value: 'auto-hide', label: 'Auto-hide' },
9
+ { value: 'hidden', label: 'Hidden' },
10
+ ] as const
11
+
12
+ /** Brings an auto-hidden indicator back, as a touch on the screen does. */
13
+ function reveal(context: { state(): HomeIndicatorState; set(patch: Partial<HomeIndicatorState>): void }) {
14
+ if (autoHides(context.state())) {
15
+ context.set({ shown: true, shownSince: Date.now() })
16
+ }
17
+ }
18
+
19
+ export default defineShellPlugin<HomeIndicatorState>({
20
+ id: 'home-indicator',
21
+ title: 'Home indicator',
22
+ icon: LineSegmentIcon,
23
+ platforms: ['ios'],
24
+ initialState: INITIAL_HOME_INDICATOR,
25
+ // The countdown's start changes with every touch: the shown/hidden changes are what the log needs.
26
+ logIgnore: ['shownSince'],
27
+ statusBar: (state) => ({ homeIndicator: { hidden: !indicatorShown(state) } }),
28
+ onPress: reveal,
29
+ actions: {
30
+ /** Brings an auto-hidden indicator back for a few seconds, as a touch does. */
31
+ reveal: (context) => {
32
+ reveal(context)
33
+ return context.state()
34
+ },
35
+ },
36
+ setup: (context) => {
37
+ // Auto-hide starting (the app asks, or the panel forces it) starts the countdown from a shown indicator; auto-hide
38
+ // ending brings the indicator back for good.
39
+ let wasAutoHiding = autoHides(context.state())
40
+ context.set({ shown: true, shownSince: Date.now() })
41
+ const unsubscribe = context.subscribe(() => {
42
+ const autoHiding = autoHides(context.state())
43
+ if (autoHiding !== wasAutoHiding) {
44
+ wasAutoHiding = autoHiding
45
+ context.set({ shown: true, shownSince: Date.now() })
46
+ }
47
+ })
48
+ const timer = setInterval(() => {
49
+ const state = context.state()
50
+ if (autoHides(state) && state.shown && Date.now() - state.shownSince >= HIDE_AFTER_MS) {
51
+ context.set({ shown: false })
52
+ }
53
+ }, 250)
54
+ return () => {
55
+ unsubscribe()
56
+ clearInterval(timer)
57
+ }
58
+ },
59
+ Panel: ({ state, set }) => (
60
+ <>
61
+ <Field label="App asks to auto-hide" value={state.appAutoHidden ? 'Yes' : 'No'} />
62
+ <Field label="Mode">
63
+ <Select label="Home indicator mode" value={state.mode} options={[...MODES]} onChange={(mode) => set({ mode })} />
64
+ </Field>
65
+ <Field label="Now" value={indicatorShown(state) ? 'Shown' : 'Hidden'} />
66
+ </>
67
+ ),
68
+ })
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The iPhone's home indicator: whether the app asks for it auto-hidden (`prefersHomeIndicatorAutoHidden`), what the
3
+ * panel or the CLI forces, and whether it shows right now.
4
+ */
5
+ export type HomeIndicatorState = {
6
+ /** The app's focused screen prefers the indicator auto-hidden. */
7
+ appAutoHidden: boolean
8
+ /**
9
+ * `app` follows the app. `visible` and `auto-hide` force what an app could ask for; `hidden` takes the indicator away
10
+ * altogether, which no app can, for clean screenshots.
11
+ */
12
+ mode: 'app' | 'visible' | 'auto-hide' | 'hidden'
13
+ /** Whether it shows now: auto-hidden, it fades out a few seconds after the last touch and comes back on the next. */
14
+ shown: boolean
15
+ /** When it last came back, in ms since the epoch. */
16
+ shownSince: number
17
+ }
18
+
19
+ export const INITIAL_HOME_INDICATOR: HomeIndicatorState = { appAutoHidden: false, mode: 'app', shown: true, shownSince: 0 }
20
+
21
+ /** How long an auto-hidden indicator stays after a touch. */
22
+ export const HIDE_AFTER_MS = 3000
23
+
24
+ export function autoHides(state: HomeIndicatorState): boolean {
25
+ return state.mode === 'auto-hide' || (state.mode === 'app' && state.appAutoHidden)
26
+ }
27
+
28
+ /** Whether the indicator is drawn now. */
29
+ export function indicatorShown(state: HomeIndicatorState): boolean {
30
+ return state.mode !== 'hidden' && (state.shown || !autoHides(state))
31
+ }