@ng-native/desktop 0.0.0 → 0.24.0

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 (401) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -0
  3. package/app.plugin.cjs +17 -0
  4. package/bin/app-config.mjs +168 -0
  5. package/bin/autolink.mjs +224 -0
  6. package/bin/cli.mjs +158 -0
  7. package/bin/host.mjs +427 -0
  8. package/bin/ng-native-desktop.mjs +4 -0
  9. package/bin/package.mjs +971 -0
  10. package/bin/plist.mjs +68 -0
  11. package/bin/prebuilt.mjs +328 -0
  12. package/bin/toolchain.mjs +192 -0
  13. package/native/CMakeLists.txt +277 -0
  14. package/native/appkit/CMakeLists.txt +130 -0
  15. package/native/appkit/address-search.h +26 -0
  16. package/native/appkit/address-search.mm +277 -0
  17. package/native/appkit/animation-frames.h +14 -0
  18. package/native/appkit/animation-frames.mm +106 -0
  19. package/native/appkit/app-info.h +12 -0
  20. package/native/appkit/app-info.mm +98 -0
  21. package/native/appkit/app-updater.mm +128 -0
  22. package/native/appkit/app-windows.h +81 -0
  23. package/native/appkit/app-windows.mm +318 -0
  24. package/native/appkit/appkit-backend.h +73 -0
  25. package/native/appkit/appkit-backend.mm +276 -0
  26. package/native/appkit/apple-authentication.h +19 -0
  27. package/native/appkit/apple-authentication.mm +248 -0
  28. package/native/appkit/apple-button-view.h +10 -0
  29. package/native/appkit/apple-button-view.mm +37 -0
  30. package/native/appkit/apple-id-button.h +16 -0
  31. package/native/appkit/apple-id-button.mm +50 -0
  32. package/native/appkit/audio.h +16 -0
  33. package/native/appkit/audio.mm +275 -0
  34. package/native/appkit/battery.h +13 -0
  35. package/native/appkit/battery.mm +92 -0
  36. package/native/appkit/bookmarks.h +17 -0
  37. package/native/appkit/bookmarks.mm +145 -0
  38. package/native/appkit/calendar.h +25 -0
  39. package/native/appkit/calendar.mm +660 -0
  40. package/native/appkit/camera-sheet.h +59 -0
  41. package/native/appkit/camera-sheet.mm +344 -0
  42. package/native/appkit/camera-view.h +15 -0
  43. package/native/appkit/camera-view.mm +134 -0
  44. package/native/appkit/camera.h +61 -0
  45. package/native/appkit/camera.mm +496 -0
  46. package/native/appkit/cg-canvas.h +24 -0
  47. package/native/appkit/cg-canvas.mm +663 -0
  48. package/native/appkit/component-view.h +17 -0
  49. package/native/appkit/crypto.h +19 -0
  50. package/native/appkit/crypto.mm +78 -0
  51. package/native/appkit/desktop-expo.h +29 -0
  52. package/native/appkit/desktop-expo.mm +385 -0
  53. package/native/appkit/expo-image-drawing.h +46 -0
  54. package/native/appkit/expo-image-drawing.mm +131 -0
  55. package/native/appkit/expo-image-view.h +15 -0
  56. package/native/appkit/expo-image-view.mm +182 -0
  57. package/native/appkit/expo-ui-renderer.h +68 -0
  58. package/native/appkit/expo-ui-renderer.mm +101 -0
  59. package/native/appkit/expo-ui-view.h +26 -0
  60. package/native/appkit/expo-ui-view.mm +134 -0
  61. package/native/appkit/expo-ui.swift +1284 -0
  62. package/native/appkit/file-system.h +16 -0
  63. package/native/appkit/file-system.mm +140 -0
  64. package/native/appkit/fonts.h +12 -0
  65. package/native/appkit/fonts.mm +48 -0
  66. package/native/appkit/geocoder.h +19 -0
  67. package/native/appkit/geocoder.mm +101 -0
  68. package/native/appkit/glass-effect.h +22 -0
  69. package/native/appkit/glass-effect.mm +63 -0
  70. package/native/appkit/glass-view.h +8 -0
  71. package/native/appkit/glass-view.mm +65 -0
  72. package/native/appkit/header-toolbar.h +60 -0
  73. package/native/appkit/header-toolbar.mm +632 -0
  74. package/native/appkit/host-view.h +54 -0
  75. package/native/appkit/host-view.mm +1228 -0
  76. package/native/appkit/image-manipulator.h +14 -0
  77. package/native/appkit/image-manipulator.mm +191 -0
  78. package/native/appkit/image-request.h +22 -0
  79. package/native/appkit/image-request.mm +62 -0
  80. package/native/appkit/image-view.h +8 -0
  81. package/native/appkit/image-view.mm +142 -0
  82. package/native/appkit/input-replay.h +25 -0
  83. package/native/appkit/input-replay.mm +418 -0
  84. package/native/appkit/language-model.h +14 -0
  85. package/native/appkit/language-model.mm +99 -0
  86. package/native/appkit/language-model.swift +472 -0
  87. package/native/appkit/local-authentication.h +15 -0
  88. package/native/appkit/local-authentication.mm +133 -0
  89. package/native/appkit/location.h +16 -0
  90. package/native/appkit/location.mm +214 -0
  91. package/native/appkit/main.mm +1475 -0
  92. package/native/appkit/map-view.h +15 -0
  93. package/native/appkit/map-view.mm +109 -0
  94. package/native/appkit/maps.h +35 -0
  95. package/native/appkit/maps.mm +343 -0
  96. package/native/appkit/menu-bar.h +22 -0
  97. package/native/appkit/menu-bar.mm +208 -0
  98. package/native/appkit/modal-focus.h +16 -0
  99. package/native/appkit/modal-focus.mm +26 -0
  100. package/native/appkit/modal-host-view.h +79 -0
  101. package/native/appkit/modal-host-view.mm +442 -0
  102. package/native/appkit/native-controls.h +22 -0
  103. package/native/appkit/native-controls.mm +431 -0
  104. package/native/appkit/network-state.h +12 -0
  105. package/native/appkit/network-state.mm +64 -0
  106. package/native/appkit/network.h +14 -0
  107. package/native/appkit/network.mm +396 -0
  108. package/native/appkit/notifications.h +19 -0
  109. package/native/appkit/notifications.mm +309 -0
  110. package/native/appkit/photo-library.h +33 -0
  111. package/native/appkit/photo-library.mm +548 -0
  112. package/native/appkit/pointer-buttons.h +32 -0
  113. package/native/appkit/presentation-label.h +15 -0
  114. package/native/appkit/presentation-label.mm +12 -0
  115. package/native/appkit/presented-screen.h +19 -0
  116. package/native/appkit/presented-screen.mm +181 -0
  117. package/native/appkit/printing.h +42 -0
  118. package/native/appkit/printing.mm +393 -0
  119. package/native/appkit/push.h +19 -0
  120. package/native/appkit/push.mm +81 -0
  121. package/native/appkit/red-box.h +26 -0
  122. package/native/appkit/red-box.mm +387 -0
  123. package/native/appkit/screen-capture.h +21 -0
  124. package/native/appkit/screen-capture.mm +92 -0
  125. package/native/appkit/scroll-view.h +13 -0
  126. package/native/appkit/scroll-view.mm +251 -0
  127. package/native/appkit/scrollers.h +25 -0
  128. package/native/appkit/scrollers.mm +43 -0
  129. package/native/appkit/search-field.h +34 -0
  130. package/native/appkit/search-field.mm +291 -0
  131. package/native/appkit/search-toolbar-item.h +19 -0
  132. package/native/appkit/search-toolbar-item.mm +269 -0
  133. package/native/appkit/share-picker.h +34 -0
  134. package/native/appkit/share-picker.mm +121 -0
  135. package/native/appkit/split-view.h +77 -0
  136. package/native/appkit/split-view.mm +1206 -0
  137. package/native/appkit/store-review.h +13 -0
  138. package/native/appkit/store-review.mm +28 -0
  139. package/native/appkit/surface-view.h +45 -0
  140. package/native/appkit/surface-view.mm +562 -0
  141. package/native/appkit/svg-view.h +18 -0
  142. package/native/appkit/svg-view.mm +103 -0
  143. package/native/appkit/symbol-drawing.h +24 -0
  144. package/native/appkit/symbol-drawing.mm +117 -0
  145. package/native/appkit/symbol-view.h +8 -0
  146. package/native/appkit/symbol-view.mm +33 -0
  147. package/native/appkit/system-access.h +34 -0
  148. package/native/appkit/system-access.mm +210 -0
  149. package/native/appkit/system.h +24 -0
  150. package/native/appkit/system.mm +403 -0
  151. package/native/appkit/tab-walk.h +31 -0
  152. package/native/appkit/tab-walk.mm +64 -0
  153. package/native/appkit/test-launch.h +36 -0
  154. package/native/appkit/test-launch.mm +115 -0
  155. package/native/appkit/text-input-field.h +81 -0
  156. package/native/appkit/text-input-field.mm +525 -0
  157. package/native/appkit/text-layout.h +58 -0
  158. package/native/appkit/text-layout.mm +485 -0
  159. package/native/appkit/text-recognition.h +13 -0
  160. package/native/appkit/text-recognition.mm +102 -0
  161. package/native/appkit/tracking.h +13 -0
  162. package/native/appkit/tracking.mm +51 -0
  163. package/native/appkit/tray-and-dock.h +45 -0
  164. package/native/appkit/tray-and-dock.mm +130 -0
  165. package/native/appkit/undo.h +23 -0
  166. package/native/appkit/undo.mm +125 -0
  167. package/native/appkit/updates.h +17 -0
  168. package/native/appkit/updates.mm +71 -0
  169. package/native/appkit/video-view.h +10 -0
  170. package/native/appkit/video-view.mm +42 -0
  171. package/native/appkit/video.h +38 -0
  172. package/native/appkit/video.mm +404 -0
  173. package/native/appkit/web-browser.h +12 -0
  174. package/native/appkit/web-browser.mm +97 -0
  175. package/native/appkit/web-view-component.h +10 -0
  176. package/native/appkit/web-view-component.mm +62 -0
  177. package/native/appkit/web-view.h +31 -0
  178. package/native/appkit/web-view.mm +401 -0
  179. package/native/cmake/libraries/react-native-reanimated.cmake +45 -0
  180. package/native/cmake/libraries/react-native-worklets.cmake +46 -0
  181. package/native/cmake/libraries.cmake +109 -0
  182. package/native/cmake/linked-modules.cmake +112 -0
  183. package/native/cmake/react-native.cmake +175 -0
  184. package/native/cmake/runtime-dependencies.cmake +34 -0
  185. package/native/cmake/swift.cmake +43 -0
  186. package/native/cmake/third-party.cmake +74 -0
  187. package/native/core/include/ngn/absent-views.h +27 -0
  188. package/native/core/include/ngn/accessibility.h +140 -0
  189. package/native/core/include/ngn/address-search.h +69 -0
  190. package/native/core/include/ngn/animation-frames.h +39 -0
  191. package/native/core/include/ngn/app-info.h +52 -0
  192. package/native/core/include/ngn/app-menus.h +151 -0
  193. package/native/core/include/ngn/app-windows.h +181 -0
  194. package/native/core/include/ngn/apple-authentication.h +116 -0
  195. package/native/core/include/ngn/asset.h +28 -0
  196. package/native/core/include/ngn/audio.h +125 -0
  197. package/native/core/include/ngn/back-swipe.h +121 -0
  198. package/native/core/include/ngn/battery.h +48 -0
  199. package/native/core/include/ngn/bytes.h +59 -0
  200. package/native/core/include/ngn/calendar.h +180 -0
  201. package/native/core/include/ngn/camera.h +222 -0
  202. package/native/core/include/ngn/control-sizes.h +111 -0
  203. package/native/core/include/ngn/core-modules.h +108 -0
  204. package/native/core/include/ngn/crypto.h +38 -0
  205. package/native/core/include/ngn/default-menu.h +91 -0
  206. package/native/core/include/ngn/desktop-expo.h +193 -0
  207. package/native/core/include/ngn/desktop-modal.h +109 -0
  208. package/native/core/include/ngn/desktop-props.h +75 -0
  209. package/native/core/include/ngn/desktop-view-props.h +110 -0
  210. package/native/core/include/ngn/dev-server.h +33 -0
  211. package/native/core/include/ngn/dom-web-view.h +53 -0
  212. package/native/core/include/ngn/download.h +24 -0
  213. package/native/core/include/ngn/expo-image.h +192 -0
  214. package/native/core/include/ngn/expo-ui.h +133 -0
  215. package/native/core/include/ngn/file-system.h +274 -0
  216. package/native/core/include/ngn/focus-order.h +63 -0
  217. package/native/core/include/ngn/fonts.h +64 -0
  218. package/native/core/include/ngn/gestures.h +305 -0
  219. package/native/core/include/ngn/glass.h +67 -0
  220. package/native/core/include/ngn/header-bar.h +112 -0
  221. package/native/core/include/ngn/host-state.h +243 -0
  222. package/native/core/include/ngn/image-manipulator.h +70 -0
  223. package/native/core/include/ngn/input-dispatcher.h +211 -0
  224. package/native/core/include/ngn/input-script.h +56 -0
  225. package/native/core/include/ngn/input.h +112 -0
  226. package/native/core/include/ngn/key-value-store.h +41 -0
  227. package/native/core/include/ngn/language-model.h +69 -0
  228. package/native/core/include/ngn/launch-frame.h +47 -0
  229. package/native/core/include/ngn/launch-settings.h +98 -0
  230. package/native/core/include/ngn/layout-animations.h +24 -0
  231. package/native/core/include/ngn/library-components.h +13 -0
  232. package/native/core/include/ngn/library-glue.h +53 -0
  233. package/native/core/include/ngn/live-regions.h +54 -0
  234. package/native/core/include/ngn/local-authentication.h +74 -0
  235. package/native/core/include/ngn/location.h +89 -0
  236. package/native/core/include/ngn/maps.h +226 -0
  237. package/native/core/include/ngn/module-registry.h +51 -0
  238. package/native/core/include/ngn/mounting-backend.h +96 -0
  239. package/native/core/include/ngn/mounting-manager.h +155 -0
  240. package/native/core/include/ngn/native-controls.h +161 -0
  241. package/native/core/include/ngn/native-module.h +109 -0
  242. package/native/core/include/ngn/network-state.h +44 -0
  243. package/native/core/include/ngn/network.h +100 -0
  244. package/native/core/include/ngn/notifications.h +185 -0
  245. package/native/core/include/ngn/photo-library.h +134 -0
  246. package/native/core/include/ngn/printing.h +69 -0
  247. package/native/core/include/ngn/processes.h +114 -0
  248. package/native/core/include/ngn/red-box.h +119 -0
  249. package/native/core/include/ngn/reload-thread.h +258 -0
  250. package/native/core/include/ngn/runtime.h +163 -0
  251. package/native/core/include/ngn/safe-areas.h +82 -0
  252. package/native/core/include/ngn/screen-capture.h +35 -0
  253. package/native/core/include/ngn/screen-presentation.h +85 -0
  254. package/native/core/include/ngn/screen-stacks.h +80 -0
  255. package/native/core/include/ngn/scrollers.h +106 -0
  256. package/native/core/include/ngn/sharing.h +39 -0
  257. package/native/core/include/ngn/spawn-rules.h +78 -0
  258. package/native/core/include/ngn/splash-screen.h +41 -0
  259. package/native/core/include/ngn/split-view.h +270 -0
  260. package/native/core/include/ngn/sqlite.h +38 -0
  261. package/native/core/include/ngn/store-review.h +26 -0
  262. package/native/core/include/ngn/surface-book.h +101 -0
  263. package/native/core/include/ngn/surface-metrics.h +51 -0
  264. package/native/core/include/ngn/svg.h +434 -0
  265. package/native/core/include/ngn/symbol.h +90 -0
  266. package/native/core/include/ngn/system.h +102 -0
  267. package/native/core/include/ngn/tabs-host.h +171 -0
  268. package/native/core/include/ngn/text-input.h +134 -0
  269. package/native/core/include/ngn/text-measurer.h +38 -0
  270. package/native/core/include/ngn/text-recognition.h +55 -0
  271. package/native/core/include/ngn/tracking.h +34 -0
  272. package/native/core/include/ngn/tray-and-dock.h +107 -0
  273. package/native/core/include/ngn/undo.h +37 -0
  274. package/native/core/include/ngn/updates.h +253 -0
  275. package/native/core/include/ngn/video.h +126 -0
  276. package/native/core/include/ngn/view-box.h +126 -0
  277. package/native/core/include/ngn/view-transform.h +26 -0
  278. package/native/core/include/ngn/view-tree.h +85 -0
  279. package/native/core/include/ngn/web-browser.h +45 -0
  280. package/native/core/include/ngn/web-view.h +137 -0
  281. package/native/core/include/ngn/worklet-host.h +98 -0
  282. package/native/core/src/absent-views.cpp +41 -0
  283. package/native/core/src/accessibility.cpp +374 -0
  284. package/native/core/src/animation-frames.cpp +49 -0
  285. package/native/core/src/app-menus.cpp +359 -0
  286. package/native/core/src/app-windows.cpp +444 -0
  287. package/native/core/src/back-swipe.cpp +98 -0
  288. package/native/core/src/bytes.cpp +158 -0
  289. package/native/core/src/control-sizes.cpp +232 -0
  290. package/native/core/src/default-menu.cpp +96 -0
  291. package/native/core/src/desktop-modal.cpp +162 -0
  292. package/native/core/src/desktop-view-props.cpp +80 -0
  293. package/native/core/src/dev-server-helper.cpp +152 -0
  294. package/native/core/src/dev-server.cpp +103 -0
  295. package/native/core/src/dom-web-view.cpp +45 -0
  296. package/native/core/src/download.cpp +53 -0
  297. package/native/core/src/expo-image.cpp +548 -0
  298. package/native/core/src/expo-ui.cpp +203 -0
  299. package/native/core/src/focus-order.cpp +441 -0
  300. package/native/core/src/gestures.cpp +1806 -0
  301. package/native/core/src/glass.cpp +49 -0
  302. package/native/core/src/header-bar.cpp +104 -0
  303. package/native/core/src/host-services.cpp +50 -0
  304. package/native/core/src/host-state.cpp +61 -0
  305. package/native/core/src/input-dispatcher.cpp +727 -0
  306. package/native/core/src/input-script.cpp +123 -0
  307. package/native/core/src/key-value-store.cpp +169 -0
  308. package/native/core/src/launch-settings.cpp +148 -0
  309. package/native/core/src/layout-animations.cpp +62 -0
  310. package/native/core/src/libraries/RNCWebViewSpec.cpp +80 -0
  311. package/native/core/src/libraries/react-native-reanimated.cpp +216 -0
  312. package/native/core/src/libraries/react-native-worklets.cpp +192 -0
  313. package/native/core/src/libraries/rnscreens.cpp +125 -0
  314. package/native/core/src/libraries/rnsvg.cpp +358 -0
  315. package/native/core/src/libraries/safeareacontext.cpp +70 -0
  316. package/native/core/src/libraries/worklets-idle-frames.js +70 -0
  317. package/native/core/src/library-glue.cpp +35 -0
  318. package/native/core/src/live-regions.cpp +122 -0
  319. package/native/core/src/module-registry.cpp +50 -0
  320. package/native/core/src/modules/accessibility-manager.cpp +98 -0
  321. package/native/core/src/modules/address-search.cpp +219 -0
  322. package/native/core/src/modules/alert-manager.cpp +140 -0
  323. package/native/core/src/modules/app-info.cpp +74 -0
  324. package/native/core/src/modules/app-modules.cpp +412 -0
  325. package/native/core/src/modules/apple-authentication.cpp +188 -0
  326. package/native/core/src/modules/asset.cpp +111 -0
  327. package/native/core/src/modules/async-storage.cpp +192 -0
  328. package/native/core/src/modules/audio.cpp +541 -0
  329. package/native/core/src/modules/battery.cpp +88 -0
  330. package/native/core/src/modules/calendar.cpp +457 -0
  331. package/native/core/src/modules/camera.cpp +401 -0
  332. package/native/core/src/modules/core-modules.cpp +62 -0
  333. package/native/core/src/modules/crypto.cpp +117 -0
  334. package/native/core/src/modules/desktop-expo.cpp +527 -0
  335. package/native/core/src/modules/file-system.cpp +941 -0
  336. package/native/core/src/modules/fonts.cpp +163 -0
  337. package/native/core/src/modules/image-loader.cpp +105 -0
  338. package/native/core/src/modules/image-manipulator.cpp +305 -0
  339. package/native/core/src/modules/language-model.cpp +195 -0
  340. package/native/core/src/modules/local-authentication.cpp +140 -0
  341. package/native/core/src/modules/location.cpp +186 -0
  342. package/native/core/src/modules/maps.cpp +500 -0
  343. package/native/core/src/modules/network-state.cpp +72 -0
  344. package/native/core/src/modules/networking.cpp +387 -0
  345. package/native/core/src/modules/notifications.cpp +549 -0
  346. package/native/core/src/modules/photo-library.cpp +385 -0
  347. package/native/core/src/modules/printing.cpp +201 -0
  348. package/native/core/src/modules/screen-capture.cpp +71 -0
  349. package/native/core/src/modules/sharing.cpp +59 -0
  350. package/native/core/src/modules/splash-screen.cpp +70 -0
  351. package/native/core/src/modules/sqlite.cpp +421 -0
  352. package/native/core/src/modules/store-review.cpp +23 -0
  353. package/native/core/src/modules/text-recognition.cpp +107 -0
  354. package/native/core/src/modules/tracking.cpp +46 -0
  355. package/native/core/src/modules/undo.cpp +59 -0
  356. package/native/core/src/modules/video.cpp +366 -0
  357. package/native/core/src/modules/web-browser.cpp +100 -0
  358. package/native/core/src/modules/web-socket.cpp +266 -0
  359. package/native/core/src/mounting-manager.cpp +384 -0
  360. package/native/core/src/native-controls.cpp +129 -0
  361. package/native/core/src/native-module.cpp +250 -0
  362. package/native/core/src/network.cpp +219 -0
  363. package/native/core/src/posix-launcher.cpp +366 -0
  364. package/native/core/src/processes.cpp +324 -0
  365. package/native/core/src/red-box-errors.js +83 -0
  366. package/native/core/src/red-box.cpp +306 -0
  367. package/native/core/src/runtime.cpp +420 -0
  368. package/native/core/src/safe-areas.cpp +137 -0
  369. package/native/core/src/screen-presentation.cpp +61 -0
  370. package/native/core/src/screen-stacks.cpp +254 -0
  371. package/native/core/src/scrollers.cpp +181 -0
  372. package/native/core/src/spawn-rules.cpp +292 -0
  373. package/native/core/src/split-view.cpp +343 -0
  374. package/native/core/src/svg.cpp +2190 -0
  375. package/native/core/src/symbol.cpp +94 -0
  376. package/native/core/src/tabs-host.cpp +234 -0
  377. package/native/core/src/text-input.cpp +139 -0
  378. package/native/core/src/text-layout-manager.cpp +63 -0
  379. package/native/core/src/tray-and-dock.cpp +154 -0
  380. package/native/core/src/updates.cpp +965 -0
  381. package/native/core/src/view-box.cpp +788 -0
  382. package/native/core/src/view-transform.cpp +45 -0
  383. package/native/core/src/view-tree.cpp +234 -0
  384. package/native/core/src/web-view.cpp +143 -0
  385. package/native/core/src/worklet-host.cpp +10 -0
  386. package/native/scripts/build-hermes.sh +44 -0
  387. package/native/scripts/build.sh +175 -0
  388. package/native/scripts/cache-dir.sh +18 -0
  389. package/native/scripts/codegen-library.sh +193 -0
  390. package/native/scripts/compiler-launcher.sh +17 -0
  391. package/native/scripts/fetch.sh +174 -0
  392. package/native/scripts/hermes-built.sh +10 -0
  393. package/native/scripts/host-dir.sh +16 -0
  394. package/native/scripts/launch-probe.sh +60 -0
  395. package/native/scripts/macos-target.sh +8 -0
  396. package/native/scripts/make-prebuilt.mjs +360 -0
  397. package/native/scripts/prebuilt-host-cache.mjs +158 -0
  398. package/native/shim/openssl/sha.h +22 -0
  399. package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +37 -0
  400. package/package.json +73 -1
  401. package/prebuilt.json +33 -0
