@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,251 @@
1
+ #import "scroll-view.h"
2
+
3
+ #import "scrollers.h"
4
+
5
+ #include <react/renderer/components/scrollview/ScrollViewEventEmitter.h>
6
+ #include <react/renderer/components/scrollview/ScrollViewProps.h>
7
+ #include <react/renderer/components/scrollview/ScrollViewState.h>
8
+ #include <react/renderer/core/ConcreteState.h>
9
+
10
+ using namespace facebook::react;
11
+
12
+ namespace {
13
+ std::function<void(NSInteger, CGPoint)> gOffsetChanged;
14
+ }
15
+
16
+ @interface NGNScrollDocumentView : NSView
17
+ @end
18
+
19
+ @implementation NGNScrollDocumentView
20
+ - (BOOL)isFlipped {
21
+ return YES;
22
+ }
23
+ @end
24
+
25
+ @implementation NGNScrollView {
26
+ NGNWheelScrollView *_scrollView;
27
+ NGNScrollDocumentView *_document;
28
+ State::Shared _scrollState;
29
+ BOOL _applyingState;
30
+ BOOL _showsVertical;
31
+ BOOL _showsHorizontal;
32
+ NGNScrollerStyleObserver *_styleObserver;
33
+ // The `contentOffset` prop last read, and one not yet applied: it waits for the content's size
34
+ // and the view's, and is applied once, as the prop arrives or changes.
35
+ std::optional<facebook::react::Point> _offsetProp;
36
+ std::optional<facebook::react::Point> _pendingOffset;
37
+ BOOL _offsetQueued;
38
+ }
39
+
40
+ + (std::function<void(NSInteger, CGPoint)>)offsetChanged {
41
+ return gOffsetChanged;
42
+ }
43
+
44
+ + (void)setOffsetChanged:(std::function<void(NSInteger, CGPoint)>)offsetChanged {
45
+ gOffsetChanged = std::move(offsetChanged);
46
+ }
47
+
48
+ - (instancetype)initWithShadowView:(const ShadowView &)view {
49
+ if ((self = [super initWithShadowView:view])) {
50
+ _scrollView = [[NGNWheelScrollView alloc] initWithFrame:NSZeroRect];
51
+ _scrollView.drawsBackground = NO;
52
+ _scrollView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
53
+ _scrollView.autohidesScrollers = YES;
54
+ // The user's "Show scroll bars" setting. A legacy scroller's strip is a gutter the content is
55
+ // laid out without (scrollers.h).
56
+ _scrollView.scrollerStyle = NSScroller.preferredScrollerStyle;
57
+ _showsVertical = YES;
58
+ _showsHorizontal = YES;
59
+ _document = [[NGNScrollDocumentView alloc] initWithFrame:NSZeroRect];
60
+ _scrollView.documentView = _document;
61
+ _scrollView.contentView.postsBoundsChangedNotifications = YES;
62
+ [NSNotificationCenter.defaultCenter addObserver:self
63
+ selector:@selector(boundsDidChange:)
64
+ name:NSViewBoundsDidChangeNotification
65
+ object:_scrollView.contentView];
66
+ [self addSubview:_scrollView];
67
+ __weak NGNScrollView *weakSelf = self;
68
+ _styleObserver = [[NGNScrollerStyleObserver alloc] initWithChanged:^{
69
+ [weakSelf updateScrollers];
70
+ }];
71
+ }
72
+ return self;
73
+ }
74
+
75
+ - (void)dealloc {
76
+ [NSNotificationCenter.defaultCenter removeObserver:self];
77
+ ngn::ScrollerGutters::shared().remove(self.reactTag);
78
+ }
79
+
80
+ - (NSView *)contentContainer {
81
+ return _document;
82
+ }
83
+
84
+ - (void)updateProps:(const Props::Shared &)props {
85
+ [super updateProps:props];
86
+ auto p = std::dynamic_pointer_cast<const ScrollViewProps>(props);
87
+ if (!p) {
88
+ return;
89
+ }
90
+ _showsVertical = p->showsVerticalScrollIndicator;
91
+ _showsHorizontal = p->showsHorizontalScrollIndicator;
92
+ [self updateScrollers];
93
+ _scrollView.verticalScrollElasticity = p->bounces ? NSScrollElasticityAutomatic : NSScrollElasticityNone;
94
+ _scrollView.horizontalScrollElasticity = _scrollView.verticalScrollElasticity;
95
+ // The inner scroll view takes the wheel before this view does.
96
+ _scrollView.scrollingDisabled = !p->scrollEnabled;
97
+ if (_offsetProp != p->contentOffset) {
98
+ bool first = !_offsetProp;
99
+ _offsetProp = p->contentOffset;
100
+ if (!first || p->contentOffset != facebook::react::Point{}) {
101
+ _pendingOffset = p->contentOffset;
102
+ }
103
+ [self applyPendingOffsetAfterMount];
104
+ }
105
+ }
106
+
107
+ // After the rest of this mount: its state and its layout, which come after the props in that
108
+ // order, give the content's size and the view's. Once, however many of them change.
109
+ - (void)applyPendingOffsetAfterMount {
110
+ if (!_pendingOffset || _offsetQueued) {
111
+ return;
112
+ }
113
+ _offsetQueued = YES;
114
+ __weak NGNScrollView *weakSelf = self;
115
+ dispatch_async(dispatch_get_main_queue(), ^{
116
+ NGNScrollView *strong = weakSelf;
117
+ if (strong != nil) {
118
+ strong->_offsetQueued = NO;
119
+ [strong applyPendingOffset];
120
+ }
121
+ });
122
+ }
123
+
124
+ // The starting offset the props ask for, within the content, once there is content to scroll. The
125
+ // viewport is the clip view's, which a legacy scroller's gutter makes smaller than this view.
126
+ - (void)applyPendingOffset {
127
+ NSSize doc = _document.frame.size, view = _scrollView.contentView.bounds.size;
128
+ if (!_pendingOffset || doc.width <= 0 || doc.height <= 0 || view.width <= 0 || view.height <= 0) {
129
+ return;
130
+ }
131
+ NSPoint target = NSMakePoint(std::clamp<CGFloat>(_pendingOffset->x, 0, std::max<CGFloat>(0, doc.width - view.width)),
132
+ std::clamp<CGFloat>(_pendingOffset->y, 0, std::max<CGFloat>(0, doc.height - view.height)));
133
+ _pendingOffset.reset();
134
+ NSClipView *clip = _scrollView.contentView;
135
+ [clip scrollToPoint:target];
136
+ [_scrollView reflectScrolledClipView:clip];
137
+ }
138
+
139
+ - (void)updateLayout:(const LayoutMetrics &)metrics {
140
+ [super updateLayout:metrics];
141
+ _scrollView.frame = self.bounds;
142
+ [self updateScrollers];
143
+ [self applyPendingOffsetAfterMount];
144
+ }
145
+
146
+ - (void)updateDesktopProps:(const ngn::DesktopProps &)props {
147
+ [super updateDesktopProps:props];
148
+ [self updateScrollers];
149
+ }
150
+
151
+ // The scrollers the core says show (scrollers.h), in the user's style; `thin` draws AppKit's small
152
+ // ones. When a legacy scroller's gutter changes, the content is laid out again without it.
153
+ - (void)updateScrollers {
154
+ const auto &desktop = self.desktopProps;
155
+ NSSize content = _document.frame.size, view = self.bounds.size;
156
+ auto visibility = ngn::scrollerVisibility(
157
+ desktop,
158
+ _showsVertical,
159
+ _showsHorizontal,
160
+ {static_cast<Float>(content.width), static_cast<Float>(content.height)},
161
+ {static_cast<Float>(view.width), static_cast<Float>(view.height)});
162
+ _scrollView.scrollerStyle = NSScroller.preferredScrollerStyle;
163
+ _scrollView.hasVerticalScroller = visibility.vertical;
164
+ _scrollView.hasHorizontalScroller = visibility.horizontal;
165
+ _scrollView.autohidesScrollers = visibility.autohides;
166
+ BOOL thin = desktop.scrollbarWidth == ngn::ScrollbarWidth::Thin;
167
+ NSControlSize size = thin ? NSControlSizeSmall : NSControlSizeRegular;
168
+ _scrollView.verticalScroller.controlSize = size;
169
+ _scrollView.horizontalScroller.controlSize = size;
170
+ auto gutter = ngn::scrollerGutter(NGNPreferredScrollerStyle(), NGNLegacyScrollerWidth(thin), visibility);
171
+ // Recorded only once there is a state to update, so a gutter is never recorded that no layout
172
+ // has asked for.
173
+ if (_scrollState && ngn::ScrollerGutters::shared().set(self.reactTag, gutter)) {
174
+ [self layOutAgain];
175
+ }
176
+ }
177
+
178
+ // A state update clones the scroll view's node, which reads its gutter (scrollers.h).
179
+ - (void)layOutAgain {
180
+ auto concrete = std::dynamic_pointer_cast<const ConcreteState<ScrollViewState>>(_scrollState);
181
+ if (concrete) {
182
+ concrete->updateState(ScrollViewState(concrete->getData()));
183
+ }
184
+ }
185
+
186
+ - (void)updateState:(const State::Shared &)state {
187
+ [super updateState:state];
188
+ _scrollState = state;
189
+ auto concrete = std::dynamic_pointer_cast<const ConcreteState<ScrollViewState>>(state);
190
+ if (!concrete) {
191
+ return;
192
+ }
193
+ auto size = concrete->getData().getContentSize();
194
+ _applyingState = YES;
195
+ [_document setFrameSize:NSMakeSize(size.width, size.height)];
196
+ _applyingState = NO;
197
+ [self updateScrollers];
198
+ [self applyPendingOffsetAfterMount];
199
+ }
200
+
201
+ - (void)scrollWheel:(NSEvent *)event {
202
+ auto p = std::dynamic_pointer_cast<const ScrollViewProps>(self.props);
203
+ if (p && !p->scrollEnabled) {
204
+ [self.nextResponder scrollWheel:event];
205
+ return;
206
+ }
207
+ [_scrollView scrollWheel:event];
208
+ }
209
+
210
+ - (void)boundsDidChange:(NSNotification *)note {
211
+ NSPoint origin = _scrollView.contentView.bounds.origin;
212
+ if (gOffsetChanged) {
213
+ gOffsetChanged(self.reactTag, origin);
214
+ }
215
+ auto concrete = std::dynamic_pointer_cast<const ConcreteState<ScrollViewState>>(_scrollState);
216
+ if (concrete && !_applyingState) {
217
+ auto data = concrete->getData();
218
+ data.contentOffset = {static_cast<Float>(origin.x), static_cast<Float>(origin.y)};
219
+ concrete->updateState(std::move(data));
220
+ }
221
+ auto emitter = std::dynamic_pointer_cast<const ScrollViewEventEmitter>(self.eventEmitter);
222
+ if (emitter) {
223
+ ScrollEvent event;
224
+ event.contentOffset = {static_cast<Float>(origin.x), static_cast<Float>(origin.y)};
225
+ event.contentSize = {static_cast<Float>(_document.frame.size.width), static_cast<Float>(_document.frame.size.height)};
226
+ event.containerSize = {static_cast<Float>(self.bounds.size.width), static_cast<Float>(self.bounds.size.height)};
227
+ event.zoomScale = 1;
228
+ event.timestamp = NSProcessInfo.processInfo.systemUptime;
229
+ emitter->onScroll(event);
230
+ }
231
+ }
232
+
233
+ - (void)handleCommand:(const std::string &)name args:(const folly::dynamic &)args {
234
+ NSClipView *clip = _scrollView.contentView;
235
+ NSPoint target = clip.bounds.origin;
236
+ if (name == "scrollTo" && args.isArray() && args.size() >= 2) {
237
+ target = NSMakePoint(args[0].asDouble(), args[1].asDouble());
238
+ } else if (name == "scrollToEnd") {
239
+ NSSize doc = _document.frame.size, view = clip.bounds.size;
240
+ target = NSMakePoint(std::max<CGFloat>(0, doc.width - view.width), std::max<CGFloat>(0, doc.height - view.height));
241
+ if (doc.height > view.height) {
242
+ target.x = clip.bounds.origin.x;
243
+ }
244
+ } else {
245
+ return;
246
+ }
247
+ [clip scrollToPoint:target];
248
+ [_scrollView reflectScrolledClipView:clip];
249
+ }
250
+
251
+ @end
@@ -0,0 +1,25 @@
1
+ // The AppKit half of scrollers.h: the scroller style the user's "Show scroll bars" setting gives,
2
+ // how wide a legacy scroller is, and word when the setting changes.
3
+ #pragma once
4
+
5
+ #import <AppKit/AppKit.h>
6
+
7
+ #include "ngn/scrollers.h"
8
+
9
+ ngn::ScrollerStyle NGNPreferredScrollerStyle();
10
+
11
+ // The strip a legacy scroller takes: AppKit's regular one, or its small one for
12
+ // `scrollbar-width: thin`.
13
+ float NGNLegacyScrollerWidth(BOOL thin);
14
+
15
+ // Calls `changed` on the main thread each time the preferred scroller style changes, which the
16
+ // setting does, and in "Automatically" a mouse plugged in or out. Stops when released.
17
+ @interface NGNScrollerStyleObserver : NSObject
18
+ - (instancetype)initWithChanged:(void (^)(void))changed;
19
+ @end
20
+
21
+ // A scroll view's NSScrollView, which takes a wheel turn before the view holding it: with
22
+ // `scrollingDisabled` (`scrollEnabled={false}`) the turn goes past it, up the responder chain.
23
+ @interface NGNWheelScrollView : NSScrollView
24
+ @property (nonatomic) BOOL scrollingDisabled;
25
+ @end
@@ -0,0 +1,43 @@
1
+ #import "scrollers.h"
2
+
3
+ ngn::ScrollerStyle NGNPreferredScrollerStyle() {
4
+ return NSScroller.preferredScrollerStyle == NSScrollerStyleLegacy ? ngn::ScrollerStyle::Legacy
5
+ : ngn::ScrollerStyle::Overlay;
6
+ }
7
+
8
+ float NGNLegacyScrollerWidth(BOOL thin) {
9
+ return static_cast<float>([NSScroller scrollerWidthForControlSize:thin ? NSControlSizeSmall : NSControlSizeRegular
10
+ scrollerStyle:NSScrollerStyleLegacy]);
11
+ }
12
+
13
+ @implementation NGNScrollerStyleObserver {
14
+ id<NSObject> _token;
15
+ }
16
+
17
+ - (instancetype)initWithChanged:(void (^)(void))changed {
18
+ if ((self = [super init])) {
19
+ _token = [NSNotificationCenter.defaultCenter addObserverForName:NSPreferredScrollerStyleDidChangeNotification
20
+ object:nil
21
+ queue:NSOperationQueue.mainQueue
22
+ usingBlock:^(NSNotification *) {
23
+ changed();
24
+ }];
25
+ }
26
+ return self;
27
+ }
28
+
29
+ - (void)dealloc {
30
+ [NSNotificationCenter.defaultCenter removeObserver:_token];
31
+ }
32
+
33
+ @end
34
+
35
+ @implementation NGNWheelScrollView
36
+ - (void)scrollWheel:(NSEvent *)event {
37
+ if (self.scrollingDisabled) {
38
+ [self.nextResponder scrollWheel:event];
39
+ return;
40
+ }
41
+ [super scrollWheel:event];
42
+ }
43
+ @end
@@ -0,0 +1,34 @@
1
+ // `<search-field>` on macOS: an NSSearchField with `@ng-native/expo`'s iOS contract. The text is
2
+ // controlled from JavaScript and a text older than what has been typed since is skipped; Return
3
+ // submits, and the clear button and Escape cancel, emptying the field. No Fabric here, so it is
4
+ // tested on offscreen windows; native-controls.mm puts it in a Fabric view.
5
+ #pragma once
6
+
7
+ #import <AppKit/AppKit.h>
8
+
9
+ #include "ngn/native-controls.h"
10
+
11
+ // The font the field draws its text in: the control size's system font, with the CSS's face, size,
12
+ // weight and slant over it. A name no face has is looked up as a family; one the system lacks
13
+ // keeps the system face.
14
+ NSFont *NGNSearchFieldFont(const ngn::NativeControlProps &props);
15
+
16
+ // How big AppKit draws the field at its control size, font and placeholder, measured with a private
17
+ // NSSearchFieldCell that no view holds. The control measurer calls it on the layout thread, as it
18
+ // measures its other controls' cells; AppKit's threading guide names NSCell main-thread-only.
19
+ NSSize NGNSearchFieldSize(const ngn::NativeControlProps &props);
20
+
21
+ @interface NGNSearchField : NSView
22
+ @property (nonatomic, readonly) NSSearchField *field;
23
+ // The text the user changed, with the count of changes so far.
24
+ @property (nonatomic, copy) void (^changed)(NSString *text, int eventCount);
25
+ // Return, with the text.
26
+ @property (nonatomic, copy) void (^submitted)(NSString *text);
27
+ // The clear button or Escape, after the field is emptied.
28
+ @property (nonatomic, copy) void (^cancelled)(void);
29
+ @property (nonatomic, copy) void (^began)(void);
30
+ @property (nonatomic, copy) void (^ended)(void);
31
+ - (void)apply:(const ngn::NativeControlProps &)props;
32
+ - (void)focus;
33
+ - (void)blur;
34
+ @end
@@ -0,0 +1,291 @@
1
+ #import "search-field.h"
2
+
3
+ #import "text-input-field.h"
4
+
5
+ using ngn::ControlSize;
6
+ using ngn::NativeControlProps;
7
+
8
+ namespace {
9
+
10
+ NSControlSize controlSize(ControlSize size) {
11
+ switch (size) {
12
+ case ControlSize::Mini:
13
+ return NSControlSizeMini;
14
+ case ControlSize::Small:
15
+ return NSControlSizeSmall;
16
+ case ControlSize::Large:
17
+ return NSControlSizeLarge;
18
+ case ControlSize::Regular:
19
+ return NSControlSizeRegular;
20
+ }
21
+ return NSControlSizeRegular;
22
+ }
23
+
24
+ NSString *string(const std::string &s) {
25
+ NSString *out = [NSString stringWithUTF8String:s.c_str()];
26
+ return out != nil ? out : @"";
27
+ }
28
+
29
+ // A CSS weight as AppKit's nearest, as the iOS field maps it to UIKit's.
30
+ NSFontWeight fontWeight(int css) {
31
+ static const NSFontWeight weights[] = {
32
+ NSFontWeightUltraLight,
33
+ NSFontWeightThin,
34
+ NSFontWeightLight,
35
+ NSFontWeightRegular,
36
+ NSFontWeightMedium,
37
+ NSFontWeightSemibold,
38
+ NSFontWeightBold,
39
+ NSFontWeightHeavy,
40
+ NSFontWeightBlack};
41
+ long index = std::lround(css / 100.0) - 1;
42
+ return weights[std::clamp<long>(index, 0, 8)];
43
+ }
44
+
45
+ ngn::TextInputOptions inputOptions(const NativeControlProps &p) {
46
+ ngn::TextInputOptions options{.capitalize = ngn::Capitalize::None};
47
+ if (p.autoCapitalize == "words") {
48
+ options.capitalize = ngn::Capitalize::Words;
49
+ } else if (p.autoCapitalize == "sentences") {
50
+ options.capitalize = ngn::Capitalize::Sentences;
51
+ } else if (p.autoCapitalize == "characters") {
52
+ options.capitalize = ngn::Capitalize::Characters;
53
+ }
54
+ return options;
55
+ }
56
+
57
+ } // namespace
58
+
59
+ NSFont *NGNSearchFieldFont(const NativeControlProps &p) {
60
+ CGFloat base = [NSFont systemFontSizeForControlSize:controlSize(p.controlSize)];
61
+ CGFloat size = p.fontSize ? static_cast<CGFloat>(*p.fontSize) : base;
62
+ NSFont *font = p.fontWeight ? [NSFont systemFontOfSize:size weight:fontWeight(*p.fontWeight)] : [NSFont systemFontOfSize:size];
63
+ if (!p.fontFamily.empty()) {
64
+ NSString *family = string(p.fontFamily);
65
+ NSFont *named = [NSFont fontWithName:family size:size];
66
+ NSString *familyName = named ? named.familyName : ([NSFontManager.sharedFontManager availableMembersOfFontFamily:family] ? family : nil);
67
+ if (familyName && p.fontWeight) {
68
+ NSFontDescriptor *descriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:@{
69
+ NSFontFamilyAttribute : familyName,
70
+ NSFontTraitsAttribute : @{NSFontWeightTrait : @(fontWeight(*p.fontWeight))},
71
+ }];
72
+ NSFont *weighted = [NSFont fontWithDescriptor:descriptor size:size];
73
+ font = weighted ? weighted : font;
74
+ } else if (named) {
75
+ font = named;
76
+ } else if (familyName) {
77
+ NSFontDescriptor *descriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:@{NSFontFamilyAttribute : familyName}];
78
+ NSFont *found = [NSFont fontWithDescriptor:descriptor size:size];
79
+ font = found ? found : font;
80
+ }
81
+ }
82
+ if (p.italic) {
83
+ font = [NSFontManager.sharedFontManager convertFont:font toHaveTrait:NSItalicFontMask];
84
+ }
85
+ return font;
86
+ }
87
+
88
+ NSSize NGNSearchFieldSize(const NativeControlProps &p) {
89
+ @autoreleasepool {
90
+ NSSearchFieldCell *cell = [[NSSearchFieldCell alloc] initTextCell:string(p.text)];
91
+ cell.controlSize = controlSize(p.controlSize);
92
+ cell.font = NGNSearchFieldFont(p);
93
+ cell.placeholderString = string(p.placeholder);
94
+ cell.bezeled = YES;
95
+ cell.editable = YES;
96
+ NSSize size = cell.cellSize;
97
+ // The cell keeps its control size's height whatever the font, so a larger face gets the
98
+ // padding the control size's own font has around it.
99
+ NSFont *system = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:cell.controlSize]];
100
+ auto lineHeight = [](NSFont *font) { return std::ceil(font.ascender - font.descender + font.leading); };
101
+ CGFloat padding = size.height - lineHeight(system);
102
+ CGFloat height = std::max<CGFloat>(size.height, lineHeight(cell.font) + padding);
103
+ return NSMakeSize(std::ceil(size.width), std::ceil(height));
104
+ }
105
+ }
106
+
107
+ @interface NGNSearchField () <NSSearchFieldDelegate>
108
+ - (const ngn::TextInputOptions &)options;
109
+ - (void)fieldDidBecomeFirstResponder;
110
+ @end
111
+
112
+ // The field itself: it tells its box when it takes the keyboard, and keeps the shared field editor
113
+ // to its capitalization.
114
+ @interface NGNSearchControl : NSSearchField
115
+ @property (nonatomic, weak) NGNSearchField *box;
116
+ @end
117
+
118
+ @implementation NGNSearchControl {
119
+ BOOL _inserting;
120
+ }
121
+
122
+ - (BOOL)becomeFirstResponder {
123
+ if (![super becomeFirstResponder]) {
124
+ return NO;
125
+ }
126
+ [self.box fieldDidBecomeFirstResponder];
127
+ return YES;
128
+ }
129
+
130
+ - (BOOL)textView:(NSTextView *)textView shouldChangeTextInRange:(NSRange)range replacementString:(NSString *)string {
131
+ static const ngn::TextInputOptions none{};
132
+ return NGNControlShouldChangeText(
133
+ self, NSSearchField.class, textView, range, string, self.box ? self.box.options : none, &_inserting);
134
+ }
135
+
136
+ - (NSDictionary<NSTextCheckingOptionKey, id> *)textView:(NSTextView *)view
137
+ willCheckTextInRange:(NSRange)range
138
+ options:(NSDictionary<NSTextCheckingOptionKey, id> *)options
139
+ types:(NSTextCheckingTypes *)checkingTypes {
140
+ return self.box ? NGNTextCheckingOptions(options, self.box.options) : options;
141
+ }
142
+
143
+ @end
144
+
145
+ @implementation NGNSearchField {
146
+ ngn::TextInputOptions _options;
147
+ NSColor *_tint;
148
+ int _eventCount;
149
+ CGFloat _height;
150
+ // Counts the editing ends: only the latest one's turn-later check may report a blur.
151
+ NSUInteger _endings;
152
+ }
153
+
154
+ - (instancetype)initWithFrame:(NSRect)frame {
155
+ if ((self = [super initWithFrame:frame])) {
156
+ NGNSearchControl *field = [[NGNSearchControl alloc] initWithFrame:self.bounds];
157
+ field.box = self;
158
+ field.delegate = self;
159
+ field.sendsWholeSearchString = YES;
160
+ _field = field;
161
+ [self addSubview:field];
162
+ [self takeCancelButton];
163
+ }
164
+ return self;
165
+ }
166
+
167
+ - (const ngn::TextInputOptions &)options {
168
+ return _options;
169
+ }
170
+
171
+ // The clear button empties the field through `cancel`, so JavaScript hears the text and the cancel.
172
+ - (void)takeCancelButton {
173
+ NSButtonCell *cancel = ((NSSearchFieldCell *)_field.cell).cancelButtonCell;
174
+ cancel.target = self;
175
+ cancel.action = @selector(cancel);
176
+ }
177
+
178
+ - (void)apply:(const NativeControlProps &)p {
179
+ _field.controlSize = controlSize(p.controlSize);
180
+ _field.font = NGNSearchFieldFont(p);
181
+ NSString *placeholder = string(p.placeholder);
182
+ if (![_field.placeholderString isEqualToString:placeholder]) {
183
+ _field.placeholderString = placeholder;
184
+ }
185
+ _options = inputOptions(p);
186
+ if (p.tintColor) {
187
+ auto c = facebook::react::colorComponentsFromColor(p.tintColor);
188
+ _tint = [NSColor colorWithSRGBRed:c.red green:c.green blue:c.blue alpha:c.alpha];
189
+ } else {
190
+ _tint = nil;
191
+ }
192
+ [self applyTint];
193
+ if (!p.enabled) {
194
+ [self blur]; // before AppKit ends the editing silently
195
+ }
196
+ _field.enabled = p.enabled;
197
+ NSString *text = string(p.text);
198
+ NSText *editor = _field.currentEditor;
199
+ BOOL composing = [editor isKindOfClass:NSTextView.class] && [(NSTextView *)editor hasMarkedText];
200
+ if (ngn::controlledTextIsCurrent(p.mostRecentEventCount, _eventCount, composing) && ![_field.stringValue isEqualToString:text]) {
201
+ _field.stringValue = text;
202
+ }
203
+ [self takeCancelButton];
204
+ _height = NGNSearchFieldSize(p).height;
205
+ [self layoutField];
206
+ }
207
+
208
+ - (void)applyTint {
209
+ if ([_field.currentEditor isKindOfClass:NSTextView.class]) {
210
+ ((NSTextView *)_field.currentEditor).insertionPointColor = _tint ? _tint : NSColor.textColor;
211
+ }
212
+ }
213
+
214
+ - (void)layoutField {
215
+ // Its own height at its control size and font, centred in the box Yoga gives it.
216
+ CGFloat own = _height > 0 ? _height : _field.intrinsicContentSize.height;
217
+ CGFloat height = std::min<CGFloat>(NSHeight(self.bounds), own);
218
+ _field.frame = NSMakeRect(0, std::round((NSHeight(self.bounds) - height) / 2), NSWidth(self.bounds), height);
219
+ }
220
+
221
+ - (void)setFrameSize:(NSSize)size {
222
+ [super setFrameSize:size];
223
+ [self layoutField];
224
+ }
225
+
226
+ - (void)focus {
227
+ [self.window makeFirstResponder:_field];
228
+ }
229
+
230
+ - (void)blur {
231
+ if (_field.currentEditor) {
232
+ [self.window makeFirstResponder:nil];
233
+ }
234
+ }
235
+
236
+ - (void)fieldDidBecomeFirstResponder {
237
+ [self applyTint];
238
+ if (self.began) {
239
+ self.began();
240
+ }
241
+ }
242
+
243
+ - (void)cancel {
244
+ if (_field.stringValue.length > 0) {
245
+ _field.stringValue = @"";
246
+ [self changedTo:@""];
247
+ }
248
+ if (self.cancelled) {
249
+ self.cancelled();
250
+ }
251
+ }
252
+
253
+ - (void)changedTo:(NSString *)text {
254
+ _eventCount++;
255
+ if (self.changed) {
256
+ self.changed(text, _eventCount);
257
+ }
258
+ }
259
+
260
+ - (void)controlTextDidChange:(NSNotification *)note {
261
+ [self changedTo:_field.stringValue];
262
+ }
263
+
264
+ // A turn later, and only when the field no longer edits: a click into the field ends its editing
265
+ // and starts it again at the click's point, which is no blur.
266
+ - (void)controlTextDidEndEditing:(NSNotification *)note {
267
+ __weak NGNSearchField *weakSelf = self;
268
+ NSUInteger ending = ++_endings;
269
+ dispatch_async(dispatch_get_main_queue(), ^{
270
+ NGNSearchField *strongSelf = weakSelf;
271
+ if (strongSelf != nil && strongSelf->_endings == ending && strongSelf.field.currentEditor == nil && strongSelf.ended) {
272
+ strongSelf.ended();
273
+ }
274
+ });
275
+ }
276
+
277
+ - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)selector {
278
+ if (selector == @selector(insertNewline:)) {
279
+ if (self.submitted) {
280
+ self.submitted(_field.stringValue);
281
+ }
282
+ return YES;
283
+ }
284
+ if (selector == @selector(cancelOperation:)) {
285
+ [self cancel];
286
+ return YES;
287
+ }
288
+ return NO;
289
+ }
290
+
291
+ @end
@@ -0,0 +1,19 @@
1
+ // `<native-search-bar>` on macOS: react-native-screens' RNSSearchBar as the window's
2
+ // NSSearchToolbarItem, trailing the toolbar as Finder's and Mail's search does. It reports what the
3
+ // user does as the core's SearchBarInput (header-bar.h) and takes RNSSearchBar's commands. No
4
+ // Fabric here, so it is tested on offscreen windows; header-toolbar.mm puts it in the toolbar.
5
+ #pragma once
6
+
7
+ #import <AppKit/AppKit.h>
8
+
9
+ #include "ngn/header-bar.h"
10
+
11
+ @interface NGNSearchToolbarItem : NSSearchToolbarItem
12
+ // What the user did, with the field's text after it.
13
+ @property (nonatomic, copy) void (^input)(ngn::SearchBarInput input, NSString *text);
14
+ - (void)apply:(const ngn::SearchBarConfig &)config;
15
+ - (void)run:(const ngn::SearchBarCommand &)command;
16
+ // Runs `change`, which may take the item out of its toolbar and put it back, and gives the field
17
+ // the keyboard and selection again if it was editing, with no blur or focus reported.
18
+ - (void)keepFocusAcross:(void (^)(void))change;
19
+ @end