@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,1206 @@
1
+ #import "split-view.h"
2
+ #import "test-launch.h"
3
+
4
+ #import "surface-view.h"
5
+
6
+ #include <react/renderer/core/ConcreteState.h>
7
+
8
+ using namespace facebook::react;
9
+
10
+ namespace {
11
+
12
+ ngn::InputSink *gInput = nullptr;
13
+ std::function<void(NSInteger, BOOL)> gContainerRootChanged;
14
+ std::function<bool(NSInteger, NSPoint)> gRowContentTakesClick;
15
+
16
+ NSString *nsString(const std::string &s) {
17
+ NSString *result = [NSString stringWithUTF8String:s.c_str()];
18
+ return result != nil ? result : @"";
19
+ }
20
+
21
+ // The name NSSplitView autosaves under, in the standard defaults: in a test launch prefixed with
22
+ // the run's, so a run never restores another's divider and removes its own as it ends.
23
+ NSString *autosaveKey(const std::string &name) {
24
+ if (name.empty()) {
25
+ return nil;
26
+ }
27
+ auto &test = ngn::appkit::testLaunch();
28
+ return nsString(test ? test->keychainPrefix() + name : name);
29
+ }
30
+
31
+ void send(NGNView *view, const std::string &name, folly::dynamic payload) {
32
+ if (auto emitter = view.eventEmitter) {
33
+ emitter->dispatchEvent(name, std::move(payload), RawEvent::Category::Discrete);
34
+ }
35
+ }
36
+
37
+ // The narrowest and widest a sidebar is dragged to when the app sets no bound.
38
+ constexpr CGFloat kSidebarMinimum = 150;
39
+ constexpr CGFloat kSidebarMaximum = 400;
40
+
41
+ } // namespace
42
+
43
+ #pragma mark - Sizes back into layout
44
+
45
+ // A view whose size the toolkit decides and layout follows.
46
+ @protocol NGNSizedByToolkit
47
+ - (void)applyToolkitSize:(facebook::react::Size)size;
48
+ @end
49
+
50
+ namespace {
51
+
52
+ ngn::FrameSizes gSizes;
53
+ NSMapTable<NSNumber *, NGNView<NGNSizedByToolkit> *> *gSized = [NSMapTable strongToWeakObjectsMapTable];
54
+
55
+ void flushSizes() {
56
+ for (const auto &[tag, size] : gSizes.flush()) {
57
+ [[gSized objectForKey:@(tag)] applyToolkitSize:size];
58
+ }
59
+ }
60
+
61
+ // Layout hears the latest size of each view at most once a display frame, however many steps a
62
+ // divider drag takes.
63
+ void reportSize(NGNView<NGNSizedByToolkit> *view, NSSize size) {
64
+ if (view == nil) {
65
+ return;
66
+ }
67
+ [gSized setObject:view forKey:@(view.reactTag)];
68
+ if (gSizes.report(static_cast<Tag>(view.reactTag), {static_cast<Float>(size.width), static_cast<Float>(size.height)})) {
69
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC / 60), dispatch_get_main_queue(), ^{
70
+ flushSizes();
71
+ });
72
+ }
73
+ }
74
+
75
+ // Sets a pane's or a row's SplitPaneState, unless it already says that.
76
+ void updatePaneState(NGNView *view, facebook::react::Size size) {
77
+ auto concrete = std::dynamic_pointer_cast<const ConcreteState<ngn::SplitPaneState>>(view.state);
78
+ if (!concrete || concrete->getData().size == size) {
79
+ return;
80
+ }
81
+ concrete->updateState(ngn::SplitPaneState{.size = size});
82
+ }
83
+
84
+ } // namespace
85
+
86
+ #pragma mark - Panes
87
+
88
+ // A pane's container in its split item: part of the surface, hit-tested from the pane.
89
+ @interface NGNPaneContainer : NGNSurfaceView
90
+ @property (nonatomic, weak) NGNSplitPaneView *pane;
91
+ @end
92
+
93
+ @interface NGNSplitPaneView () <NGNSizedByToolkit>
94
+ @property (nonatomic, weak) NGNSplitView *split;
95
+ - (const ngn::SplitPaneProps *)paneProps;
96
+ @end
97
+
98
+ @interface NGNSplitView ()
99
+ - (void)paneChanged:(NGNSplitPaneView *)pane;
100
+ // What a subclass shows in place of the panes.
101
+ - (void)setSidebarView:(NSView *)sidebar contentView:(NSView *)content;
102
+ @end
103
+
104
+ @implementation NGNPaneContainer
105
+ - (void)setFrameSize:(NSSize)size {
106
+ [super setFrameSize:size];
107
+ if (size.width > 0 && size.height > 0) {
108
+ reportSize(self.pane, size);
109
+ }
110
+ }
111
+ @end
112
+
113
+ @implementation NGNSplitPaneView
114
+ - (void)updateProps:(const Props::Shared &)props {
115
+ [super updateProps:props];
116
+ [self.split paneChanged:self];
117
+ }
118
+ // Its container places it: Yoga's origin is in the split view, and its size is the container's.
119
+ - (void)updateLayout:(const LayoutMetrics &)metrics {
120
+ [super updateLayout:metrics];
121
+ if ([self.superview isKindOfClass:NGNPaneContainer.class]) {
122
+ self.frame = self.superview.bounds;
123
+ }
124
+ }
125
+ - (void)applyToolkitSize:(facebook::react::Size)size {
126
+ updatePaneState(self, size);
127
+ }
128
+ - (const ngn::SplitPaneProps *)paneProps {
129
+ return dynamic_cast<const ngn::SplitPaneProps *>(self.props.get());
130
+ }
131
+ @end
132
+
133
+ #pragma mark - Split view
134
+
135
+ NSWindow *NGNWindowOfSplit(NSView *surfaceView) {
136
+ if (surfaceView.window != nil) {
137
+ return surfaceView.window;
138
+ }
139
+ // A split view controller took the window's content: the surface's split view knows the window.
140
+ NSMutableArray<NSView *> *queue = [NSMutableArray arrayWithObject:surfaceView];
141
+ while (queue.count > 0) {
142
+ NSView *view = queue.firstObject;
143
+ [queue removeObjectAtIndex:0];
144
+ if ([view isKindOfClass:NGNSplitView.class] && ((NGNSplitView *)view).ownWindow != nil) {
145
+ return ((NGNSplitView *)view).ownWindow;
146
+ }
147
+ [queue addObjectsFromArray:view.subviews];
148
+ }
149
+ return nil;
150
+ }
151
+
152
+ @interface NGNSplitView () <NSSplitViewDelegate>
153
+ @end
154
+
155
+ @implementation NGNSplitView {
156
+ NGNSplitPaneView *_sidebar;
157
+ NGNSplitPaneView *_content;
158
+ // What the split view shows: the panes' containers, or a tabs host's list and content.
159
+ NSView *_sidebarContainer;
160
+ NSView *_contentContainer;
161
+ BOOL _decided;
162
+ BOOL _windows;
163
+ // The window's: the controller, its sidebar item, and the surface view it took the place of.
164
+ NSSplitViewController *_controller;
165
+ NSSplitViewItem *_sidebarItem;
166
+ NSView *_surfaceView;
167
+ // A plain one.
168
+ NSSplitView *_plain;
169
+ CGFloat _plainWidth;
170
+ ngn::SidebarCollapse _collapse;
171
+ std::string _autosave;
172
+ }
173
+
174
+ + (ngn::InputSink *)input {
175
+ return gInput;
176
+ }
177
+ + (void)setInput:(ngn::InputSink *)input {
178
+ gInput = input;
179
+ }
180
+ + (std::function<void(NSInteger, BOOL)>)containerRootChanged {
181
+ return gContainerRootChanged;
182
+ }
183
+ + (void)setContainerRootChanged:(std::function<void(NSInteger, BOOL)>)fn {
184
+ gContainerRootChanged = std::move(fn);
185
+ }
186
+ + (std::function<bool(NSInteger, NSPoint)>)rowContentTakesClick {
187
+ return gRowContentTakesClick;
188
+ }
189
+ + (void)setRowContentTakesClick:(std::function<bool(NSInteger, NSPoint)>)fn {
190
+ gRowContentTakesClick = std::move(fn);
191
+ }
192
+
193
+ - (NGNPaneContainer *)containerFor:(NGNSplitPaneView *)pane {
194
+ if (gInput == nullptr) {
195
+ return nil;
196
+ }
197
+ NGNPaneContainer *container = [[NGNPaneContainer alloc] initWithFrame:NSMakeRect(0, 0, 240, 400)
198
+ surfaceId:static_cast<SurfaceId>(pane.surfaceId)
199
+ container:static_cast<ngn::ContainerId>(pane.reactTag)
200
+ rootTag:static_cast<Tag>(pane.reactTag)
201
+ input:gInput];
202
+ container.wantsLayer = YES;
203
+ container.pane = pane;
204
+ pane.frame = container.bounds;
205
+ pane.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
206
+ [container addSubview:pane];
207
+ if (gContainerRootChanged) {
208
+ gContainerRootChanged(pane.reactTag, YES);
209
+ }
210
+ return container;
211
+ }
212
+
213
+ - (void)setSidebarView:(NSView *)sidebar contentView:(NSView *)content {
214
+ _sidebarContainer = sidebar;
215
+ _contentContainer = content;
216
+ }
217
+
218
+ - (void)mountChild:(NGNView *)child index:(NSInteger)index {
219
+ if (![child isKindOfClass:NGNSplitPaneView.class]) {
220
+ // Anything else in a split view has nowhere to show: the element puts only its panes here.
221
+ return;
222
+ }
223
+ auto *pane = (NGNSplitPaneView *)child;
224
+ pane.split = self;
225
+ BOOL sidebar = [pane.componentName isEqualToString:@"NgNativeSidebar"];
226
+ NSView *old = sidebar ? _sidebarContainer : _contentContainer;
227
+ NSView *container = [self containerFor:pane];
228
+ if (sidebar) {
229
+ _sidebar = pane;
230
+ _sidebarContainer = container;
231
+ } else {
232
+ _content = pane;
233
+ _contentContainer = container;
234
+ }
235
+ // A pane mounted in place of one the split already shows takes its place there.
236
+ if (old != nil && (_controller != nil || _plain != nil)) {
237
+ [self replaceContainer:old with:container sidebar:sidebar];
238
+ } else if (_decided) {
239
+ [self build];
240
+ }
241
+ }
242
+
243
+ - (void)replaceContainer:(NSView *)old with:(NSView *)container sidebar:(BOOL)sidebar {
244
+ if (_plain != nil) {
245
+ NSUInteger at = [_plain.arrangedSubviews indexOfObjectIdenticalTo:old];
246
+ // The width the user gave the pane stays: adjustSubviews keeps a sidebar's size as it is.
247
+ if (at != NSNotFound) {
248
+ container.frame = old.frame;
249
+ }
250
+ [old removeFromSuperview];
251
+ [_plain insertArrangedSubview:container atIndex:at == NSNotFound ? (sidebar ? 0 : _plain.arrangedSubviews.count) : at];
252
+ [_plain adjustSubviews];
253
+ [self paneChanged:_sidebar];
254
+ return;
255
+ }
256
+ if (sidebar) {
257
+ NSView *sideView = _sidebarItem.viewController.view;
258
+ [old removeFromSuperview];
259
+ container.translatesAutoresizingMaskIntoConstraints = NO;
260
+ [sideView addSubview:container];
261
+ [NSLayoutConstraint activateConstraints:@[
262
+ [container.topAnchor constraintEqualToAnchor:sideView.safeAreaLayoutGuide.topAnchor],
263
+ [container.bottomAnchor constraintEqualToAnchor:sideView.bottomAnchor],
264
+ [container.leadingAnchor constraintEqualToAnchor:sideView.leadingAnchor],
265
+ [container.trailingAnchor constraintEqualToAnchor:sideView.trailingAnchor],
266
+ ]];
267
+ [self paneChanged:_sidebar];
268
+ } else {
269
+ // A split view item keeps the view its controller had as it was added: the item is replaced.
270
+ NSViewController *main = [NSViewController new];
271
+ main.view = container;
272
+ [_controller removeSplitViewItem:_controller.splitViewItems.lastObject];
273
+ [_controller addSplitViewItem:[NSSplitViewItem splitViewItemWithViewController:main]];
274
+ }
275
+ }
276
+
277
+ - (void)unmountChild:(NGNView *)child {
278
+ if (child == _sidebar) {
279
+ _sidebar = nil;
280
+ } else if (child == _content) {
281
+ _content = nil;
282
+ }
283
+ [child removeFromSuperview];
284
+ if (gContainerRootChanged) {
285
+ gContainerRootChanged(child.reactTag, NO);
286
+ }
287
+ }
288
+
289
+ - (void)placeAsWindows:(BOOL)window {
290
+ _decided = YES;
291
+ _windows = window;
292
+ [self build];
293
+ }
294
+
295
+ - (void)viewDidMoveToWindow {
296
+ [super viewDidMoveToWindow];
297
+ if (_decided && _windows && _controller == nil && self.window != nil) {
298
+ [self build];
299
+ }
300
+ }
301
+
302
+ - (void)build {
303
+ if (_sidebarContainer == nil || _contentContainer == nil) {
304
+ return;
305
+ }
306
+ if (_windows) {
307
+ [self installInWindow];
308
+ } else {
309
+ [self buildPlain];
310
+ }
311
+ [self paneChanged:_sidebar];
312
+ }
313
+
314
+ - (CGFloat)minimumWidth {
315
+ const auto *p = [_sidebar paneProps];
316
+ return p && p->paneMinWidth > 0 ? p->paneMinWidth : kSidebarMinimum;
317
+ }
318
+
319
+ - (CGFloat)maximumWidth {
320
+ const auto *p = [_sidebar paneProps];
321
+ return std::max([self minimumWidth], p && p->paneMaxWidth > 0 ? (CGFloat)p->paneMaxWidth : kSidebarMaximum);
322
+ }
323
+
324
+ - (CGFloat)startingWidth {
325
+ return std::min(std::max<CGFloat>(ngn::kSidebarDefaultWidth, [self minimumWidth]), [self maximumWidth]);
326
+ }
327
+
328
+ // Whether the split view's autosave already holds its divider, which it then restores.
329
+ - (BOOL)hasAutosavedFrames {
330
+ return !_autosave.empty() &&
331
+ [NSUserDefaults.standardUserDefaults
332
+ objectForKey:[@"NSSplitView Subview Frames " stringByAppendingString:autosaveKey(_autosave)]] != nil;
333
+ }
334
+
335
+ - (void)installInWindow {
336
+ NSWindow *window = self.window;
337
+ if (window == nil || _controller != nil) {
338
+ return;
339
+ }
340
+ NSRect frame = window.frame;
341
+ _ownWindow = window;
342
+ _surfaceView = window.contentView;
343
+
344
+ NSViewController *side = [NSViewController new];
345
+ NSView *sideView = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, [self startingWidth], NSHeight(frame))];
346
+ side.view = sideView;
347
+ // Below the title bar, where the window controls are; the sidebar's material runs under it.
348
+ _sidebarContainer.translatesAutoresizingMaskIntoConstraints = NO;
349
+ [sideView addSubview:_sidebarContainer];
350
+ [NSLayoutConstraint activateConstraints:@[
351
+ [_sidebarContainer.topAnchor constraintEqualToAnchor:sideView.safeAreaLayoutGuide.topAnchor],
352
+ [_sidebarContainer.bottomAnchor constraintEqualToAnchor:sideView.bottomAnchor],
353
+ [_sidebarContainer.leadingAnchor constraintEqualToAnchor:sideView.leadingAnchor],
354
+ [_sidebarContainer.trailingAnchor constraintEqualToAnchor:sideView.trailingAnchor],
355
+ ]];
356
+ _sidebarItem = [NSSplitViewItem sidebarWithViewController:side];
357
+ _sidebarItem.canCollapse = YES;
358
+ _sidebarItem.minimumThickness = [self minimumWidth];
359
+ _sidebarItem.maximumThickness = [self maximumWidth];
360
+
361
+ NSViewController *main = [NSViewController new];
362
+ main.view = _contentContainer;
363
+ NSSplitViewItem *contentItem = [NSSplitViewItem splitViewItemWithViewController:main];
364
+
365
+ _controller = [NSSplitViewController new];
366
+ const auto *p = [_sidebar paneProps];
367
+ _autosave = p ? p->autosaveName : std::string{};
368
+ if (!_autosave.empty()) {
369
+ _controller.splitView.autosaveName = autosaveKey(_autosave);
370
+ }
371
+ BOOL restoring = [self hasAutosavedFrames];
372
+ [_controller addSplitViewItem:_sidebarItem];
373
+ [_controller addSplitViewItem:contentItem];
374
+ window.contentViewController = _controller;
375
+ [window setFrame:frame display:YES];
376
+ if (!restoring) {
377
+ [_controller.splitView setPosition:[self startingWidth] ofDividerAtIndex:0];
378
+ }
379
+ [_sidebarItem addObserver:self forKeyPath:@"collapsed" options:NSKeyValueObservingOptionNew context:nil];
380
+ // A collapsed state the autosave restored is the user's: the app hears it.
381
+ if (_sidebarItem.collapsed) {
382
+ [self toolkitCollapsed:YES];
383
+ }
384
+ }
385
+
386
+ - (void)buildPlain {
387
+ if (_plain != nil) {
388
+ return;
389
+ }
390
+ _plain = [[NSSplitView alloc] initWithFrame:self.bounds];
391
+ _plain.vertical = YES;
392
+ _plain.dividerStyle = NSSplitViewDividerStyleThin;
393
+ _plain.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
394
+ _plain.delegate = self;
395
+ const auto *p = [_sidebar paneProps];
396
+ _autosave = p ? p->autosaveName : std::string{};
397
+ if (!_autosave.empty()) {
398
+ _plain.autosaveName = autosaveKey(_autosave);
399
+ }
400
+ BOOL restoring = [self hasAutosavedFrames];
401
+ [_plain addArrangedSubview:_sidebarContainer];
402
+ [_plain addArrangedSubview:_contentContainer];
403
+ [self addSubview:_plain];
404
+ [_plain adjustSubviews];
405
+ if (!restoring) {
406
+ [_plain setPosition:[self startingWidth] ofDividerAtIndex:0];
407
+ }
408
+ _plainWidth = [self startingWidth];
409
+ [NSNotificationCenter.defaultCenter addObserver:self
410
+ selector:@selector(plainResized:)
411
+ name:NSSplitViewDidResizeSubviewsNotification
412
+ object:_plain];
413
+ }
414
+
415
+ - (void)uninstall {
416
+ [NSNotificationCenter.defaultCenter removeObserver:self];
417
+ if (_sidebarItem != nil) {
418
+ [_sidebarItem removeObserver:self forKeyPath:@"collapsed"];
419
+ }
420
+ NSWindow *window = _ownWindow;
421
+ if (window != nil && window.contentViewController == _controller && _surfaceView != nil) {
422
+ NSRect frame = window.frame;
423
+ window.contentViewController = nil;
424
+ window.contentView = _surfaceView;
425
+ [window setFrame:frame display:YES];
426
+ }
427
+ _controller = nil;
428
+ _sidebarItem = nil;
429
+ _ownWindow = nil;
430
+ }
431
+
432
+ - (void)dealloc {
433
+ [self uninstall];
434
+ }
435
+
436
+ // The sidebar's props: its bounds, its autosave and whether the app has it collapsed.
437
+ - (void)paneChanged:(NGNSplitPaneView *)pane {
438
+ if (pane != _sidebar || !_decided) {
439
+ return;
440
+ }
441
+ const auto *p = [_sidebar paneProps];
442
+ if (p == nullptr) {
443
+ return;
444
+ }
445
+ if (_sidebarItem != nil) {
446
+ _sidebarItem.minimumThickness = [self minimumWidth];
447
+ _sidebarItem.maximumThickness = [self maximumWidth];
448
+ }
449
+ if (p->autosaveName != _autosave) {
450
+ _autosave = p->autosaveName;
451
+ NSSplitView *view = _controller != nil ? _controller.splitView : _plain;
452
+ view.autosaveName = autosaveKey(_autosave);
453
+ }
454
+ if (auto collapsed = _collapse.propChanged(p->collapsed)) {
455
+ [self setToolkitCollapsed:*collapsed];
456
+ }
457
+ }
458
+
459
+ - (void)setToolkitCollapsed:(BOOL)collapsed {
460
+ if (_sidebarItem != nil) {
461
+ if (_sidebarItem.collapsed != collapsed) {
462
+ _sidebarItem.animator.collapsed = collapsed;
463
+ }
464
+ } else if (_plain != nil) {
465
+ [_plain setPosition:collapsed ? 0 : _plainWidth ofDividerAtIndex:0];
466
+ }
467
+ }
468
+
469
+ - (void)toolkitCollapsed:(BOOL)collapsed {
470
+ if (_collapse.toolkitChanged(collapsed)) {
471
+ send(_sidebar, "sidebarCollapse", folly::dynamic::object("collapsed", (bool)collapsed));
472
+ }
473
+ }
474
+
475
+ - (void)observeValueForKeyPath:(NSString *)keyPath
476
+ ofObject:(id)object
477
+ change:(NSDictionary<NSKeyValueChangeKey, id> *)change
478
+ context:(void *)context {
479
+ if (object == _sidebarItem) {
480
+ [self toolkitCollapsed:_sidebarItem.collapsed];
481
+ }
482
+ }
483
+
484
+ - (void)plainResized:(NSNotification *)note {
485
+ BOOL collapsed = [_plain isSubviewCollapsed:_sidebarContainer] || NSWidth(_sidebarContainer.frame) < 1;
486
+ if (!collapsed) {
487
+ _plainWidth = NSWidth(_sidebarContainer.frame);
488
+ }
489
+ [self toolkitCollapsed:collapsed];
490
+ }
491
+
492
+ #pragma mark NSSplitViewDelegate (a plain one)
493
+
494
+ - (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview {
495
+ return subview == _sidebarContainer;
496
+ }
497
+
498
+ - (CGFloat)splitView:(NSSplitView *)splitView
499
+ constrainMinCoordinate:(CGFloat)proposedMinimumPosition
500
+ ofSubviewAt:(NSInteger)dividerIndex {
501
+ return [self minimumWidth];
502
+ }
503
+
504
+ - (CGFloat)splitView:(NSSplitView *)splitView
505
+ constrainMaxCoordinate:(CGFloat)proposedMaximumPosition
506
+ ofSubviewAt:(NSInteger)dividerIndex {
507
+ return [self maximumWidth];
508
+ }
509
+
510
+ - (BOOL)splitView:(NSSplitView *)splitView shouldAdjustSizeOfSubview:(NSView *)view {
511
+ return view != _sidebarContainer;
512
+ }
513
+
514
+ @end
515
+
516
+ #pragma mark - Source lists
517
+
518
+ @interface NGNSidebarSectionView () <NGNSizedByToolkit>
519
+ @end
520
+
521
+ @implementation NGNSidebarSectionView
522
+ - (void)setHidden:(BOOL)hidden {
523
+ // The source list draws it.
524
+ [super setHidden:YES];
525
+ }
526
+ - (void)setFolded:(BOOL)folded {
527
+ auto concrete = std::dynamic_pointer_cast<const ConcreteState<ngn::SidebarSectionState>>(self.state);
528
+ if (concrete && concrete->getData().collapsed != folded) {
529
+ concrete->updateState(ngn::SidebarSectionState{.collapsed = static_cast<bool>(folded)});
530
+ }
531
+ }
532
+ - (void)applyToolkitSize:(facebook::react::Size)size {
533
+ }
534
+ @end
535
+
536
+ @interface NGNSidebarItemView () <NGNSizedByToolkit>
537
+ // The custom row's container it is in, once its source list drew it.
538
+ @property (nonatomic, weak) NSView *host;
539
+ @property (nonatomic, copy) void (^heightChanged)(void);
540
+ @end
541
+
542
+ @implementation NGNSidebarItemView
543
+ - (void)updateLayout:(const LayoutMetrics &)metrics {
544
+ CGFloat before = NSHeight(self.frame);
545
+ [super updateLayout:metrics];
546
+ if (self.host != nil && self.superview == self.host) {
547
+ [self setFrameOrigin:NSZeroPoint];
548
+ if (fabs(NSHeight(self.frame) - before) > 0.5 && self.heightChanged) {
549
+ self.heightChanged();
550
+ }
551
+ }
552
+ }
553
+ - (void)applyToolkitSize:(facebook::react::Size)size {
554
+ updatePaneState(self, size);
555
+ }
556
+ @end
557
+
558
+ // The model the outline view reads: a titled section, and a row.
559
+ @interface NGNSourceGroup : NSObject
560
+ @property (nonatomic) NSInteger tag;
561
+ @property (nonatomic, copy) NSString *title;
562
+ @property (nonatomic) BOOL collapsible;
563
+ @property (nonatomic, copy) NSArray *rows;
564
+ @end
565
+ @implementation NGNSourceGroup
566
+ @end
567
+
568
+ @interface NGNSourceRow : NSObject
569
+ @property (nonatomic) NSInteger tag;
570
+ @property (nonatomic) ngn::SidebarRow row;
571
+ @end
572
+ @implementation NGNSourceRow
573
+ @end
574
+
575
+ // A custom row's cell: a container of its own for the item's views, kept for the row (never
576
+ // recycled). A click goes to the content when it lands on something that takes it, and otherwise
577
+ // to the outline view, which selects the row.
578
+ @interface NGNSourceRowHost : NGNSurfaceView
579
+ @property (nonatomic, weak) NGNSidebarItemView *item;
580
+ - (BOOL)takeMouseDown:(NSEvent *)event;
581
+ @end
582
+
583
+ @implementation NGNSourceRowHost
584
+ - (void)setFrameSize:(NSSize)size {
585
+ [super setFrameSize:size];
586
+ if (size.width > 0) {
587
+ // Only the width is the cell's: the row is as tall as the item lays out.
588
+ reportSize(self.item, NSMakeSize(size.width, 0));
589
+ }
590
+ }
591
+ - (NSOutlineView *)outline {
592
+ for (NSView *v = self.superview; v != nil; v = v.superview) {
593
+ if ([v isKindOfClass:NSOutlineView.class]) {
594
+ return (NSOutlineView *)v;
595
+ }
596
+ }
597
+ return nil;
598
+ }
599
+ // The outline view hears the click (it selects rows) and offers it here first: the row's content
600
+ // takes it when it lands on something that takes it. Then the drag and the release follow it.
601
+ - (BOOL)takeMouseDown:(NSEvent *)event {
602
+ NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
603
+ bool takes = gRowContentTakesClick && gRowContentTakesClick(self.item.reactTag, point);
604
+ if (!takes) {
605
+ return NO;
606
+ }
607
+ [super mouseDown:event];
608
+ return YES;
609
+ }
610
+ - (void)dealloc {
611
+ if (gContainerRootChanged && self.item != nil) {
612
+ gContainerRootChanged(self.item.reactTag, NO);
613
+ }
614
+ }
615
+ @end
616
+
617
+ // A native row: the item's SF Symbol, label and badge.
618
+ @interface NGNSourceRowCell : NSTableCellView
619
+ @property (nonatomic, strong) NSTextField *badge;
620
+ @end
621
+
622
+ @implementation NGNSourceRowCell
623
+ - (instancetype)initWithFrame:(NSRect)frame {
624
+ if ((self = [super initWithFrame:frame])) {
625
+ NSImageView *image = [NSImageView new];
626
+ NSTextField *label = [NSTextField labelWithString:@""];
627
+ label.lineBreakMode = NSLineBreakByTruncatingTail;
628
+ [label setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow
629
+ forOrientation:NSLayoutConstraintOrientationHorizontal];
630
+ _badge = [NSTextField labelWithString:@""];
631
+ _badge.textColor = NSColor.secondaryLabelColor;
632
+ _badge.alignment = NSTextAlignmentRight;
633
+ for (NSView *v in @[ image, label, _badge ]) {
634
+ v.translatesAutoresizingMaskIntoConstraints = NO;
635
+ [self addSubview:v];
636
+ }
637
+ self.imageView = image;
638
+ self.textField = label;
639
+ [NSLayoutConstraint activateConstraints:@[
640
+ [image.leadingAnchor constraintEqualToAnchor:self.leadingAnchor constant:2],
641
+ [image.centerYAnchor constraintEqualToAnchor:self.centerYAnchor],
642
+ [image.widthAnchor constraintEqualToConstant:18],
643
+ [label.leadingAnchor constraintEqualToAnchor:image.trailingAnchor constant:6],
644
+ [label.centerYAnchor constraintEqualToAnchor:self.centerYAnchor],
645
+ [_badge.leadingAnchor constraintGreaterThanOrEqualToAnchor:label.trailingAnchor constant:6],
646
+ [_badge.trailingAnchor constraintEqualToAnchor:self.trailingAnchor constant:-14],
647
+ [_badge.centerYAnchor constraintEqualToAnchor:self.centerYAnchor],
648
+ ]];
649
+ }
650
+ return self;
651
+ }
652
+ @end
653
+
654
+ // A row's selection as a source list draws it: rounded, inset from the sidebar's edges, the accent
655
+ // colour while the list has the focus and grey otherwise.
656
+ @interface NGNSourceRowView : NSTableRowView
657
+ @end
658
+
659
+ @implementation NGNSourceRowView
660
+ - (void)drawSelectionInRect:(NSRect)dirtyRect {
661
+ NSRect rect = NSInsetRect(self.bounds, 10, 0);
662
+ NSColor *color =
663
+ self.emphasized ? NSColor.selectedContentBackgroundColor : NSColor.unemphasizedSelectedContentBackgroundColor;
664
+ [color setFill];
665
+ [[NSBezierPath bezierPathWithRoundedRect:rect xRadius:6 yRadius:6] fill];
666
+ }
667
+ @end
668
+
669
+ // One run of sections as one source list.
670
+ @interface NGNSourceListView : NSOutlineView <NSOutlineViewDataSource, NSOutlineViewDelegate>
671
+ @property (nonatomic, copy) NGNView * (^views)(NSInteger tag);
672
+ // A tabs host's: it fills its scroll view, in the source-list style, and a choice goes to `chose`
673
+ // rather than to the row's item.
674
+ @property (nonatomic) BOOL fills;
675
+ @property (nonatomic, copy) void (^chose)(NSInteger rowTag);
676
+ - (void)setList:(const ngn::SourceList &)list;
677
+ - (void)layOutInParent;
678
+ @end
679
+
680
+ @implementation NGNSourceListView {
681
+ ngn::SourceList _list;
682
+ NSArray *_top;
683
+ NSMutableDictionary<NSNumber *, id> *_objects;
684
+ NSMutableDictionary<NSNumber *, NGNSourceRowHost *> *_hosts;
685
+ // Sections the user folded away.
686
+ NSMutableSet<NSNumber *> *_folded;
687
+ BOOL _syncing;
688
+ // The custom row whose content took the click in progress.
689
+ NGNSourceRowHost *_claimedBy;
690
+ }
691
+
692
+ - (instancetype)initWithFrame:(NSRect)frame {
693
+ if ((self = [super initWithFrame:frame])) {
694
+ _objects = [NSMutableDictionary dictionary];
695
+ _hosts = [NSMutableDictionary dictionary];
696
+ _folded = [NSMutableSet set];
697
+ _top = @[];
698
+ NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:@"row"];
699
+ column.resizingMask = NSTableColumnAutoresizingMask;
700
+ [self addTableColumn:column];
701
+ self.outlineTableColumn = column;
702
+ self.headerView = nil;
703
+ // The plain style lays rows out exactly at their heights, as Yoga does: the source-list style
704
+ // adds insets above and between sections. Its rounded selection is drawn by NGNSourceRowView.
705
+ self.style = NSTableViewStylePlain;
706
+ self.backgroundColor = NSColor.clearColor;
707
+ self.focusRingType = NSFocusRingTypeNone;
708
+ self.intercellSpacing = NSMakeSize(0, 0);
709
+ self.floatsGroupRows = NO;
710
+ self.columnAutoresizingStyle = NSTableViewUniformColumnAutoresizingStyle;
711
+ self.dataSource = self;
712
+ self.delegate = self;
713
+ }
714
+ return self;
715
+ }
716
+
717
+ - (BOOL)isFlipped {
718
+ return YES;
719
+ }
720
+
721
+ // NSTableView's hit test answers the table for a cell's content, so the custom row under the click
722
+ // is found by where it is.
723
+ - (void)mouseDown:(NSEvent *)event {
724
+ for (NGNSourceRowHost *host in _hosts.allValues) {
725
+ if (host.window == self.window &&
726
+ NSPointInRect([host convertPoint:event.locationInWindow fromView:nil], host.bounds)) {
727
+ if ([host takeMouseDown:event]) {
728
+ _claimedBy = host;
729
+ return;
730
+ }
731
+ break;
732
+ }
733
+ }
734
+ [super mouseDown:event];
735
+ }
736
+
737
+ - (void)mouseDragged:(NSEvent *)event {
738
+ if (_claimedBy != nil) {
739
+ [_claimedBy mouseDragged:event];
740
+ } else {
741
+ [super mouseDragged:event];
742
+ }
743
+ }
744
+
745
+ - (void)mouseUp:(NSEvent *)event {
746
+ if (_claimedBy != nil) {
747
+ [_claimedBy mouseUp:event];
748
+ _claimedBy = nil;
749
+ } else {
750
+ [super mouseUp:event];
751
+ }
752
+ }
753
+
754
+ - (id)objectFor:(NSInteger)tag class:(Class)cls {
755
+ id object = _objects[@(tag)];
756
+ if (![object isKindOfClass:cls]) {
757
+ object = [cls new];
758
+ _objects[@(tag)] = object;
759
+ }
760
+ return object;
761
+ }
762
+
763
+ - (void)setList:(const ngn::SourceList &)list {
764
+ _list = list;
765
+ NSMutableArray *top = [NSMutableArray array];
766
+ NSMutableSet<NSNumber *> *live = [NSMutableSet set];
767
+ for (const auto &g : list.groups) {
768
+ NSMutableArray *rows = [NSMutableArray array];
769
+ for (const auto &r : g.rows) {
770
+ NGNSourceRow *row = [self objectFor:r.tag class:NGNSourceRow.class];
771
+ row.tag = r.tag;
772
+ row.row = r;
773
+ [rows addObject:row];
774
+ [live addObject:@(r.tag)];
775
+ }
776
+ if (g.title.empty()) {
777
+ [top addObjectsFromArray:rows];
778
+ } else {
779
+ NGNSourceGroup *group = [self objectFor:g.tag class:NGNSourceGroup.class];
780
+ group.tag = g.tag;
781
+ group.title = nsString(g.title);
782
+ group.collapsible = g.collapsible;
783
+ group.rows = rows;
784
+ [top addObject:group];
785
+ [live addObject:@(g.tag)];
786
+ }
787
+ }
788
+ _top = top;
789
+ for (NSNumber *tag in _objects.allKeys) {
790
+ if (![live containsObject:tag]) {
791
+ [_objects removeObjectForKey:tag];
792
+ [_folded removeObject:tag];
793
+ [_hosts removeObjectForKey:tag];
794
+ }
795
+ }
796
+ _syncing = YES;
797
+ [self reloadData];
798
+ for (id item in _top) {
799
+ if ([item isKindOfClass:NGNSourceGroup.class] && ![_folded containsObject:@(((NGNSourceGroup *)item).tag)]) {
800
+ [self expandItem:item];
801
+ }
802
+ }
803
+ _syncing = NO;
804
+ [self syncSelection];
805
+ [self layOutInParent];
806
+ }
807
+
808
+ // The row the app says is selected, which survives its section folding away and back.
809
+ - (void)syncSelection {
810
+ _syncing = YES;
811
+ NSInteger selected = -1;
812
+ for (NSNumber *tag in _objects) {
813
+ NGNSourceRow *row = _objects[tag];
814
+ if ([row isKindOfClass:NGNSourceRow.class] && row.row.selected) {
815
+ selected = [self rowForItem:row];
816
+ }
817
+ }
818
+ if (selected >= 0) {
819
+ [self selectRowIndexes:[NSIndexSet indexSetWithIndex:(NSUInteger)selected] byExtendingSelection:NO];
820
+ } else {
821
+ [self deselectAll:nil];
822
+ }
823
+ _syncing = NO;
824
+ }
825
+
826
+ // Over the union of its sections' frames, in their parent.
827
+ - (void)setFills:(BOOL)fills {
828
+ _fills = fills;
829
+ self.style = fills ? NSTableViewStyleSourceList : NSTableViewStylePlain;
830
+ }
831
+
832
+ // Filling its scroll view, its one column is as wide as the view.
833
+ - (void)setFrameSize:(NSSize)size {
834
+ [super setFrameSize:size];
835
+ if (self.fills) {
836
+ [self sizeLastColumnToFit];
837
+ }
838
+ }
839
+
840
+ - (void)layOutInParent {
841
+ if (self.fills) {
842
+ return;
843
+ }
844
+ NSRect frame = NSZeroRect;
845
+ BOOL first = YES;
846
+ for (const auto &g : _list.groups) {
847
+ NGNView *section = self.views ? self.views(g.tag) : nil;
848
+ if (section == nil) {
849
+ continue;
850
+ }
851
+ frame = first ? section.frame : NSUnionRect(frame, section.frame);
852
+ first = NO;
853
+ }
854
+ if (!NSEqualRects(self.frame, frame)) {
855
+ self.frame = frame;
856
+ [self sizeLastColumnToFit];
857
+ }
858
+ }
859
+
860
+ #pragma mark Data source
861
+
862
+ - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
863
+ if (item == nil) {
864
+ return (NSInteger)_top.count;
865
+ }
866
+ return [item isKindOfClass:NGNSourceGroup.class] ? (NSInteger)((NGNSourceGroup *)item).rows.count : 0;
867
+ }
868
+
869
+ - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
870
+ return item == nil ? _top[(NSUInteger)index] : ((NGNSourceGroup *)item).rows[(NSUInteger)index];
871
+ }
872
+
873
+ - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
874
+ return [item isKindOfClass:NGNSourceGroup.class];
875
+ }
876
+
877
+ #pragma mark Delegate
878
+
879
+ - (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item {
880
+ return [item isKindOfClass:NGNSourceGroup.class];
881
+ }
882
+
883
+ - (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(id)item {
884
+ return [item isKindOfClass:NGNSourceGroup.class] && ((NGNSourceGroup *)item).collapsible;
885
+ }
886
+
887
+ - (BOOL)outlineView:(NSOutlineView *)outlineView shouldCollapseItem:(id)item {
888
+ return [item isKindOfClass:NGNSourceGroup.class] && ((NGNSourceGroup *)item).collapsible;
889
+ }
890
+
891
+ - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item {
892
+ return [item isKindOfClass:NGNSourceRow.class];
893
+ }
894
+
895
+ - (NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item {
896
+ return self.fills ? nil : [NGNSourceRowView new];
897
+ }
898
+
899
+ - (CGFloat)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id)item {
900
+ if ([item isKindOfClass:NGNSourceGroup.class]) {
901
+ return ngn::kSidebarHeaderHeight;
902
+ }
903
+ NGNSourceRow *row = item;
904
+ if (row.row.custom) {
905
+ NGNView *view = self.views ? self.views(row.tag) : nil;
906
+ return std::max<CGFloat>(ngn::kSidebarRowHeight, NSHeight(view.frame));
907
+ }
908
+ return ngn::kSidebarRowHeight;
909
+ }
910
+
911
+ - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)column item:(id)item {
912
+ if ([item isKindOfClass:NGNSourceGroup.class]) {
913
+ NSTableCellView *cell = [outlineView makeViewWithIdentifier:@"header" owner:self];
914
+ if (cell == nil) {
915
+ cell = [NSTableCellView new];
916
+ cell.identifier = @"header";
917
+ NSTextField *title = [NSTextField labelWithString:@""];
918
+ title.font = [NSFont systemFontOfSize:NSFont.smallSystemFontSize weight:NSFontWeightSemibold];
919
+ title.textColor = NSColor.secondaryLabelColor;
920
+ title.translatesAutoresizingMaskIntoConstraints = NO;
921
+ [cell addSubview:title];
922
+ cell.textField = title;
923
+ [NSLayoutConstraint activateConstraints:@[
924
+ [title.leadingAnchor constraintEqualToAnchor:cell.leadingAnchor constant:2],
925
+ [title.centerYAnchor constraintEqualToAnchor:cell.centerYAnchor],
926
+ ]];
927
+ }
928
+ cell.textField.stringValue = ((NGNSourceGroup *)item).title;
929
+ return cell;
930
+ }
931
+ NGNSourceRow *row = item;
932
+ if (row.row.custom) {
933
+ return [self hostFor:row];
934
+ }
935
+ NGNSourceRowCell *cell = [outlineView makeViewWithIdentifier:@"row" owner:self];
936
+ if (cell == nil) {
937
+ cell = [[NGNSourceRowCell alloc] initWithFrame:NSZeroRect];
938
+ cell.identifier = @"row";
939
+ }
940
+ const auto &r = row.row;
941
+ cell.textField.stringValue = nsString(r.label);
942
+ cell.imageView.image = r.sfSymbol.empty()
943
+ ? nil
944
+ : [NSImage imageWithSystemSymbolName:nsString(r.sfSymbol) accessibilityDescription:nil];
945
+ cell.badge.stringValue = nsString(r.badge);
946
+ cell.badge.hidden = r.badge.empty();
947
+ return cell;
948
+ }
949
+
950
+ - (NGNSourceRowHost *)hostFor:(NGNSourceRow *)row {
951
+ NGNSourceRowHost *host = _hosts[@(row.tag)];
952
+ NGNSidebarItemView *item = (NGNSidebarItemView *)(self.views ? self.views(row.tag) : nil);
953
+ if (![item isKindOfClass:NGNSidebarItemView.class] || gInput == nullptr) {
954
+ return nil;
955
+ }
956
+ if (host == nil || host.item != item) {
957
+ host = [[NGNSourceRowHost alloc] initWithFrame:NSMakeRect(0, 0, NSWidth(self.bounds), NSHeight(item.frame))
958
+ surfaceId:static_cast<SurfaceId>(item.surfaceId)
959
+ container:static_cast<ngn::ContainerId>(item.reactTag)
960
+ rootTag:static_cast<Tag>(item.reactTag)
961
+ input:gInput];
962
+ host.item = item;
963
+ host.wantsLayer = YES;
964
+ _hosts[@(row.tag)] = host;
965
+ if (gContainerRootChanged) {
966
+ gContainerRootChanged(item.reactTag, YES);
967
+ }
968
+ }
969
+ if (item.superview != host) {
970
+ [item removeFromSuperview];
971
+ [host addSubview:item];
972
+ }
973
+ item.host = host;
974
+ [item setFrameOrigin:NSZeroPoint];
975
+ __weak NGNSourceListView *weakSelf = self;
976
+ __weak NGNSourceRow *weakRow = row;
977
+ item.heightChanged = ^{
978
+ NGNSourceListView *list = weakSelf;
979
+ NSInteger index = [list rowForItem:weakRow];
980
+ if (index >= 0) {
981
+ [list noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndex:(NSUInteger)index]];
982
+ }
983
+ };
984
+ return host;
985
+ }
986
+
987
+ - (void)outlineViewSelectionDidChange:(NSNotification *)notification {
988
+ if (_syncing) {
989
+ return;
990
+ }
991
+ id item = [self itemAtRow:self.selectedRow];
992
+ if (![item isKindOfClass:NGNSourceRow.class]) {
993
+ return;
994
+ }
995
+ NSInteger tag = ((NGNSourceRow *)item).tag;
996
+ if (self.chose) {
997
+ self.chose(tag);
998
+ return;
999
+ }
1000
+ NGNView *view = self.views ? self.views(tag) : nil;
1001
+ send(view, "sidebarSelect", folly::dynamic::object());
1002
+ }
1003
+
1004
+ - (void)outlineViewItemDidCollapse:(NSNotification *)notification {
1005
+ [self folded:notification.userInfo[@"NSObject"] folded:YES];
1006
+ }
1007
+
1008
+ - (void)outlineViewItemDidExpand:(NSNotification *)notification {
1009
+ [self folded:notification.userInfo[@"NSObject"] folded:NO];
1010
+ if (!_syncing) {
1011
+ [self syncSelection];
1012
+ }
1013
+ }
1014
+
1015
+ - (void)folded:(id)item folded:(BOOL)folded {
1016
+ if (![item isKindOfClass:NGNSourceGroup.class]) {
1017
+ return;
1018
+ }
1019
+ NSInteger tag = ((NGNSourceGroup *)item).tag;
1020
+ if (!_syncing) {
1021
+ if (folded) {
1022
+ [_folded addObject:@(tag)];
1023
+ } else {
1024
+ [_folded removeObject:@(tag)];
1025
+ }
1026
+ }
1027
+ NGNView *section = self.views ? self.views(tag) : nil;
1028
+ if ([section isKindOfClass:NGNSidebarSectionView.class]) {
1029
+ [(NGNSidebarSectionView *)section setFolded:folded];
1030
+ }
1031
+ }
1032
+
1033
+ @end
1034
+
1035
+ @implementation NGNSourceLists {
1036
+ __weak NGNView *_parent;
1037
+ NSMutableArray<NGNSourceListView *> *_lists;
1038
+ }
1039
+
1040
+ - (instancetype)initWithParent:(NGNView *)parent {
1041
+ if ((self = [super init])) {
1042
+ _parent = parent;
1043
+ _lists = [NSMutableArray array];
1044
+ }
1045
+ return self;
1046
+ }
1047
+
1048
+ - (void)setLists:(const std::vector<ngn::SourceList> &)lists views:(NGNView * (^)(NSInteger tag))views {
1049
+ while (_lists.count > lists.size()) {
1050
+ [_lists.lastObject removeFromSuperview];
1051
+ [_lists removeLastObject];
1052
+ }
1053
+ while (_lists.count < lists.size()) {
1054
+ NGNSourceListView *list = [[NGNSourceListView alloc] initWithFrame:NSZeroRect];
1055
+ [_parent.contentContainer addSubview:list];
1056
+ [_lists addObject:list];
1057
+ }
1058
+ for (size_t i = 0; i < lists.size(); i++) {
1059
+ _lists[i].views = views;
1060
+ [_lists[i] setList:lists[i]];
1061
+ }
1062
+ }
1063
+
1064
+ - (void)layOut {
1065
+ for (NGNSourceListView *list in _lists) {
1066
+ [list layOutInParent];
1067
+ }
1068
+ }
1069
+
1070
+ - (void)remove {
1071
+ for (NGNSourceListView *list in _lists) {
1072
+ [list removeFromSuperview];
1073
+ }
1074
+ [_lists removeAllObjects];
1075
+ }
1076
+
1077
+ @end
1078
+
1079
+ #pragma mark - Tabs
1080
+
1081
+ namespace {
1082
+ std::function<void(NSInteger, NSInteger, NSInteger)> gTabChosen;
1083
+ } // namespace
1084
+
1085
+ @interface NGNTabScreenView () <NGNSizedByToolkit>
1086
+ @end
1087
+
1088
+ @implementation NGNTabScreenView
1089
+ - (void)applyToolkitSize:(facebook::react::Size)size {
1090
+ updatePaneState(self, size);
1091
+ }
1092
+ @end
1093
+
1094
+ // The flipped view a tabs host's screens mount in.
1095
+ @interface NGNTabsScreens : NSView
1096
+ @end
1097
+ @implementation NGNTabsScreens
1098
+ - (BOOL)isFlipped {
1099
+ return YES;
1100
+ }
1101
+ @end
1102
+
1103
+ // The content pane of a tabs host: part of the surface, hit-tested from the host, and the size
1104
+ // every tab's screen takes.
1105
+ @interface NGNTabsContent : NGNSurfaceView
1106
+ @property (nonatomic, weak) NSView *screens;
1107
+ @end
1108
+
1109
+ @implementation NGNTabsContent
1110
+ - (void)setFrameSize:(NSSize)size {
1111
+ [super setFrameSize:size];
1112
+ if (size.width > 0 && size.height > 0) {
1113
+ for (NSView *screen in self.screens.subviews) {
1114
+ if ([screen isKindOfClass:NGNTabScreenView.class]) {
1115
+ reportSize((NGNTabScreenView *)screen, size);
1116
+ }
1117
+ }
1118
+ }
1119
+ }
1120
+ @end
1121
+
1122
+ @implementation NGNTabsHostView {
1123
+ NGNTabsScreens *_screens;
1124
+ NGNTabsContent *_content;
1125
+ NSScrollView *_scroll;
1126
+ NGNSourceListView *_list;
1127
+ }
1128
+
1129
+ + (std::function<void(NSInteger, NSInteger, NSInteger)>)tabChosen {
1130
+ return gTabChosen;
1131
+ }
1132
+ + (void)setTabChosen:(std::function<void(NSInteger, NSInteger, NSInteger)>)fn {
1133
+ gTabChosen = std::move(fn);
1134
+ }
1135
+
1136
+ - (instancetype)initWithShadowView:(const ShadowView &)view {
1137
+ if ((self = [super initWithShadowView:view])) {
1138
+ _screens = [[NGNTabsScreens alloc] initWithFrame:NSMakeRect(0, 0, 600, 400)];
1139
+ _screens.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
1140
+ if (gInput != nullptr) {
1141
+ _content = [[NGNTabsContent alloc] initWithFrame:_screens.frame
1142
+ surfaceId:view.surfaceId
1143
+ container:static_cast<ngn::ContainerId>(view.tag)
1144
+ rootTag:view.tag
1145
+ input:gInput];
1146
+ _content.wantsLayer = YES;
1147
+ _content.screens = _screens;
1148
+ [_content addSubview:_screens];
1149
+ if (gContainerRootChanged) {
1150
+ gContainerRootChanged(view.tag, YES);
1151
+ }
1152
+ }
1153
+ _list = [[NGNSourceListView alloc] initWithFrame:NSMakeRect(0, 0, 240, 400)];
1154
+ _list.fills = YES;
1155
+ NSInteger surface = view.surfaceId;
1156
+ NSInteger host = view.tag;
1157
+ _list.chose = ^(NSInteger screen) {
1158
+ if (gTabChosen) {
1159
+ gTabChosen(surface, host, screen);
1160
+ }
1161
+ };
1162
+ _scroll = [[NSScrollView alloc] initWithFrame:_list.frame];
1163
+ _scroll.drawsBackground = NO;
1164
+ _scroll.hasVerticalScroller = YES;
1165
+ _scroll.autohidesScrollers = YES;
1166
+ _scroll.documentView = _list;
1167
+ [self setSidebarView:_scroll contentView:_content];
1168
+ }
1169
+ return self;
1170
+ }
1171
+
1172
+ - (NSView *)contentContainer {
1173
+ return _screens;
1174
+ }
1175
+
1176
+ - (void)mountChild:(NGNView *)child index:(NSInteger)index {
1177
+ NSMutableArray<NSView *> *siblings = [NSMutableArray array];
1178
+ for (NSView *v in _screens.subviews) {
1179
+ if ([v isKindOfClass:NGNView.class]) {
1180
+ [siblings addObject:v];
1181
+ }
1182
+ }
1183
+ if (index >= (NSInteger)siblings.count) {
1184
+ [_screens addSubview:child];
1185
+ } else {
1186
+ [_screens addSubview:child positioned:NSWindowBelow relativeTo:siblings[(NSUInteger)index]];
1187
+ }
1188
+ if ([child isKindOfClass:NGNTabScreenView.class] && NSWidth(_content.bounds) > 0) {
1189
+ reportSize((NGNTabScreenView *)child, _content.bounds.size);
1190
+ }
1191
+ }
1192
+
1193
+ - (void)unmountChild:(NGNView *)child {
1194
+ [child removeFromSuperview];
1195
+ }
1196
+
1197
+ - (void)setTabs:(const ngn::SourceList &)tabs {
1198
+ [_list setList:tabs];
1199
+ }
1200
+
1201
+ - (void)dealloc {
1202
+ if (gContainerRootChanged) {
1203
+ gContainerRootChanged(self.reactTag, NO);
1204
+ }
1205
+ }
1206
+ @end