@ng-native/desktop 0.0.0-stage → 0.23.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 (393) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +51 -2
  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 +276 -0
  14. package/native/appkit/CMakeLists.txt +109 -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-view.h +15 -0
  41. package/native/appkit/camera-view.mm +130 -0
  42. package/native/appkit/camera.h +39 -0
  43. package/native/appkit/camera.mm +362 -0
  44. package/native/appkit/cg-canvas.h +17 -0
  45. package/native/appkit/cg-canvas.mm +518 -0
  46. package/native/appkit/component-view.h +17 -0
  47. package/native/appkit/crypto.h +19 -0
  48. package/native/appkit/crypto.mm +78 -0
  49. package/native/appkit/desktop-expo.h +29 -0
  50. package/native/appkit/desktop-expo.mm +385 -0
  51. package/native/appkit/expo-image-drawing.h +46 -0
  52. package/native/appkit/expo-image-drawing.mm +131 -0
  53. package/native/appkit/expo-image-view.h +15 -0
  54. package/native/appkit/expo-image-view.mm +182 -0
  55. package/native/appkit/expo-ui-renderer.h +68 -0
  56. package/native/appkit/expo-ui-renderer.mm +101 -0
  57. package/native/appkit/expo-ui-view.h +26 -0
  58. package/native/appkit/expo-ui-view.mm +134 -0
  59. package/native/appkit/expo-ui.swift +1284 -0
  60. package/native/appkit/file-system.h +16 -0
  61. package/native/appkit/file-system.mm +140 -0
  62. package/native/appkit/fonts.h +12 -0
  63. package/native/appkit/fonts.mm +48 -0
  64. package/native/appkit/geocoder.h +19 -0
  65. package/native/appkit/geocoder.mm +101 -0
  66. package/native/appkit/glass-effect.h +22 -0
  67. package/native/appkit/glass-effect.mm +63 -0
  68. package/native/appkit/glass-view.h +8 -0
  69. package/native/appkit/glass-view.mm +65 -0
  70. package/native/appkit/header-toolbar.h +60 -0
  71. package/native/appkit/header-toolbar.mm +629 -0
  72. package/native/appkit/host-view.h +54 -0
  73. package/native/appkit/host-view.mm +1200 -0
  74. package/native/appkit/image-manipulator.h +14 -0
  75. package/native/appkit/image-manipulator.mm +191 -0
  76. package/native/appkit/image-request.h +22 -0
  77. package/native/appkit/image-request.mm +62 -0
  78. package/native/appkit/image-view.h +8 -0
  79. package/native/appkit/image-view.mm +142 -0
  80. package/native/appkit/input-replay.h +25 -0
  81. package/native/appkit/input-replay.mm +418 -0
  82. package/native/appkit/language-model.h +14 -0
  83. package/native/appkit/language-model.mm +99 -0
  84. package/native/appkit/language-model.swift +472 -0
  85. package/native/appkit/local-authentication.h +15 -0
  86. package/native/appkit/local-authentication.mm +133 -0
  87. package/native/appkit/location.h +16 -0
  88. package/native/appkit/location.mm +214 -0
  89. package/native/appkit/main.mm +1515 -0
  90. package/native/appkit/map-view.h +15 -0
  91. package/native/appkit/map-view.mm +109 -0
  92. package/native/appkit/maps.h +35 -0
  93. package/native/appkit/maps.mm +343 -0
  94. package/native/appkit/menu-bar.h +22 -0
  95. package/native/appkit/menu-bar.mm +208 -0
  96. package/native/appkit/modal-focus.h +16 -0
  97. package/native/appkit/modal-focus.mm +26 -0
  98. package/native/appkit/modal-host-view.h +79 -0
  99. package/native/appkit/modal-host-view.mm +442 -0
  100. package/native/appkit/native-controls.h +22 -0
  101. package/native/appkit/native-controls.mm +431 -0
  102. package/native/appkit/network-state.h +12 -0
  103. package/native/appkit/network-state.mm +64 -0
  104. package/native/appkit/network.h +14 -0
  105. package/native/appkit/network.mm +396 -0
  106. package/native/appkit/notifications.h +19 -0
  107. package/native/appkit/notifications.mm +309 -0
  108. package/native/appkit/photo-library.h +33 -0
  109. package/native/appkit/photo-library.mm +548 -0
  110. package/native/appkit/pointer-buttons.h +32 -0
  111. package/native/appkit/presentation-label.h +15 -0
  112. package/native/appkit/presentation-label.mm +12 -0
  113. package/native/appkit/presented-screen.h +19 -0
  114. package/native/appkit/presented-screen.mm +181 -0
  115. package/native/appkit/printing.h +42 -0
  116. package/native/appkit/printing.mm +393 -0
  117. package/native/appkit/push.h +19 -0
  118. package/native/appkit/push.mm +81 -0
  119. package/native/appkit/red-box.h +26 -0
  120. package/native/appkit/red-box.mm +387 -0
  121. package/native/appkit/screen-capture.h +21 -0
  122. package/native/appkit/screen-capture.mm +92 -0
  123. package/native/appkit/scroll-view.h +13 -0
  124. package/native/appkit/scroll-view.mm +251 -0
  125. package/native/appkit/scrollers.h +25 -0
  126. package/native/appkit/scrollers.mm +43 -0
  127. package/native/appkit/search-field.h +34 -0
  128. package/native/appkit/search-field.mm +291 -0
  129. package/native/appkit/search-toolbar-item.h +19 -0
  130. package/native/appkit/search-toolbar-item.mm +269 -0
  131. package/native/appkit/share-picker.h +34 -0
  132. package/native/appkit/share-picker.mm +121 -0
  133. package/native/appkit/split-view.h +77 -0
  134. package/native/appkit/split-view.mm +1206 -0
  135. package/native/appkit/store-review.h +13 -0
  136. package/native/appkit/store-review.mm +28 -0
  137. package/native/appkit/surface-view.h +45 -0
  138. package/native/appkit/surface-view.mm +558 -0
  139. package/native/appkit/svg-view.h +17 -0
  140. package/native/appkit/svg-view.mm +57 -0
  141. package/native/appkit/symbol-drawing.h +24 -0
  142. package/native/appkit/symbol-drawing.mm +117 -0
  143. package/native/appkit/symbol-view.h +8 -0
  144. package/native/appkit/symbol-view.mm +33 -0
  145. package/native/appkit/system-access.h +34 -0
  146. package/native/appkit/system-access.mm +210 -0
  147. package/native/appkit/system.h +24 -0
  148. package/native/appkit/system.mm +403 -0
  149. package/native/appkit/test-launch.h +36 -0
  150. package/native/appkit/test-launch.mm +115 -0
  151. package/native/appkit/text-input-field.h +76 -0
  152. package/native/appkit/text-input-field.mm +444 -0
  153. package/native/appkit/text-layout.h +58 -0
  154. package/native/appkit/text-layout.mm +477 -0
  155. package/native/appkit/text-recognition.h +13 -0
  156. package/native/appkit/text-recognition.mm +102 -0
  157. package/native/appkit/tracking.h +13 -0
  158. package/native/appkit/tracking.mm +51 -0
  159. package/native/appkit/tray-and-dock.h +45 -0
  160. package/native/appkit/tray-and-dock.mm +130 -0
  161. package/native/appkit/undo.h +23 -0
  162. package/native/appkit/undo.mm +125 -0
  163. package/native/appkit/updates.h +17 -0
  164. package/native/appkit/updates.mm +71 -0
  165. package/native/appkit/video-view.h +10 -0
  166. package/native/appkit/video-view.mm +42 -0
  167. package/native/appkit/video.h +38 -0
  168. package/native/appkit/video.mm +404 -0
  169. package/native/appkit/web-browser.h +12 -0
  170. package/native/appkit/web-browser.mm +97 -0
  171. package/native/appkit/web-view-component.h +9 -0
  172. package/native/appkit/web-view-component.mm +56 -0
  173. package/native/appkit/web-view.h +31 -0
  174. package/native/appkit/web-view.mm +394 -0
  175. package/native/cmake/libraries/react-native-reanimated.cmake +45 -0
  176. package/native/cmake/libraries/react-native-worklets.cmake +46 -0
  177. package/native/cmake/libraries.cmake +109 -0
  178. package/native/cmake/linked-modules.cmake +112 -0
  179. package/native/cmake/react-native.cmake +175 -0
  180. package/native/cmake/runtime-dependencies.cmake +34 -0
  181. package/native/cmake/swift.cmake +43 -0
  182. package/native/cmake/third-party.cmake +74 -0
  183. package/native/core/include/ngn/absent-views.h +27 -0
  184. package/native/core/include/ngn/accessibility.h +140 -0
  185. package/native/core/include/ngn/address-search.h +69 -0
  186. package/native/core/include/ngn/animation-frames.h +39 -0
  187. package/native/core/include/ngn/app-info.h +52 -0
  188. package/native/core/include/ngn/app-menus.h +146 -0
  189. package/native/core/include/ngn/app-windows.h +181 -0
  190. package/native/core/include/ngn/apple-authentication.h +116 -0
  191. package/native/core/include/ngn/asset.h +28 -0
  192. package/native/core/include/ngn/audio.h +125 -0
  193. package/native/core/include/ngn/back-swipe.h +112 -0
  194. package/native/core/include/ngn/battery.h +48 -0
  195. package/native/core/include/ngn/bytes.h +59 -0
  196. package/native/core/include/ngn/calendar.h +180 -0
  197. package/native/core/include/ngn/camera.h +128 -0
  198. package/native/core/include/ngn/control-sizes.h +111 -0
  199. package/native/core/include/ngn/core-modules.h +105 -0
  200. package/native/core/include/ngn/crypto.h +38 -0
  201. package/native/core/include/ngn/default-menu.h +91 -0
  202. package/native/core/include/ngn/desktop-expo.h +193 -0
  203. package/native/core/include/ngn/desktop-modal.h +109 -0
  204. package/native/core/include/ngn/desktop-props.h +75 -0
  205. package/native/core/include/ngn/desktop-view-props.h +110 -0
  206. package/native/core/include/ngn/dev-server.h +33 -0
  207. package/native/core/include/ngn/download.h +24 -0
  208. package/native/core/include/ngn/expo-image.h +192 -0
  209. package/native/core/include/ngn/expo-ui.h +133 -0
  210. package/native/core/include/ngn/file-system.h +274 -0
  211. package/native/core/include/ngn/focus-order.h +63 -0
  212. package/native/core/include/ngn/fonts.h +64 -0
  213. package/native/core/include/ngn/gestures.h +305 -0
  214. package/native/core/include/ngn/glass.h +67 -0
  215. package/native/core/include/ngn/header-bar.h +112 -0
  216. package/native/core/include/ngn/host-state.h +243 -0
  217. package/native/core/include/ngn/image-manipulator.h +70 -0
  218. package/native/core/include/ngn/input-dispatcher.h +211 -0
  219. package/native/core/include/ngn/input-script.h +56 -0
  220. package/native/core/include/ngn/input.h +112 -0
  221. package/native/core/include/ngn/key-value-store.h +41 -0
  222. package/native/core/include/ngn/language-model.h +69 -0
  223. package/native/core/include/ngn/launch-frame.h +47 -0
  224. package/native/core/include/ngn/launch-settings.h +98 -0
  225. package/native/core/include/ngn/layout-animations.h +24 -0
  226. package/native/core/include/ngn/library-components.h +13 -0
  227. package/native/core/include/ngn/library-glue.h +53 -0
  228. package/native/core/include/ngn/live-regions.h +54 -0
  229. package/native/core/include/ngn/local-authentication.h +74 -0
  230. package/native/core/include/ngn/location.h +89 -0
  231. package/native/core/include/ngn/maps.h +226 -0
  232. package/native/core/include/ngn/module-registry.h +51 -0
  233. package/native/core/include/ngn/mounting-backend.h +96 -0
  234. package/native/core/include/ngn/mounting-manager.h +155 -0
  235. package/native/core/include/ngn/native-controls.h +161 -0
  236. package/native/core/include/ngn/native-module.h +109 -0
  237. package/native/core/include/ngn/network-state.h +44 -0
  238. package/native/core/include/ngn/network.h +100 -0
  239. package/native/core/include/ngn/notifications.h +185 -0
  240. package/native/core/include/ngn/photo-library.h +130 -0
  241. package/native/core/include/ngn/printing.h +69 -0
  242. package/native/core/include/ngn/processes.h +114 -0
  243. package/native/core/include/ngn/red-box.h +119 -0
  244. package/native/core/include/ngn/reload-thread.h +258 -0
  245. package/native/core/include/ngn/runtime.h +161 -0
  246. package/native/core/include/ngn/safe-areas.h +77 -0
  247. package/native/core/include/ngn/screen-capture.h +35 -0
  248. package/native/core/include/ngn/screen-presentation.h +85 -0
  249. package/native/core/include/ngn/screen-stacks.h +80 -0
  250. package/native/core/include/ngn/scrollers.h +106 -0
  251. package/native/core/include/ngn/sharing.h +39 -0
  252. package/native/core/include/ngn/spawn-rules.h +78 -0
  253. package/native/core/include/ngn/splash-screen.h +41 -0
  254. package/native/core/include/ngn/split-view.h +270 -0
  255. package/native/core/include/ngn/sqlite.h +38 -0
  256. package/native/core/include/ngn/store-review.h +26 -0
  257. package/native/core/include/ngn/surface-book.h +101 -0
  258. package/native/core/include/ngn/svg.h +393 -0
  259. package/native/core/include/ngn/symbol.h +90 -0
  260. package/native/core/include/ngn/system.h +102 -0
  261. package/native/core/include/ngn/tabs-host.h +171 -0
  262. package/native/core/include/ngn/text-input.h +125 -0
  263. package/native/core/include/ngn/text-measurer.h +38 -0
  264. package/native/core/include/ngn/text-recognition.h +55 -0
  265. package/native/core/include/ngn/tracking.h +34 -0
  266. package/native/core/include/ngn/tray-and-dock.h +107 -0
  267. package/native/core/include/ngn/undo.h +37 -0
  268. package/native/core/include/ngn/updates.h +253 -0
  269. package/native/core/include/ngn/video.h +126 -0
  270. package/native/core/include/ngn/view-box.h +126 -0
  271. package/native/core/include/ngn/view-transform.h +26 -0
  272. package/native/core/include/ngn/view-tree.h +85 -0
  273. package/native/core/include/ngn/web-browser.h +45 -0
  274. package/native/core/include/ngn/web-view.h +133 -0
  275. package/native/core/include/ngn/worklet-host.h +98 -0
  276. package/native/core/src/absent-views.cpp +41 -0
  277. package/native/core/src/accessibility.cpp +374 -0
  278. package/native/core/src/animation-frames.cpp +49 -0
  279. package/native/core/src/app-menus.cpp +352 -0
  280. package/native/core/src/app-windows.cpp +444 -0
  281. package/native/core/src/back-swipe.cpp +91 -0
  282. package/native/core/src/bytes.cpp +158 -0
  283. package/native/core/src/control-sizes.cpp +232 -0
  284. package/native/core/src/default-menu.cpp +96 -0
  285. package/native/core/src/desktop-modal.cpp +162 -0
  286. package/native/core/src/desktop-view-props.cpp +80 -0
  287. package/native/core/src/dev-server-helper.cpp +152 -0
  288. package/native/core/src/dev-server.cpp +103 -0
  289. package/native/core/src/download.cpp +53 -0
  290. package/native/core/src/expo-image.cpp +548 -0
  291. package/native/core/src/expo-ui.cpp +203 -0
  292. package/native/core/src/focus-order.cpp +441 -0
  293. package/native/core/src/gestures.cpp +1806 -0
  294. package/native/core/src/glass.cpp +49 -0
  295. package/native/core/src/header-bar.cpp +104 -0
  296. package/native/core/src/host-services.cpp +50 -0
  297. package/native/core/src/host-state.cpp +61 -0
  298. package/native/core/src/input-dispatcher.cpp +727 -0
  299. package/native/core/src/input-script.cpp +123 -0
  300. package/native/core/src/key-value-store.cpp +169 -0
  301. package/native/core/src/launch-settings.cpp +148 -0
  302. package/native/core/src/layout-animations.cpp +62 -0
  303. package/native/core/src/libraries/RNCWebViewSpec.cpp +80 -0
  304. package/native/core/src/libraries/react-native-reanimated.cpp +216 -0
  305. package/native/core/src/libraries/react-native-worklets.cpp +192 -0
  306. package/native/core/src/libraries/rnscreens.cpp +125 -0
  307. package/native/core/src/libraries/rnsvg.cpp +345 -0
  308. package/native/core/src/libraries/safeareacontext.cpp +70 -0
  309. package/native/core/src/libraries/worklets-idle-frames.js +70 -0
  310. package/native/core/src/library-glue.cpp +35 -0
  311. package/native/core/src/live-regions.cpp +122 -0
  312. package/native/core/src/module-registry.cpp +50 -0
  313. package/native/core/src/modules/accessibility-manager.cpp +98 -0
  314. package/native/core/src/modules/address-search.cpp +219 -0
  315. package/native/core/src/modules/alert-manager.cpp +140 -0
  316. package/native/core/src/modules/app-info.cpp +74 -0
  317. package/native/core/src/modules/app-modules.cpp +405 -0
  318. package/native/core/src/modules/apple-authentication.cpp +188 -0
  319. package/native/core/src/modules/asset.cpp +111 -0
  320. package/native/core/src/modules/async-storage.cpp +192 -0
  321. package/native/core/src/modules/audio.cpp +541 -0
  322. package/native/core/src/modules/battery.cpp +88 -0
  323. package/native/core/src/modules/calendar.cpp +457 -0
  324. package/native/core/src/modules/camera.cpp +221 -0
  325. package/native/core/src/modules/core-modules.cpp +62 -0
  326. package/native/core/src/modules/crypto.cpp +117 -0
  327. package/native/core/src/modules/desktop-expo.cpp +527 -0
  328. package/native/core/src/modules/file-system.cpp +941 -0
  329. package/native/core/src/modules/fonts.cpp +163 -0
  330. package/native/core/src/modules/image-loader.cpp +105 -0
  331. package/native/core/src/modules/image-manipulator.cpp +305 -0
  332. package/native/core/src/modules/language-model.cpp +195 -0
  333. package/native/core/src/modules/local-authentication.cpp +140 -0
  334. package/native/core/src/modules/location.cpp +186 -0
  335. package/native/core/src/modules/maps.cpp +500 -0
  336. package/native/core/src/modules/network-state.cpp +72 -0
  337. package/native/core/src/modules/networking.cpp +387 -0
  338. package/native/core/src/modules/notifications.cpp +549 -0
  339. package/native/core/src/modules/photo-library.cpp +371 -0
  340. package/native/core/src/modules/printing.cpp +201 -0
  341. package/native/core/src/modules/screen-capture.cpp +71 -0
  342. package/native/core/src/modules/sharing.cpp +59 -0
  343. package/native/core/src/modules/splash-screen.cpp +70 -0
  344. package/native/core/src/modules/sqlite.cpp +421 -0
  345. package/native/core/src/modules/store-review.cpp +23 -0
  346. package/native/core/src/modules/text-recognition.cpp +107 -0
  347. package/native/core/src/modules/tracking.cpp +46 -0
  348. package/native/core/src/modules/undo.cpp +59 -0
  349. package/native/core/src/modules/video.cpp +366 -0
  350. package/native/core/src/modules/web-browser.cpp +100 -0
  351. package/native/core/src/modules/web-socket.cpp +266 -0
  352. package/native/core/src/mounting-manager.cpp +380 -0
  353. package/native/core/src/native-controls.cpp +129 -0
  354. package/native/core/src/native-module.cpp +250 -0
  355. package/native/core/src/network.cpp +219 -0
  356. package/native/core/src/posix-launcher.cpp +366 -0
  357. package/native/core/src/processes.cpp +324 -0
  358. package/native/core/src/red-box-errors.js +83 -0
  359. package/native/core/src/red-box.cpp +306 -0
  360. package/native/core/src/runtime.cpp +422 -0
  361. package/native/core/src/safe-areas.cpp +130 -0
  362. package/native/core/src/screen-presentation.cpp +61 -0
  363. package/native/core/src/screen-stacks.cpp +254 -0
  364. package/native/core/src/scrollers.cpp +181 -0
  365. package/native/core/src/spawn-rules.cpp +292 -0
  366. package/native/core/src/split-view.cpp +343 -0
  367. package/native/core/src/svg.cpp +1883 -0
  368. package/native/core/src/symbol.cpp +94 -0
  369. package/native/core/src/tabs-host.cpp +234 -0
  370. package/native/core/src/text-input.cpp +126 -0
  371. package/native/core/src/text-layout-manager.cpp +63 -0
  372. package/native/core/src/tray-and-dock.cpp +154 -0
  373. package/native/core/src/updates.cpp +965 -0
  374. package/native/core/src/view-box.cpp +788 -0
  375. package/native/core/src/view-transform.cpp +45 -0
  376. package/native/core/src/view-tree.cpp +234 -0
  377. package/native/core/src/web-view.cpp +143 -0
  378. package/native/core/src/worklet-host.cpp +10 -0
  379. package/native/scripts/build-hermes.sh +44 -0
  380. package/native/scripts/build.sh +171 -0
  381. package/native/scripts/cache-dir.sh +18 -0
  382. package/native/scripts/codegen-library.sh +193 -0
  383. package/native/scripts/compiler-launcher.sh +17 -0
  384. package/native/scripts/fetch.sh +174 -0
  385. package/native/scripts/hermes-built.sh +10 -0
  386. package/native/scripts/host-dir.sh +16 -0
  387. package/native/scripts/macos-target.sh +8 -0
  388. package/native/scripts/make-prebuilt.mjs +360 -0
  389. package/native/scripts/prebuilt-host-cache.mjs +158 -0
  390. package/native/shim/openssl/sha.h +22 -0
  391. package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +37 -0
  392. package/package.json +70 -3
  393. package/prebuilt.json +33 -0