@@ -0,0 +1,137 @@
1
+ // react-native-webview's RNCWebView on a desktop host: what the core decides for a web view, apart
2
+ // from the toolkit's web engine. The host compiles the component in only with the library
3
+ // (`build.sh --library`, core/src/libraries/RNCWebViewSpec.cpp), which reads the library's props
4
+ // into a WebViewConfig; the backend's view loads it into its engine (WKWebView on macOS) and sends
5
+ // the library's iOS events: loadingStart, loadingFinish, loadingError, loadingProgress, httpError,
6
+ // message, shouldStartLoadWithRequest, openWindow and contentProcessDidTerminate.
7
+ //
8
+ // As on iOS, every navigation waits for the app: shouldStartLoadWithRequest carries a
9
+ // `lockIdentifier`, and the navigation goes ahead or stops once the app answers
10
+ // RNCWebViewModule.shouldStartLoadWithLockIdentifier(shouldStart, lockIdentifier). On a desktop
11
+ // host the view also takes `originWhitelist`, which the library's JavaScript applies on iOS and
12
+ // Android: a page navigation to an origin it does not match is not made, and the url is handed to
13
+ // the OS to open, as the library's JavaScript does with Linking.
14
+ #pragma once
15
+
16
+ #include "ngn/file-system.h"
17
+ #include "ngn/native-module.h"
18
+
19
+ #include <folly/dynamic.h>
20
+
21
+ #include <functional>
22
+ #include <map>
23
+ #include <memory>
24
+ #include <mutex>
25
+ #include <optional>
26
+ #include <string>
27
+ #include <string_view>
28
+ #include <utility>
29
+ #include <vector>
30
+
31
+ namespace ngn {
32
+
33
+ struct WebViewSource {
34
+ std::string uri;
35
+ std::string method;
36
+ std::string body;
37
+ std::vector<std::pair<std::string, std::string>> headers;
38
+ std::string html;
39
+ std::string baseUrl;
40
+ bool operator==(const WebViewSource &) const = default;
41
+ };
42
+
43
+ // A web view's page from a file (a source's `uri`, or the `baseUrl` of its `html`), inside the file
44
+ // boundary: the file uri checked, what the page may read beside it (its folder where the app may
45
+ // read that, else the file alone) and the pick held open. Nothing for a uri that is not a file;
46
+ // throws FileRefused for one outside.
47
+ struct WebViewFile {
48
+ std::string uri;
49
+ std::string readAccess;
50
+ std::shared_ptr<FileAccess::Use> use;
51
+ };
52
+ std::optional<WebViewFile> webViewFile(const FileAccess *access, const std::string &uri);
53
+
54
+ struct WebViewConfig {
55
+ WebViewSource source;
56
+ std::string injectedJavaScript;
57
+ std::string injectedJavaScriptBeforeContentLoaded;
58
+ bool injectedJavaScriptForMainFrameOnly{true};
59
+ bool injectedJavaScriptBeforeContentLoadedForMainFrameOnly{true};
60
+ // window.ReactNativeWebView.injectedObjectJson()'s answer, when set.
61
+ std::string injectedJavaScriptObject;
62
+ bool messagingEnabled{false};
63
+ bool javaScriptEnabled{true};
64
+ bool javaScriptCanOpenWindowsAutomatically{false};
65
+ bool hasOnOpenWindowEvent{false};
66
+ bool incognito{false};
67
+ bool webviewDebuggingEnabled{false};
68
+ bool allowsBackForwardNavigationGestures{false};
69
+ std::string userAgent;
70
+ std::string applicationNameForUserAgent;
71
+ // Nothing when the prop is not set, and then no origin is refused.
72
+ std::optional<std::vector<std::string>> originWhitelist;
73
+ // Whether a navigation waits for the app's answer (shouldStartLoadWithRequest), as
74
+ // react-native-webview's does. Expo's DOM web view (dom-web-view.h) lets each one go ahead.
75
+ bool asksApp{true};
76
+ bool operator==(const WebViewConfig &) const = default;
77
+ };
78
+
79
+ // The origin the library's JavaScript compares (extractOrigin): the scheme and, for a url with
80
+ // one, its authority, as written. Empty for a string with no scheme.
81
+ std::string webViewOrigin(const std::string &url);
82
+
83
+ // Whether `url`'s origin matches one of `whitelist`'s patterns, `*` matching anything, from the
84
+ // start of the origin, as the library's JavaScript compares them. `about:` and `data:` urls, which
85
+ // a page made from `html` is at, always do.
86
+ bool passesOriginWhitelist(const std::vector<std::string> &whitelist, const std::string &url);
87
+
88
+ // What a navigation to `url` waits for: the app's answer, or nothing. A page navigation outside
89
+ // `originWhitelist` is handed to the OS only when the user made it (`navigationType`, the library's
90
+ // name for it, is "click" or "formsubmit") and Linking would open it (externalUrlAllowed); any
91
+ // other is cancelled, so a page's script cannot open a scheme or a file on its own. Any other
92
+ // navigation is the app's to answer, or, without `asksApp`, goes ahead.
93
+ enum class NavigationStep { AskApp, Allow, OpenExternally, Cancel };
94
+ NavigationStep navigationStep(const WebViewConfig &config, const std::string &url, bool topFrame, std::string_view navigationType);
95
+
96
+ // The script, at document start, that gives the page window.ReactNativeWebView.postMessage, sent
97
+ // to the host's script message handler named "ReactNativeWebView" as a string.
98
+ std::string webViewMessagingScript();
99
+ // The script that gives the page window.ReactNativeWebView.injectedObjectJson().
100
+ std::string webViewInjectedObjectScript(const std::string &json);
101
+ // The script `postMessage(data)` runs in the page: a MessageEvent on the window.
102
+ std::string webViewPostMessageScript(const std::string &data);
103
+
104
+ // What every event carries, as the library's iOS view builds it (baseEvent).
105
+ struct WebViewState {
106
+ std::string url;
107
+ std::string title;
108
+ bool loading{false};
109
+ bool canGoBack{false};
110
+ bool canGoForward{false};
111
+ };
112
+ folly::dynamic webViewEvent(const WebViewState &state);
113
+
114
+ // The navigations waiting for the app, by lock identifier, shared by every web view and
115
+ // RNCWebViewModule. Any thread.
116
+ class NavigationLocks {
117
+ public:
118
+ // Holds a navigation until `decide` is answered; returns its lock identifier.
119
+ int hold(std::function<void(bool shouldStart)> decide);
120
+ // Answers the navigation held as `lock`, once; false for a lock not held.
121
+ bool settle(int lock, bool shouldStart);
122
+ // How many navigations wait.
123
+ size_t pending() const;
124
+
125
+ private:
126
+ mutable std::mutex mutex_;
127
+ std::map<int, std::function<void(bool)>> held_;
128
+ int next_{1};
129
+ };
130
+
131
+ // RNCWebViewModule: shouldStartLoadWithLockIdentifier(shouldStart, lockIdentifier).
132
+ std::shared_ptr<NativeModule> makeWebViewModule(std::shared_ptr<NavigationLocks> locks);
133
+
134
+ // The locks every web view in the host shares.
135
+ std::shared_ptr<NavigationLocks> sharedNavigationLocks();
136
+
137
+ } // namespace ngn
@@ -0,0 +1,98 @@
1
+ // What react-native-worklets, Reanimated and the gesture handler's glue take from the host, which
2
+ // React Native iOS gives their modules through RCTBridge, RCTSurfacePresenter and the main queue.
3
+ // The runtime and the backend fill it in at start-up; the glue (core/src/libraries/) reads it when
4
+ // JavaScript first asks for the modules. A host built without the libraries never reads it.
5
+ #pragma once
6
+
7
+ #include "ngn/animation-frames.h"
8
+
9
+ #include <folly/dynamic.h>
10
+ #include <react/renderer/core/Props.h>
11
+ #include <react/renderer/core/ReactPrimitives.h>
12
+
13
+ #include <functional>
14
+ #include <memory>
15
+ #include <mutex>
16
+ #include <string>
17
+ #include <utility>
18
+
19
+ namespace facebook::react {
20
+ class Scheduler;
21
+ }
22
+
23
+ namespace ngn {
24
+
25
+ // A callback one thread sets or clears while another calls it: a reload clears the glue's on its
26
+ // own thread while the UI thread calls them. A call holds the whole callback it read, so clearing
27
+ // during it neither tears it nor frees its closure.
28
+ template <typename Signature>
29
+ class SharedCallback {
30
+ public:
31
+ using Function = std::function<Signature>;
32
+
33
+ void set(Function function) {
34
+ auto next = function ? std::make_shared<const Function>(std::move(function)) : nullptr;
35
+ std::lock_guard lock(mutex_);
36
+ // The old callback is released after the lock, in case its closure's destructor sets this.
37
+ std::swap(function_, next);
38
+ }
39
+ std::shared_ptr<const Function> get() const {
40
+ std::lock_guard lock(mutex_);
41
+ return function_;
42
+ }
43
+ explicit operator bool() const {
44
+ return get() != nullptr;
45
+ }
46
+ // Calls the callback if one is set, and says whether one was.
47
+ template <typename... Args>
48
+ bool call(Args &&...args) const {
49
+ auto function = get();
50
+ if (!function) {
51
+ return false;
52
+ }
53
+ (*function)(std::forward<Args>(args)...);
54
+ return true;
55
+ }
56
+
57
+ private:
58
+ mutable std::mutex mutex_;
59
+ std::shared_ptr<const Function> function_;
60
+ };
61
+
62
+ struct WorkletHost {
63
+ // The backend's UI thread, the one its views and its display link belong to: the worklets' UI
64
+ // runtime runs there.
65
+ std::function<void(std::function<void()> task)> runOnUiThread;
66
+ std::function<bool()> isUiThread;
67
+ // Now in milliseconds, on the clock the frames are stamped with.
68
+ std::function<double()> now;
69
+ // The display frames, which the backend drives while they are wanted.
70
+ AnimationFrames frames;
71
+ // The running ReactHost's scheduler (its UIManager), set by the Runtime and cleared by a reload
72
+ // on its own thread. Any thread.
73
+ SharedCallback<void(std::function<void(facebook::react::Scheduler &)>)> runOnScheduler;
74
+ // React Native's fast path for props that need no layout (IMountingManager's
75
+ // synchronouslyUpdateViewOnUIThread). UI thread.
76
+ std::function<void(facebook::react::Tag tag, const folly::dynamic &props)> synchronouslyUpdateView;
77
+ // The props a view is mounted with now, or null. UI thread.
78
+ std::function<facebook::react::Props::Shared(facebook::react::Tag tag)> readMountedProps;
79
+
80
+ // Set by the worklets' glue while its module lives: the UI runtime's frame loop, parked while it
81
+ // has nothing to do (worklets-idle-frames.js), runs a frame again. Called after work that ran on
82
+ // the UI runtime outside a frame and may have changed a shared value. Called on the UI thread;
83
+ // set on the JS thread and cleared as the module goes, on the reload's thread.
84
+ SharedCallback<void()> wakeUiFrames;
85
+
86
+ // Set by Reanimated's glue while its module lives: an event for the worklets registered on a
87
+ // view, as React Native iOS's RCTEventDispatcher hands RNGestureHandler's events to Reanimated.
88
+ // Called on the UI thread; set and cleared as wakeUiFrames is.
89
+ SharedCallback<void(const std::string &name, facebook::react::Tag viewTag, const folly::dynamic &payload)> reanimatedEvent;
90
+ // Set by the gesture handler's module: a worklet's GestureStateManager moving a handler's state
91
+ // (begin, activate, fail, end), as Reanimated's setGestureState asks RNGestureHandlerModule.
92
+ // UI thread.
93
+ std::function<void(int handlerTag, int state)> setGestureState;
94
+ };
95
+
96
+ WorkletHost &workletHost();
97
+
98
+ } // namespace ngn
@@ -0,0 +1,41 @@
1
+ #include "ngn/absent-views.h"
2
+
3
+ namespace ngn {
4
+
5
+ const std::vector<AbsentView> &absentViews() {
6
+ static constexpr std::string_view kNoPull = "a Mac has no pull to refresh: a scroll view stops at its top";
7
+ static constexpr std::string_view kNoKeyboard = "a Mac has no software keyboard to follow or sit on";
8
+ static const std::vector<AbsentView> views{
9
+ // `<refresh-control>`: iOS's and Android's.
10
+ {"PullToRefreshView", kNoPull},
11
+ {"AndroidSwipeRefreshLayout", kNoPull},
12
+ // `<input-accessory-view>`.
13
+ {"InputAccessoryView", kNoKeyboard},
14
+ // `<keyboard-dock>`, `<keyboard-avoiding-view>`'s helpers and the rest of
15
+ // react-native-keyboard-controller's views.
16
+ {"KeyboardControllerView", kNoKeyboard},
17
+ {"KeyboardGestureArea", kNoKeyboard},
18
+ {"KeyboardExtender", kNoKeyboard},
19
+ {"KeyboardBackgroundView", kNoKeyboard},
20
+ {"KeyboardToolbarGroupView", kNoKeyboard},
21
+ {"OverKeyboardView", kNoKeyboard},
22
+ {"ClippingScrollViewDecoratorView", kNoKeyboard},
23
+ // Community views whose libraries ship no macOS code, and no host view stands in for.
24
+ {"RNCSlider", "@react-native-community/slider has no macOS view: ui-slider (@expo/ui) is a SwiftUI slider"},
25
+ {"RNCPicker", "@react-native-picker/picker has no macOS view: ui-picker (@expo/ui) is a SwiftUI picker"},
26
+ {"RNCPickerItem", "@react-native-picker/picker has no macOS view: ui-picker (@expo/ui) is a SwiftUI picker"},
27
+ {"RNCMaskedView", "@react-native-masked-view/masked-view has no macOS view: the content shows unmasked"},
28
+ };
29
+ return views;
30
+ }
31
+
32
+ std::optional<std::string_view> absentReason(std::string_view name) {
33
+ for (const auto &view : absentViews()) {
34
+ if (view.name == name) {
35
+ return view.reason;
36
+ }
37
+ }
38
+ return std::nullopt;
39
+ }
40
+
41
+ } // namespace ngn
@@ -0,0 +1,374 @@
1
+ #include "ngn/accessibility.h"
2
+ #include "ngn/desktop-props.h"
3
+ #include "ngn/view-tree.h"
4
+
5
+ #include <react/renderer/components/text/ParagraphState.h>
6
+ #include <react/renderer/components/view/accessibilityPropsConversions.h>
7
+ #include <react/renderer/core/ConcreteState.h>
8
+
9
+ #include <algorithm>
10
+ #include <unordered_map>
11
+ #include <unordered_set>
12
+
13
+ using namespace facebook::react;
14
+
15
+ namespace ngn {
16
+
17
+ namespace {
18
+
19
+ struct Mapping {
20
+ AxRole role;
21
+ AxSubrole subrole{AxSubrole::None};
22
+ // For a role the toolkit has no equivalent of.
23
+ const char *description{""};
24
+ };
25
+
26
+ // React Native's accessibilityRole values and the ARIA roles `role` takes, as AppKit has them.
27
+ // A role with no AppKit counterpart is a group that says what it is.
28
+ const std::unordered_map<std::string, Mapping> &roles() {
29
+ static const std::unordered_map<std::string, Mapping> table{
30
+ {"button", {AxRole::Button}},
31
+ {"togglebutton", {AxRole::CheckBox, AxSubrole::Toggle}},
32
+ {"link", {AxRole::Link}},
33
+ {"image", {AxRole::Image}},
34
+ {"img", {AxRole::Image}},
35
+ {"imagebutton", {AxRole::Button}},
36
+ {"text", {AxRole::StaticText}},
37
+ {"checkbox", {AxRole::CheckBox}},
38
+ {"switch", {AxRole::CheckBox, AxSubrole::Switch}},
39
+ {"radio", {AxRole::RadioButton}},
40
+ {"radiogroup", {AxRole::RadioGroup}},
41
+ {"adjustable", {AxRole::Slider}},
42
+ {"slider", {AxRole::Slider}},
43
+ {"search", {AxRole::TextField, AxSubrole::SearchField}},
44
+ {"searchbox", {AxRole::TextField, AxSubrole::SearchField}},
45
+ {"list", {AxRole::List}},
46
+ {"menu", {AxRole::Menu}},
47
+ {"menuitem", {AxRole::MenuItem}},
48
+ {"menubar", {AxRole::MenuBar}},
49
+ {"progressbar", {AxRole::ProgressIndicator}},
50
+ {"combobox", {AxRole::ComboBox}},
51
+ {"tablist", {AxRole::TabGroup}},
52
+ {"tab", {AxRole::RadioButton, AxSubrole::Tab}},
53
+ {"toolbar", {AxRole::Toolbar}},
54
+ {"scrollbar", {AxRole::ScrollBar}},
55
+ {"grid", {AxRole::Table}},
56
+ {"table", {AxRole::Table}},
57
+ {"row", {AxRole::Row}},
58
+ {"cell", {AxRole::Cell}},
59
+ {"spinbutton", {AxRole::Incrementor}},
60
+ {"header", {AxRole::Heading, AxSubrole::None, "heading"}},
61
+ {"heading", {AxRole::Heading, AxSubrole::None, "heading"}},
62
+ {"meter", {AxRole::LevelIndicator}},
63
+ {"tree", {AxRole::Outline}},
64
+ {"treegrid", {AxRole::Outline}},
65
+ {"treeitem", {AxRole::Row, AxSubrole::OutlineRow}},
66
+ {"scrollview", {AxRole::ScrollArea}},
67
+ {"horizontalscrollview", {AxRole::ScrollArea}},
68
+ {"tabbar", {AxRole::TabGroup}},
69
+ {"iconmenu", {AxRole::Menu}},
70
+ {"keyboardkey", {AxRole::Button}},
71
+ {"directory", {AxRole::List, AxSubrole::None, "directory"}},
72
+ {"feed", {AxRole::List, AxSubrole::None, "feed"}},
73
+ {"option", {AxRole::Row, AxSubrole::None, "option"}},
74
+ // ARIA roles React Native's Role lacks, read as written (DesktopProps::role).
75
+ {"listbox", {AxRole::List}},
76
+ {"gridcell", {AxRole::Cell}},
77
+ {"menuitemcheckbox", {AxRole::MenuItem}},
78
+ {"menuitemradio", {AxRole::MenuItem}},
79
+ {"columnheader", {AxRole::Cell, AxSubrole::None, "column header"}},
80
+ {"rowheader", {AxRole::Cell, AxSubrole::None, "row header"}},
81
+ {"term", {AxRole::StaticText, AxSubrole::None, "term"}},
82
+ {"application", {AxRole::Group, AxSubrole::None, "application"}},
83
+ {"article", {AxRole::Group, AxSubrole::None, "article"}},
84
+ {"complementary", {AxRole::Group, AxSubrole::None, "complementary"}},
85
+ {"contentinfo", {AxRole::Group, AxSubrole::None, "content information"}},
86
+ {"definition", {AxRole::Group, AxSubrole::None, "definition"}},
87
+ {"document", {AxRole::Group, AxSubrole::None, "document"}},
88
+ {"figure", {AxRole::Group, AxSubrole::None, "figure"}},
89
+ {"form", {AxRole::Group, AxSubrole::None, "form"}},
90
+ {"log", {AxRole::Group, AxSubrole::None, "log"}},
91
+ {"marquee", {AxRole::Group, AxSubrole::None, "marquee"}},
92
+ {"math", {AxRole::Group, AxSubrole::None, "math"}},
93
+ {"note", {AxRole::Group, AxSubrole::None, "note"}},
94
+ {"region", {AxRole::Group, AxSubrole::None, "region"}},
95
+ {"rowgroup", {AxRole::Group, AxSubrole::None, "row group"}},
96
+ {"separator", {AxRole::Group, AxSubrole::None, "separator"}},
97
+ {"tabpanel", {AxRole::Group, AxSubrole::None, "tab panel"}},
98
+ {"pager", {AxRole::Group, AxSubrole::None, "pager"}},
99
+ {"drawerlayout", {AxRole::Group, AxSubrole::None, "drawer"}},
100
+ {"slidingdrawer", {AxRole::Group, AxSubrole::None, "drawer"}},
101
+ {"webview", {AxRole::Group, AxSubrole::None, "web view"}},
102
+ {"alert", {AxRole::Group, AxSubrole::None, "alert"}},
103
+ {"alertdialog", {AxRole::Group, AxSubrole::None, "alert dialog"}},
104
+ {"dialog", {AxRole::Group, AxSubrole::None, "dialog"}},
105
+ {"listitem", {AxRole::Group, AxSubrole::None, "list item"}},
106
+ {"navigation", {AxRole::Group, AxSubrole::None, "navigation"}},
107
+ {"main", {AxRole::Group, AxSubrole::None, "main"}},
108
+ {"banner", {AxRole::Group, AxSubrole::None, "banner"}},
109
+ {"summary", {AxRole::Group, AxSubrole::None, "summary"}},
110
+ {"timer", {AxRole::Group, AxSubrole::None, "timer"}},
111
+ {"status", {AxRole::Group, AxSubrole::None, "status"}},
112
+ {"tooltip", {AxRole::Group, AxSubrole::None, "tooltip"}},
113
+ };
114
+ return table;
115
+ }
116
+
117
+ // The roles a press means something on: AppKit's controls, which VoiceOver presses.
118
+ bool pressableRole(const std::string &name) {
119
+ static const std::unordered_set<std::string> names{"button", "togglebutton", "link", "imagebutton", "checkbox",
120
+ "switch", "radio", "tab", "menuitem", "menuitemcheckbox", "menuitemradio", "combobox", "searchbox", "search"};
121
+ return names.contains(name);
122
+ }
123
+
124
+ // The roles that are one thing to read, whatever views draw them.
125
+ bool leafRole(AxRole role) {
126
+ switch (role) {
127
+ case AxRole::Button:
128
+ case AxRole::Link:
129
+ case AxRole::Image:
130
+ case AxRole::StaticText:
131
+ case AxRole::CheckBox:
132
+ case AxRole::RadioButton:
133
+ case AxRole::Slider:
134
+ case AxRole::TextField:
135
+ case AxRole::MenuItem:
136
+ case AxRole::ProgressIndicator:
137
+ case AxRole::ComboBox:
138
+ case AxRole::Incrementor:
139
+ case AxRole::Heading:
140
+ case AxRole::LevelIndicator:
141
+ return true;
142
+ default:
143
+ return false;
144
+ }
145
+ }
146
+
147
+ bool adjustableRole(const std::string &name) {
148
+ return name == "adjustable" || name == "slider" || name == "spinbutton";
149
+ }
150
+
151
+ bool declares(const ViewProps &props, const std::string &action) {
152
+ for (const auto &declared : props.accessibilityActions) {
153
+ if (declared.name == action) {
154
+ return true;
155
+ }
156
+ }
157
+ return false;
158
+ }
159
+
160
+ } // namespace
161
+
162
+ std::string roleName(const ViewProps &props) {
163
+ if (props.role != Role::None) {
164
+ return toString(props.role);
165
+ }
166
+ // An ARIA role React Native's Role lacks, as written.
167
+ if (const auto *desktop = dynamic_cast<const HasDesktopProps *>(&props); desktop && !desktop->desktop.role.empty()) {
168
+ return desktop->desktop.role;
169
+ }
170
+ return props.accessibilityRole;
171
+ }
172
+
173
+ AxInfo accessibilityInfo(const ViewProps &props) {
174
+ AxInfo info;
175
+ auto name = roleName(props);
176
+ bool presentation = name == "none" || name == "presentation";
177
+ if (auto it = roles().find(name); it != roles().end()) {
178
+ info.role = it->second.role;
179
+ info.subrole = it->second.subrole;
180
+ info.roleDescription = it->second.description;
181
+ }
182
+ info.label = props.accessibilityLabel;
183
+ info.hint = props.accessibilityHint;
184
+ if (props.accessibilityValue.text) {
185
+ info.value = *props.accessibilityValue.text;
186
+ } else if (props.accessibilityValue.now) {
187
+ info.value = std::to_string(*props.accessibilityValue.now);
188
+ }
189
+ if (const auto &state = props.accessibilityState) {
190
+ info.disabled = state->disabled;
191
+ info.selected = state->selected;
192
+ switch (state->checked) {
193
+ case AccessibilityState::Unchecked:
194
+ info.checked = 0;
195
+ break;
196
+ case AccessibilityState::Checked:
197
+ info.checked = 1;
198
+ break;
199
+ case AccessibilityState::Mixed:
200
+ info.checked = 2;
201
+ break;
202
+ case AccessibilityState::None:
203
+ break;
204
+ }
205
+ }
206
+ static const std::unordered_set<std::string> landmarks{
207
+ "banner", "main", "navigation", "complementary", "contentinfo", "form", "region"};
208
+ info.landmark = landmarks.contains(name);
209
+ if (const auto *desktop = dynamic_cast<const HasDesktopProps *>(&props); desktop && info.role == AxRole::Heading) {
210
+ info.level = desktop->desktop.accessibilityLevel;
211
+ }
212
+ if (props.accessibilityState) {
213
+ info.expanded = props.accessibilityState->expanded;
214
+ }
215
+ for (const auto &action : props.accessibilityActions) {
216
+ const auto &n = action.name;
217
+ if (n != "activate" && n != "increment" && n != "decrement" && n != "escape") {
218
+ info.customActions.push_back({n, action.label.value_or(n)});
219
+ }
220
+ }
221
+ info.offersPress = props.onAccessibilityTap || declares(props, "activate") || pressableRole(name);
222
+ info.offersIncrement = adjustableRole(name) || declares(props, "increment") || declares(props, "decrement");
223
+ info.offersCancel = props.onAccessibilityEscape || declares(props, "escape");
224
+ bool hidden = props.accessibilityElementsHidden ||
225
+ props.importantForAccessibility == ImportantForAccessibility::NoHideDescendants ||
226
+ props.importantForAccessibility == ImportantForAccessibility::No;
227
+ info.element = !hidden && !presentation && (props.accessible || !info.label.empty() || !name.empty());
228
+ info.hidesChildren = info.element && (props.accessible || leafRole(info.role));
229
+ return info;
230
+ }
231
+
232
+ AxInfo paragraphAccessibilityInfo(const ViewProps &props, const std::string &text) {
233
+ auto info = accessibilityInfo(props);
234
+ if (roleName(props).empty()) {
235
+ info.role = AxRole::StaticText;
236
+ }
237
+ if (info.value.empty()) {
238
+ info.value = text;
239
+ }
240
+ // A paragraph in another role (a heading, a link) is named by its text, as VoiceOver reads a
241
+ // title rather than a value for those.
242
+ if (info.role != AxRole::StaticText && info.label.empty()) {
243
+ info.label = text;
244
+ }
245
+ bool hidden = props.accessibilityElementsHidden ||
246
+ props.importantForAccessibility == ImportantForAccessibility::NoHideDescendants ||
247
+ props.importantForAccessibility == ImportantForAccessibility::No;
248
+ auto name = roleName(props);
249
+ info.element = !hidden && name != "none" && name != "presentation" && (!text.empty() || !info.label.empty());
250
+ // Its text is its own; anything under it (an inline view) is part of what it says.
251
+ info.hidesChildren = info.element;
252
+ return info;
253
+ }
254
+
255
+ std::string paragraphText(const ShadowView &view) {
256
+ if (std::string_view(view.componentName) != "Paragraph" || !view.state) {
257
+ return "";
258
+ }
259
+ return paragraphText(view.state);
260
+ }
261
+
262
+ std::string paragraphText(const State::Shared &state) {
263
+ if (!state) {
264
+ return "";
265
+ }
266
+ // A Paragraph's state is always ParagraphState (its component descriptor makes it).
267
+ return std::static_pointer_cast<const ConcreteState<ParagraphState>>(state)->getData().attributedString.getString();
268
+ }
269
+
270
+ std::vector<AxRotor> rotorsOf(const AxInfo &info) {
271
+ if (!info.element) {
272
+ return {};
273
+ }
274
+ if (info.role == AxRole::Heading) {
275
+ return {AxRotor::Headings};
276
+ }
277
+ if (info.role == AxRole::Link) {
278
+ return {AxRotor::Links};
279
+ }
280
+ if (info.landmark) {
281
+ return {AxRotor::Landmarks};
282
+ }
283
+ return {};
284
+ }
285
+
286
+ namespace {
287
+
288
+ // Hidden with everything under it, as React Native reads these two; importantForAccessibility "no"
289
+ // hides only the view itself.
290
+ bool hidesSubtree(const ViewProps &props) {
291
+ return props.accessibilityElementsHidden || props.importantForAccessibility == ImportantForAccessibility::NoHideDescendants;
292
+ }
293
+
294
+ void collectRotor(const ViewTree &tree, Tag tag, Tag root, AxRotor kind, std::vector<Tag> &out) {
295
+ const auto *node = tree.find(tag);
296
+ if (node == nullptr || tree.covered(tag) || (tag != root && tree.isContainerRoot(tag)) ||
297
+ node->view.layoutMetrics.displayType == DisplayType::None) {
298
+ return;
299
+ }
300
+ if (const auto *props = dynamic_cast<const ViewProps *>(node->view.props.get())) {
301
+ if (hidesSubtree(*props)) {
302
+ return;
303
+ }
304
+ auto info = std::string_view(node->view.componentName) == "Paragraph" ? paragraphAccessibilityInfo(*props, paragraphText(node->view))
305
+ : accessibilityInfo(*props);
306
+ auto rotors = rotorsOf(info);
307
+ if (std::find(rotors.begin(), rotors.end(), kind) != rotors.end()) {
308
+ out.push_back(tag);
309
+ }
310
+ if (info.hidesChildren) {
311
+ return;
312
+ }
313
+ }
314
+ for (auto child : node->children) {
315
+ collectRotor(tree, child, root, kind, out);
316
+ }
317
+ }
318
+
319
+ } // namespace
320
+
321
+ std::vector<Tag> rotorItems(const ViewTree &tree, Tag root, AxRotor kind) {
322
+ std::vector<Tag> out;
323
+ collectRotor(tree, root, root, kind, out);
324
+ return out;
325
+ }
326
+
327
+ std::optional<size_t> rotorStep(size_t count, std::optional<size_t> current, bool forward) {
328
+ if (count == 0) {
329
+ return std::nullopt;
330
+ }
331
+ if (!current) {
332
+ return forward ? 0 : count - 1;
333
+ }
334
+ if (forward) {
335
+ return *current + 1 < count ? std::optional<size_t>(*current + 1) : std::nullopt;
336
+ }
337
+ return *current > 0 ? std::optional<size_t>(*current - 1) : std::nullopt;
338
+ }
339
+
340
+ std::optional<size_t> rotorStep(const std::vector<bool> &matches, std::optional<size_t> current, bool forward) {
341
+ for (auto at = rotorStep(matches.size(), current, forward); at; at = rotorStep(matches.size(), at, forward)) {
342
+ if (matches[*at]) {
343
+ return at;
344
+ }
345
+ }
346
+ return std::nullopt;
347
+ }
348
+
349
+ AxDispatch axDispatch(const ViewProps &props, AxVerb verb) {
350
+ auto action = [&](const char *name) { return AxDispatch{AxDispatch::Kind::Action, name}; };
351
+ bool actions = props.onAccessibilityAction;
352
+ switch (verb) {
353
+ case AxVerb::Press:
354
+ if (props.onAccessibilityTap) {
355
+ return {AxDispatch::Kind::Tap, ""};
356
+ }
357
+ if (actions && declares(props, "activate")) {
358
+ return action("activate");
359
+ }
360
+ return {AxDispatch::Kind::Click, ""};
361
+ case AxVerb::Increment:
362
+ return actions ? action("increment") : AxDispatch{};
363
+ case AxVerb::Decrement:
364
+ return actions ? action("decrement") : AxDispatch{};
365
+ case AxVerb::Cancel:
366
+ if (props.onAccessibilityEscape) {
367
+ return {AxDispatch::Kind::Escape, ""};
368
+ }
369
+ return actions && declares(props, "escape") ? action("escape") : AxDispatch{};
370
+ }
371
+ return {};
372
+ }
373
+
374
+ } // namespace ngn