@@ -0,0 +1,182 @@
1
+ #import "expo-image-view.h"
2
+
3
+ #include "expo-image-drawing.h"
4
+
5
+ #import <QuartzCore/QuartzCore.h>
6
+
7
+ namespace {
8
+
9
+ std::shared_ptr<ngn::Http> gHttp;
10
+ std::shared_ptr<ngn::ImageCache> gCache;
11
+
12
+ struct Shown {
13
+ CGImageRef image{nullptr};
14
+ ~Shown() {
15
+ CGImageRelease(image);
16
+ }
17
+ void set(CGImageRef next) {
18
+ CGImageRelease(image);
19
+ image = next;
20
+ }
21
+ };
22
+
23
+ } // namespace
24
+
25
+ @implementation NGNExpoImageView {
26
+ Shown _image;
27
+ Shown _placeholder;
28
+ // The source shown or loading, and which load is current: a later one supersedes it.
29
+ ngn::ImageLoads _loads;
30
+ std::optional<ngn::ImageSourceRef> _placeholderSource;
31
+ std::string _recyclingKey;
32
+ }
33
+
34
+ + (void)useHttp:(std::shared_ptr<ngn::Http>)http cache:(std::shared_ptr<ngn::ImageCache>)cache {
35
+ gHttp = std::move(http);
36
+ gCache = std::move(cache);
37
+ }
38
+
39
+ - (std::shared_ptr<const ngn::ExpoImageProps>)imageProps {
40
+ return std::dynamic_pointer_cast<const ngn::ExpoImageProps>(self.props);
41
+ }
42
+
43
+ - (void)updateProps:(const facebook::react::Props::Shared &)props {
44
+ [super updateProps:props];
45
+ [self reload];
46
+ [self setNeedsDisplay:YES];
47
+ }
48
+
49
+ - (void)updateLayout:(const facebook::react::LayoutMetrics &)metrics {
50
+ [super updateLayout:metrics];
51
+ [self reload];
52
+ [self setNeedsDisplay:YES];
53
+ }
54
+
55
+ - (void)send:(const std::string &)name payload:(folly::dynamic)payload {
56
+ if (auto emitter = self.eventEmitter) {
57
+ emitter->dispatchEvent(name, std::move(payload), facebook::react::RawEvent::Category::Discrete);
58
+ }
59
+ }
60
+
61
+ // Loads the source that fits the view now, and the placeholder, when either changed.
62
+ - (void)reload {
63
+ auto props = [self imageProps];
64
+ if (!props || self.bounds.size.width <= 0 || self.bounds.size.height <= 0) {
65
+ return;
66
+ }
67
+ if (ngn::recyclingKeyClears(_recyclingKey, props->recyclingKey)) {
68
+ _image.set(nullptr);
69
+ [self setNeedsDisplay:YES];
70
+ // The image is gone: the same source loads again below, and a load still running for the last
71
+ // item shows nothing, even when this item has no source to load.
72
+ _loads.recycle();
73
+ }
74
+ _recyclingKey = props->recyclingKey;
75
+ double scale = self.window ? self.window.backingScaleFactor : NSScreen.mainScreen.backingScaleFactor;
76
+ auto placeholder = ngn::bestImageSource(ngn::imageSources(props->placeholder), self.bounds.size.width, self.bounds.size.height, scale);
77
+ if (placeholder != _placeholderSource) {
78
+ _placeholderSource = placeholder;
79
+ [self loadPlaceholder:placeholder cachePolicy:props->cachePolicy];
80
+ }
81
+ auto source = ngn::bestImageSource(ngn::imageSources(props->source), self.bounds.size.width, self.bounds.size.height, scale);
82
+ auto turn = _loads.fit(source);
83
+ if (!turn) {
84
+ return;
85
+ }
86
+ uint64_t generation = *turn;
87
+ if (!source) {
88
+ _image.set(nullptr);
89
+ [self setNeedsDisplay:YES];
90
+ return;
91
+ }
92
+ [self send:"loadStart" payload:folly::dynamic::object()];
93
+ __weak NGNExpoImageView *weakSelf = self;
94
+ auto policy = props->cachePolicy;
95
+ auto url = source->uri;
96
+ ngn::loadImageBytes(gHttp, gCache, ngn::viewFileAccess().get(), *source, policy, [weakSelf, generation, url](std::string bytes, ngn::ImageCache::Hit hit, const std::string &error) {
97
+ auto decoded = error.empty() ? ngn::appkit::decodeImage(bytes) : std::nullopt;
98
+ auto shared = std::make_shared<std::optional<ngn::appkit::DecodedImage>>(std::move(decoded));
99
+ std::string why = !error.empty() ? error : (*shared ? "" : url + " is not an image");
100
+ dispatch_async(dispatch_get_main_queue(), ^{
101
+ [weakSelf show:shared generation:generation hit:hit url:url error:why];
102
+ });
103
+ });
104
+ }
105
+
106
+ - (void)loadPlaceholder:(const std::optional<ngn::ImageSourceRef> &)source cachePolicy:(const std::string &)policy {
107
+ _placeholder.set(nullptr);
108
+ if (!source) {
109
+ return;
110
+ }
111
+ if (auto pixels = ngn::decodeHashUri(source->uri, source->width, source->height)) {
112
+ _placeholder.set(ngn::appkit::imageOfPixels(*pixels));
113
+ [self setNeedsDisplay:YES];
114
+ return;
115
+ }
116
+ __weak NGNExpoImageView *weakSelf = self;
117
+ auto wanted = *source;
118
+ ngn::loadImageBytes(gHttp, gCache, ngn::viewFileAccess().get(), wanted, policy, [weakSelf, wanted](std::string bytes, ngn::ImageCache::Hit, const std::string &error) {
119
+ if (!error.empty()) {
120
+ return;
121
+ }
122
+ auto decoded = std::make_shared<std::optional<ngn::appkit::DecodedImage>>(ngn::appkit::decodeImage(bytes));
123
+ dispatch_async(dispatch_get_main_queue(), ^{
124
+ NGNExpoImageView *view = weakSelf;
125
+ if (view == nil || view->_placeholderSource != wanted || !*decoded) {
126
+ return;
127
+ }
128
+ view->_placeholder.set(CGImageRetain((*decoded)->image));
129
+ [view setNeedsDisplay:YES];
130
+ });
131
+ });
132
+ }
133
+
134
+ - (void)show:(std::shared_ptr<std::optional<ngn::appkit::DecodedImage>>)decoded
135
+ generation:(uint64_t)generation
136
+ hit:(ngn::ImageCache::Hit)hit
137
+ url:(const std::string &)url
138
+ error:(const std::string &)error {
139
+ if (!_loads.current(generation)) {
140
+ return;
141
+ }
142
+ if (!error.empty()) {
143
+ [self send:"error" payload:folly::dynamic::object("error", error)];
144
+ return;
145
+ }
146
+ auto &image = **decoded;
147
+ auto props = [self imageProps];
148
+ auto transition = props ? ngn::imageTransition(props->transition) : ngn::ImageTransition{};
149
+ if (transition.duration > 0 && transition.effect != "none" && self.layer != nil) {
150
+ // Every effect is a cross-dissolve here; AppKit's layers have no flips or curls.
151
+ CATransition *fade = [CATransition animation];
152
+ fade.type = kCATransitionFade;
153
+ fade.duration = transition.duration / 1000.0;
154
+ NSString *timing = transition.timing == "linear" ? kCAMediaTimingFunctionLinear
155
+ : transition.timing == "ease-in" ? kCAMediaTimingFunctionEaseIn
156
+ : transition.timing == "ease-out" ? kCAMediaTimingFunctionEaseOut
157
+ : kCAMediaTimingFunctionEaseInEaseOut;
158
+ fade.timingFunction = [CAMediaTimingFunction functionWithName:timing];
159
+ [self.layer addAnimation:fade forKey:@"expoImageTransition"];
160
+ }
161
+ _image.set(CGImageRetain(image.image));
162
+ [self setNeedsDisplay:YES];
163
+ auto source = folly::dynamic::object("url", url)("width", static_cast<double>(CGImageGetWidth(image.image)))(
164
+ "height", static_cast<double>(CGImageGetHeight(image.image)))("mediaType", image.mediaType)("isAnimated", image.animated);
165
+ [self send:"load" payload:folly::dynamic::object("cacheType", ngn::cacheTypeName(hit))("source", std::move(source))];
166
+ [self send:"display" payload:folly::dynamic::object()];
167
+ }
168
+
169
+ - (void)drawRect:(NSRect)dirtyRect {
170
+ auto props = [self imageProps];
171
+ if (!props) {
172
+ return;
173
+ }
174
+ CGContextRef context = NSGraphicsContext.currentContext.CGContext;
175
+ if (_image.image != nullptr) {
176
+ ngn::appkit::drawImage(context, _image.image, props->contentFit, props->contentPosition, self.bounds.size, props->tintColor, props->blurRadius);
177
+ } else if (_placeholder.image != nullptr) {
178
+ ngn::appkit::drawImage(context, _placeholder.image, props->placeholderContentFit, props->contentPosition, self.bounds.size, {}, 0);
179
+ }
180
+ }
181
+
182
+ @end
@@ -0,0 +1,68 @@
1
+ // `@expo/ui` drawn in SwiftUI (expo-ui.swift): a HostView's tree (the core's expo-ui.h) as the
2
+ // SwiftUI views it names, in one NSView, with the content's fitting size for Yoga and each view's
3
+ // events. No Fabric view here: the HostView's NGNView (expo-ui-view.mm) holds a renderer and sends
4
+ // its events through the views' event emitters.
5
+ #pragma once
6
+
7
+ #include "ngn/expo-ui.h"
8
+
9
+ #import <AppKit/AppKit.h>
10
+
11
+ #include <folly/dynamic.h>
12
+
13
+ #include <functional>
14
+ #include <memory>
15
+ #include <string>
16
+ #include <unordered_map>
17
+
18
+ namespace ngn::appkit {
19
+
20
+ class ExpoUIRenderer {
21
+ public:
22
+ // A view's event: its tag, expo/ui's iOS name for it without `on`, and the payload.
23
+ using Events = std::function<void(facebook::react::Tag, const std::string &, folly::dynamic)>;
24
+ // An RNHostView's NSView, by its tag: the app's own views, which the SwiftUI content holds.
25
+ using Views = std::function<NSView *(facebook::react::Tag)>;
26
+
27
+ ExpoUIRenderer(Events events, Views views);
28
+ ~ExpoUIRenderer();
29
+ ExpoUIRenderer(const ExpoUIRenderer &) = delete;
30
+ ExpoUIRenderer &operator=(const ExpoUIRenderer &) = delete;
31
+
32
+ // The SwiftUI content's view, which fills the HostView.
33
+ NSView *view() const;
34
+
35
+ void setTree(std::shared_ptr<const ExpoUINode> root);
36
+ const std::shared_ptr<const ExpoUINode> &tree() const {
37
+ return root_;
38
+ }
39
+
40
+ // The content's size: its own with no width or height given (negative), or the size it takes at
41
+ // the width or height given.
42
+ facebook::react::Size fit(double width, double height) const;
43
+
44
+ // Acts on the view `tag` as the user would (expo-ui.swift's ngn_ui_host_perform). False for a tag
45
+ // or an action the view does not take.
46
+ bool perform(facebook::react::Tag tag, const folly::dynamic &action);
47
+
48
+ // Whether the renderer draws the iOS view `name`.
49
+ static bool draws(const std::string &name);
50
+
51
+ // `node` as the JSON the Swift half reads.
52
+ static folly::dynamic json(const ExpoUINode &node);
53
+
54
+ // Called by the Swift half.
55
+ void deliver(facebook::react::Tag tag, const std::string &name, const std::string &payload);
56
+ NSView *viewFor(facebook::react::Tag tag) const;
57
+
58
+ private:
59
+ Events events_;
60
+ Views views_;
61
+ void *host_;
62
+ std::shared_ptr<const ExpoUINode> root_;
63
+ };
64
+
65
+ // The event emitter of each view in `root`'s tree, by tag.
66
+ std::unordered_map<facebook::react::Tag, facebook::react::SharedEventEmitter> expoUIEmitters(const ExpoUINode &root);
67
+
68
+ } // namespace ngn::appkit
@@ -0,0 +1,101 @@
1
+ #include "expo-ui-renderer.h"
2
+
3
+ #include <folly/json.h>
4
+
5
+ // expo-ui.swift's C interface.
6
+ extern "C" {
7
+ typedef void (*NGNUIEvent)(void *, int32_t, const char *, const char *);
8
+ typedef void *(*NGNUIViewForTag)(void *, int32_t);
9
+ void *ngn_ui_host_make(void *context, NGNUIEvent onEvent, NGNUIViewForTag viewForTag);
10
+ void ngn_ui_host_detach(void *host);
11
+ void ngn_ui_host_set_tree(void *host, const char *tree);
12
+ void ngn_ui_host_fit(void *host, double width, double height, double *outWidth, double *outHeight);
13
+ bool ngn_ui_host_perform(void *host, int32_t tag, const char *action);
14
+ bool ngn_ui_draws(const char *name);
15
+ }
16
+
17
+ namespace ngn::appkit {
18
+
19
+ namespace {
20
+
21
+ void onEvent(void *context, int32_t tag, const char *name, const char *payload) {
22
+ static_cast<ExpoUIRenderer *>(context)->deliver(tag, name, payload);
23
+ }
24
+
25
+ void *onViewForTag(void *context, int32_t tag) {
26
+ return (__bridge void *)static_cast<ExpoUIRenderer *>(context)->viewFor(tag);
27
+ }
28
+
29
+ } // namespace
30
+
31
+ ExpoUIRenderer::ExpoUIRenderer(Events events, Views views)
32
+ : events_(std::move(events)), views_(std::move(views)), host_(ngn_ui_host_make(this, &onEvent, &onViewForTag)) {}
33
+
34
+ ExpoUIRenderer::~ExpoUIRenderer() {
35
+ // The view can outlive the renderer in its superview for a moment: it calls back no more.
36
+ ngn_ui_host_detach(host_);
37
+ CFRelease(host_);
38
+ }
39
+
40
+ NSView *ExpoUIRenderer::view() const {
41
+ return (__bridge NSView *)host_;
42
+ }
43
+
44
+ folly::dynamic ExpoUIRenderer::json(const ExpoUINode &node) {
45
+ auto children = folly::dynamic::array();
46
+ for (const auto &child : node.children) {
47
+ children.push_back(json(child));
48
+ }
49
+ return folly::dynamic::object("tag", node.tag)("name", node.name)("props", node.props)("children", std::move(children));
50
+ }
51
+
52
+ void ExpoUIRenderer::setTree(std::shared_ptr<const ExpoUINode> root) {
53
+ root_ = std::move(root);
54
+ ngn_ui_host_set_tree(host_, root_ ? folly::toJson(json(*root_)).c_str() : "null");
55
+ }
56
+
57
+ facebook::react::Size ExpoUIRenderer::fit(double width, double height) const {
58
+ double w = 0, h = 0;
59
+ ngn_ui_host_fit(host_, width, height, &w, &h);
60
+ return {static_cast<facebook::react::Float>(w), static_cast<facebook::react::Float>(h)};
61
+ }
62
+
63
+ bool ExpoUIRenderer::perform(facebook::react::Tag tag, const folly::dynamic &action) {
64
+ return ngn_ui_host_perform(host_, tag, folly::toJson(action).c_str());
65
+ }
66
+
67
+ bool ExpoUIRenderer::draws(const std::string &name) {
68
+ return ngn_ui_draws(name.c_str());
69
+ }
70
+
71
+ void ExpoUIRenderer::deliver(facebook::react::Tag tag, const std::string &name, const std::string &payload) {
72
+ if (!events_) {
73
+ return;
74
+ }
75
+ folly::dynamic parsed = folly::dynamic::object();
76
+ try {
77
+ parsed = folly::parseJson(payload);
78
+ } catch (const std::exception &) {
79
+ }
80
+ events_(tag, name, std::move(parsed));
81
+ }
82
+
83
+ NSView *ExpoUIRenderer::viewFor(facebook::react::Tag tag) const {
84
+ return views_ ? views_(tag) : nil;
85
+ }
86
+
87
+ std::unordered_map<facebook::react::Tag, facebook::react::SharedEventEmitter> expoUIEmitters(const ExpoUINode &root) {
88
+ std::unordered_map<facebook::react::Tag, facebook::react::SharedEventEmitter> out;
89
+ std::function<void(const ExpoUINode &)> walk = [&](const ExpoUINode &node) {
90
+ if (node.eventEmitter) {
91
+ out[node.tag] = node.eventEmitter;
92
+ }
93
+ for (const auto &child : node.children) {
94
+ walk(child);
95
+ }
96
+ };
97
+ walk(root);
98
+ return out;
99
+ }
100
+
101
+ } // namespace ngn::appkit
@@ -0,0 +1,26 @@
1
+ // `@expo/ui`'s views on macOS (the core's expo-ui.h). A HostView is an NGNView holding the SwiftUI
2
+ // content of its tree (expo-ui-renderer.h), which it sends each view's events from, and whose size
3
+ // it reports as its state when it matches its content. Every other expo/ui view is a hidden NGNView
4
+ // that mounts none of its children, since SwiftUI draws them, except an RNHostView: the app's own
5
+ // views, which the SwiftUI content holds where the RNHostView is.
6
+ #pragma once
7
+
8
+ #import "host-view.h"
9
+ #import "split-view.h"
10
+
11
+ #include "ngn/expo-ui.h"
12
+
13
+ #include <memory>
14
+
15
+ @interface NGNExpoUIView : NGNView <NGNMountsChildren>
16
+ @end
17
+
18
+ @interface NGNExpoUIHostView : NGNView <NGNMountsChildren>
19
+ - (void)setTree:(std::shared_ptr<const ngn::ExpoUINode>)tree;
20
+ @end
21
+
22
+ @interface NGNExpoUIEmbeddedView : NGNView
23
+ @end
24
+
25
+ // The view for an expo/ui component, or nil for another component.
26
+ NGNView *NGNMakeExpoUIView(const facebook::react::ShadowView &view);
@@ -0,0 +1,134 @@
1
+ #import "expo-ui-view.h"
2
+
3
+ #include "expo-ui-renderer.h"
4
+
5
+ #include <react/renderer/core/ConcreteState.h>
6
+
7
+ #include <cmath>
8
+ #include <unordered_map>
9
+
10
+ using namespace facebook::react;
11
+
12
+ namespace {
13
+
14
+ // The RNHostViews mounted, by tag, for the SwiftUI content that holds them.
15
+ NSMapTable<NSNumber *, NGNView *> *embeddedViews() {
16
+ static NSMapTable<NSNumber *, NGNView *> *views = [NSMapTable strongToWeakObjectsMapTable];
17
+ return views;
18
+ }
19
+
20
+ } // namespace
21
+
22
+ @implementation NGNExpoUIView
23
+
24
+ - (void)updateLayout:(const LayoutMetrics &)metrics {
25
+ [super updateLayout:metrics];
26
+ // SwiftUI draws it, in its HostView's content.
27
+ self.hidden = YES;
28
+ }
29
+
30
+ - (void)mountChild:(NGNView *)child index:(NSInteger)index {
31
+ }
32
+
33
+ - (void)unmountChild:(NGNView *)child {
34
+ }
35
+
36
+ @end
37
+
38
+ @implementation NGNExpoUIHostView {
39
+ std::unique_ptr<ngn::appkit::ExpoUIRenderer> _renderer;
40
+ std::unordered_map<Tag, SharedEventEmitter> _emitters;
41
+ facebook::react::Size _reported;
42
+ }
43
+
44
+ - (instancetype)initWithShadowView:(const ShadowView &)view {
45
+ if ((self = [super initWithShadowView:view])) {
46
+ __weak NGNExpoUIHostView *weakSelf = self;
47
+ _renderer = std::make_unique<ngn::appkit::ExpoUIRenderer>(
48
+ [weakSelf](Tag tag, const std::string &name, folly::dynamic payload) {
49
+ [weakSelf send:name payload:std::move(payload) to:tag];
50
+ },
51
+ [](Tag tag) -> NSView * { return [embeddedViews() objectForKey:@(tag)]; });
52
+ NSView *content = _renderer->view();
53
+ content.frame = self.bounds;
54
+ content.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
55
+ [self addSubview:content];
56
+ }
57
+ return self;
58
+ }
59
+
60
+ - (void)send:(const std::string &)name payload:(folly::dynamic)payload to:(Tag)tag {
61
+ auto found = _emitters.find(tag);
62
+ if (found != _emitters.end() && found->second) {
63
+ found->second->dispatchEvent(name, std::move(payload), RawEvent::Category::Discrete);
64
+ }
65
+ }
66
+
67
+ - (void)updateLayout:(const LayoutMetrics &)metrics {
68
+ [super updateLayout:metrics];
69
+ [self reportContentSize];
70
+ }
71
+
72
+ // Its children are SwiftUI's to draw.
73
+ - (void)mountChild:(NGNView *)child index:(NSInteger)index {
74
+ }
75
+
76
+ - (void)unmountChild:(NGNView *)child {
77
+ }
78
+
79
+ - (void)setTree:(std::shared_ptr<const ngn::ExpoUINode>)tree {
80
+ _emitters = tree ? ngn::appkit::expoUIEmitters(*tree) : decltype(_emitters){};
81
+ _renderer->setTree(std::move(tree));
82
+ [self reportContentSize];
83
+ }
84
+
85
+ // Tells layout the content's size on the axes the HostView matches, as expo/ui's setViewSize does.
86
+ - (void)reportContentSize {
87
+ auto props = std::dynamic_pointer_cast<const ngn::ExpoUIProps>(self.props);
88
+ auto state = std::dynamic_pointer_cast<const ConcreteState<ngn::ExpoUIState>>(self.state);
89
+ if (!props || !state || !_renderer->tree() || (!props->matchContentsHorizontal && !props->matchContentsVertical)) {
90
+ return;
91
+ }
92
+ const auto &frame = self.layoutMetrics.frame.size;
93
+ auto size = _renderer->fit(props->matchContentsHorizontal ? -1 : frame.width, props->matchContentsVertical ? -1 : frame.height);
94
+ size = {std::ceil(size.width), std::ceil(size.height)};
95
+ if (size == _reported || size == state->getData().contentSize) {
96
+ return;
97
+ }
98
+ _reported = size;
99
+ state->updateState(ngn::ExpoUIState{.contentSize = size});
100
+ }
101
+
102
+ @end
103
+
104
+ @implementation NGNExpoUIEmbeddedView
105
+
106
+ - (instancetype)initWithShadowView:(const ShadowView &)view {
107
+ if ((self = [super initWithShadowView:view])) {
108
+ [embeddedViews() setObject:self forKey:@(view.tag)];
109
+ }
110
+ return self;
111
+ }
112
+
113
+ - (void)updateLayout:(const LayoutMetrics &)metrics {
114
+ [super updateLayout:metrics];
115
+ // Where it is in the SwiftUI content is SwiftUI's to say; its size is Yoga's.
116
+ [self setFrameOrigin:NSZeroPoint];
117
+ [self.superview invalidateIntrinsicContentSize];
118
+ }
119
+
120
+ @end
121
+
122
+ NGNView *NGNMakeExpoUIView(const ShadowView &view) {
123
+ auto name = ngn::expoUIViewName(view.componentName);
124
+ if (!name) {
125
+ return nil;
126
+ }
127
+ if (*name == "HostView") {
128
+ return [[NGNExpoUIHostView alloc] initWithShadowView:view];
129
+ }
130
+ if (*name == "RNHostView") {
131
+ return [[NGNExpoUIEmbeddedView alloc] initWithShadowView:view];
132
+ }
133
+ return [[NGNExpoUIView alloc] initWithShadowView:view];
134
+ }