basalt-core 0.0.0-rc5

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 (325) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cli/basalt.d.ts +3 -0
  3. package/dist/cli/basalt.d.ts.map +1 -0
  4. package/dist/cli/basalt.js +47 -0
  5. package/dist/cli/basalt.js.map +1 -0
  6. package/dist/cli/bundle-cli.d.ts +12 -0
  7. package/dist/cli/bundle-cli.d.ts.map +1 -0
  8. package/dist/cli/bundle-cli.js +124 -0
  9. package/dist/cli/bundle-cli.js.map +1 -0
  10. package/dist/cli/bundleWithAssets.d.ts +79 -0
  11. package/dist/cli/bundleWithAssets.d.ts.map +1 -0
  12. package/dist/cli/bundleWithAssets.js +198 -0
  13. package/dist/cli/bundleWithAssets.js.map +1 -0
  14. package/dist/cli/desktop.d.ts +339 -0
  15. package/dist/cli/desktop.d.ts.map +1 -0
  16. package/dist/cli/desktop.js +1029 -0
  17. package/dist/cli/desktop.js.map +1 -0
  18. package/dist/cli/doctor.d.ts +31 -0
  19. package/dist/cli/doctor.d.ts.map +1 -0
  20. package/dist/cli/doctor.js +283 -0
  21. package/dist/cli/doctor.js.map +1 -0
  22. package/dist/cli/init.d.ts +77 -0
  23. package/dist/cli/init.d.ts.map +1 -0
  24. package/dist/cli/init.js +442 -0
  25. package/dist/cli/init.js.map +1 -0
  26. package/dist/cli/metro.d.ts +49 -0
  27. package/dist/cli/metro.d.ts.map +1 -0
  28. package/dist/cli/metro.js +148 -0
  29. package/dist/cli/metro.js.map +1 -0
  30. package/dist/cli/packageApp.d.ts +102 -0
  31. package/dist/cli/packageApp.d.ts.map +1 -0
  32. package/dist/cli/packageApp.js +319 -0
  33. package/dist/cli/packageApp.js.map +1 -0
  34. package/dist/cli/steps.d.ts +34 -0
  35. package/dist/cli/steps.d.ts.map +1 -0
  36. package/dist/cli/steps.js +53 -0
  37. package/dist/cli/steps.js.map +1 -0
  38. package/dist/metro-config.d.ts +168 -0
  39. package/dist/metro-config.d.ts.map +1 -0
  40. package/dist/metro-config.js +671 -0
  41. package/dist/metro-config.js.map +1 -0
  42. package/dist/react-native.config.d.ts +7 -0
  43. package/dist/react-native.config.d.ts.map +1 -0
  44. package/dist/react-native.config.js +80 -0
  45. package/dist/react-native.config.js.map +1 -0
  46. package/dist/src/DragSource.d.ts +52 -0
  47. package/dist/src/DragSource.d.ts.map +1 -0
  48. package/dist/src/DragSource.js +97 -0
  49. package/dist/src/DragSource.js.map +1 -0
  50. package/dist/src/DropTarget.d.ts +58 -0
  51. package/dist/src/DropTarget.d.ts.map +1 -0
  52. package/dist/src/DropTarget.js +131 -0
  53. package/dist/src/DropTarget.js.map +1 -0
  54. package/dist/src/KeyHandler.d.ts +57 -0
  55. package/dist/src/KeyHandler.d.ts.map +1 -0
  56. package/dist/src/KeyHandler.js +48 -0
  57. package/dist/src/KeyHandler.js.map +1 -0
  58. package/dist/src/Menu.d.ts +72 -0
  59. package/dist/src/Menu.d.ts.map +1 -0
  60. package/dist/src/Menu.js +179 -0
  61. package/dist/src/Menu.js.map +1 -0
  62. package/dist/src/TitleBar.d.ts +75 -0
  63. package/dist/src/TitleBar.d.ts.map +1 -0
  64. package/dist/src/TitleBar.js +236 -0
  65. package/dist/src/TitleBar.js.map +1 -0
  66. package/dist/src/Window.d.ts +87 -0
  67. package/dist/src/Window.d.ts.map +1 -0
  68. package/dist/src/Window.js +248 -0
  69. package/dist/src/Window.js.map +1 -0
  70. package/dist/src/closeRequest.d.ts +55 -0
  71. package/dist/src/closeRequest.d.ts.map +1 -0
  72. package/dist/src/closeRequest.js +134 -0
  73. package/dist/src/closeRequest.js.map +1 -0
  74. package/dist/src/index.d.ts +45 -0
  75. package/dist/src/index.d.ts.map +1 -0
  76. package/dist/src/index.js +92 -0
  77. package/dist/src/index.js.map +1 -0
  78. package/dist/src/overrides/Alert.d.ts +69 -0
  79. package/dist/src/overrides/Alert.d.ts.map +1 -0
  80. package/dist/src/overrides/Alert.js +112 -0
  81. package/dist/src/overrides/Alert.js.map +1 -0
  82. package/dist/src/overrides/BaseViewConfig.d.ts +28 -0
  83. package/dist/src/overrides/BaseViewConfig.d.ts.map +1 -0
  84. package/dist/src/overrides/BaseViewConfig.js +72 -0
  85. package/dist/src/overrides/BaseViewConfig.js.map +1 -0
  86. package/dist/src/overrides/Platform.linux.d.ts +10 -0
  87. package/dist/src/overrides/Platform.linux.d.ts.map +1 -0
  88. package/dist/src/overrides/Platform.linux.js +15 -0
  89. package/dist/src/overrides/Platform.linux.js.map +1 -0
  90. package/dist/src/overrides/Platform.macos.d.ts +10 -0
  91. package/dist/src/overrides/Platform.macos.d.ts.map +1 -0
  92. package/dist/src/overrides/Platform.macos.js +15 -0
  93. package/dist/src/overrides/Platform.macos.js.map +1 -0
  94. package/dist/src/overrides/Platform.windows.d.ts +10 -0
  95. package/dist/src/overrides/Platform.windows.d.ts.map +1 -0
  96. package/dist/src/overrides/Platform.windows.js +15 -0
  97. package/dist/src/overrides/Platform.windows.js.map +1 -0
  98. package/dist/src/overrides/ReactDevToolsSettingsManager.d.ts +24 -0
  99. package/dist/src/overrides/ReactDevToolsSettingsManager.d.ts.map +1 -0
  100. package/dist/src/overrides/ReactDevToolsSettingsManager.js +30 -0
  101. package/dist/src/overrides/ReactDevToolsSettingsManager.js.map +1 -0
  102. package/dist/src/overrides/RefreshControl.d.ts +52 -0
  103. package/dist/src/overrides/RefreshControl.d.ts.map +1 -0
  104. package/dist/src/overrides/RefreshControl.js +92 -0
  105. package/dist/src/overrides/RefreshControl.js.map +1 -0
  106. package/dist/src/overrides/ScrollView.d.ts +39 -0
  107. package/dist/src/overrides/ScrollView.d.ts.map +1 -0
  108. package/dist/src/overrides/ScrollView.js +59 -0
  109. package/dist/src/overrides/ScrollView.js.map +1 -0
  110. package/dist/src/overrides/Share.d.ts +96 -0
  111. package/dist/src/overrides/Share.d.ts.map +1 -0
  112. package/dist/src/overrides/Share.js +97 -0
  113. package/dist/src/overrides/Share.js.map +1 -0
  114. package/dist/src/overrides/TextInput.d.ts +81 -0
  115. package/dist/src/overrides/TextInput.d.ts.map +1 -0
  116. package/dist/src/overrides/TextInput.js +213 -0
  117. package/dist/src/overrides/TextInput.js.map +1 -0
  118. package/dist/src/overrides/View.d.ts +36 -0
  119. package/dist/src/overrides/View.d.ts.map +1 -0
  120. package/dist/src/overrides/View.js +99 -0
  121. package/dist/src/overrides/View.js.map +1 -0
  122. package/dist/src/overrides/createPlatform.d.ts +32 -0
  123. package/dist/src/overrides/createPlatform.d.ts.map +1 -0
  124. package/dist/src/overrides/createPlatform.js +84 -0
  125. package/dist/src/overrides/createPlatform.js.map +1 -0
  126. package/dist/src/overrides/setUpDeveloperTools.d.ts +28 -0
  127. package/dist/src/overrides/setUpDeveloperTools.d.ts.map +1 -0
  128. package/dist/src/overrides/setUpDeveloperTools.js +84 -0
  129. package/dist/src/overrides/setUpDeveloperTools.js.map +1 -0
  130. package/dist/src/overrides/setUpXHR.d.ts +46 -0
  131. package/dist/src/overrides/setUpXHR.d.ts.map +1 -0
  132. package/dist/src/overrides/setUpXHR.js +236 -0
  133. package/dist/src/overrides/setUpXHR.js.map +1 -0
  134. package/dist/src/quitRequest.d.ts +55 -0
  135. package/dist/src/quitRequest.d.ts.map +1 -0
  136. package/dist/src/quitRequest.js +121 -0
  137. package/dist/src/quitRequest.js.map +1 -0
  138. package/dist/src/resourcePath.d.ts +18 -0
  139. package/dist/src/resourcePath.d.ts.map +1 -0
  140. package/dist/src/resourcePath.js +31 -0
  141. package/dist/src/resourcePath.js.map +1 -0
  142. package/dist/src/responseBody.d.ts +76 -0
  143. package/dist/src/responseBody.d.ts.map +1 -0
  144. package/dist/src/responseBody.js +94 -0
  145. package/dist/src/responseBody.js.map +1 -0
  146. package/dist/src/responseHeaders.d.ts +40 -0
  147. package/dist/src/responseHeaders.d.ts.map +1 -0
  148. package/dist/src/responseHeaders.js +75 -0
  149. package/dist/src/responseHeaders.js.map +1 -0
  150. package/dist/src/titleBarState.d.ts +43 -0
  151. package/dist/src/titleBarState.d.ts.map +1 -0
  152. package/dist/src/titleBarState.js +77 -0
  153. package/dist/src/titleBarState.js.map +1 -0
  154. package/dist/src/useContextMenu.d.ts +113 -0
  155. package/dist/src/useContextMenu.d.ts.map +1 -0
  156. package/dist/src/useContextMenu.js +109 -0
  157. package/dist/src/useContextMenu.js.map +1 -0
  158. package/dist/src/useDialog.d.ts +98 -0
  159. package/dist/src/useDialog.d.ts.map +1 -0
  160. package/dist/src/useDialog.js +112 -0
  161. package/dist/src/useDialog.js.map +1 -0
  162. package/dist/src/useDisplays.d.ts +70 -0
  163. package/dist/src/useDisplays.d.ts.map +1 -0
  164. package/dist/src/useDisplays.js +118 -0
  165. package/dist/src/useDisplays.js.map +1 -0
  166. package/dist/src/useHandledKeys.d.ts +38 -0
  167. package/dist/src/useHandledKeys.d.ts.map +1 -0
  168. package/dist/src/useHandledKeys.js +70 -0
  169. package/dist/src/useHandledKeys.js.map +1 -0
  170. package/dist/src/useWindow.d.ts +140 -0
  171. package/dist/src/useWindow.d.ts.map +1 -0
  172. package/dist/src/useWindow.js +233 -0
  173. package/dist/src/useWindow.js.map +1 -0
  174. package/dist/tsconfig.tsbuildinfo +1 -0
  175. package/native/CMakeLists.txt +355 -0
  176. package/native/bootstrap.sh +613 -0
  177. package/native/cmake/CompilerFlags.cmake +49 -0
  178. package/native/cmake/Expo.cmake +125 -0
  179. package/native/cmake/ReactNativeCore.cmake +612 -0
  180. package/native/cmake/Reanimated.cmake +108 -0
  181. package/native/cmake/Skia.cmake +379 -0
  182. package/native/cmake/ThirdParty.cmake +290 -0
  183. package/native/cmake/Worklets.cmake +67 -0
  184. package/native/cmake/codegen/CMakeLists.txt +32 -0
  185. package/native/core/AppIdentity.cpp +85 -0
  186. package/native/core/AppIdentity.h +59 -0
  187. package/native/core/AppPaths.cpp +96 -0
  188. package/native/core/AppPaths.h +53 -0
  189. package/native/core/AppearanceModule.cpp +60 -0
  190. package/native/core/AppearanceModule.h +40 -0
  191. package/native/core/Backface.h +59 -0
  192. package/native/core/BlobModule.cpp +283 -0
  193. package/native/core/BlobModule.h +76 -0
  194. package/native/core/BlobRegistry.cpp +75 -0
  195. package/native/core/BlobRegistry.h +44 -0
  196. package/native/core/ColorScheme.cpp +105 -0
  197. package/native/core/ColorScheme.h +59 -0
  198. package/native/core/ComponentRegistry.h +30 -0
  199. package/native/core/ControlMetrics.h +37 -0
  200. package/native/core/CoreModules.cpp +592 -0
  201. package/native/core/CoreModules.h +308 -0
  202. package/native/core/DebuggingOverlay.cpp +106 -0
  203. package/native/core/DebuggingOverlay.h +65 -0
  204. package/native/core/DesktopControls.cpp +232 -0
  205. package/native/core/DesktopControls.h +170 -0
  206. package/native/core/DevBundle.cpp +108 -0
  207. package/native/core/DevBundle.h +69 -0
  208. package/native/core/DevMenu.cpp +99 -0
  209. package/native/core/DevMenu.h +75 -0
  210. package/native/core/DialogModule.cpp +150 -0
  211. package/native/core/DialogModule.h +51 -0
  212. package/native/core/DragAndDrop.cpp +45 -0
  213. package/native/core/DragAndDrop.h +225 -0
  214. package/native/core/ExpoImageComponent.cpp +79 -0
  215. package/native/core/ExpoImageComponent.h +80 -0
  216. package/native/core/ExpoModules.cpp +415 -0
  217. package/native/core/ExpoModules.h +115 -0
  218. package/native/core/ExpoRuntime.cpp +366 -0
  219. package/native/core/ExpoRuntime.h +42 -0
  220. package/native/core/FocusRing.h +36 -0
  221. package/native/core/FontRegistry.h +51 -0
  222. package/native/core/GestureHandlerModule.cpp +136 -0
  223. package/native/core/GestureHandlerModule.h +71 -0
  224. package/native/core/Gestures.cpp +533 -0
  225. package/native/core/Gestures.h +145 -0
  226. package/native/core/HoverTracker.cpp +69 -0
  227. package/native/core/HoverTracker.h +109 -0
  228. package/native/core/HttpClient.cpp +282 -0
  229. package/native/core/ImageBytes.cpp +205 -0
  230. package/native/core/ImageBytes.h +29 -0
  231. package/native/core/ImageCache.cpp +51 -0
  232. package/native/core/ImageCache.h +89 -0
  233. package/native/core/JsRuntimeAccess.cpp +70 -0
  234. package/native/core/JsRuntimeAccess.h +60 -0
  235. package/native/core/JsiPromise.h +51 -0
  236. package/native/core/KeyEvents.cpp +116 -0
  237. package/native/core/KeyEvents.h +144 -0
  238. package/native/core/LogBoxSurface.cpp +46 -0
  239. package/native/core/LogBoxSurface.h +68 -0
  240. package/native/core/MenuModel.h +117 -0
  241. package/native/core/MenuModule.cpp +209 -0
  242. package/native/core/MenuModule.h +66 -0
  243. package/native/core/MountingWalk.h +524 -0
  244. package/native/core/PackageModules.cpp.in +25 -0
  245. package/native/core/PackageModules.h +50 -0
  246. package/native/core/PlatformConstantsModule.cpp +63 -0
  247. package/native/core/PlatformConstantsModule.h +64 -0
  248. package/native/core/PlatformServices.h +213 -0
  249. package/native/core/PointerButtons.h +63 -0
  250. package/native/core/PullToRefresh.cpp +57 -0
  251. package/native/core/PullToRefresh.h +73 -0
  252. package/native/core/ReanimatedCompat.h +47 -0
  253. package/native/core/ReanimatedModule.cpp +203 -0
  254. package/native/core/ReanimatedModule.h +55 -0
  255. package/native/core/ScrollAnimation.cpp +59 -0
  256. package/native/core/ScrollAnimation.h +70 -0
  257. package/native/core/ScrollBounds.cpp +26 -0
  258. package/native/core/ScrollBounds.h +68 -0
  259. package/native/core/ScrollIndicator.cpp +50 -0
  260. package/native/core/ScrollIndicator.h +69 -0
  261. package/native/core/ScrollMomentum.cpp +71 -0
  262. package/native/core/ScrollMomentum.h +73 -0
  263. package/native/core/ScrollSnap.cpp +123 -0
  264. package/native/core/ScrollSnap.h +80 -0
  265. package/native/core/ShareFallback.cpp +101 -0
  266. package/native/core/ShareFallback.h +45 -0
  267. package/native/core/SkiaPictureViewComponent.cpp +11 -0
  268. package/native/core/SkiaPictureViewComponent.h +47 -0
  269. package/native/core/SourceCodeModule.cpp +55 -0
  270. package/native/core/SourceCodeModule.h +53 -0
  271. package/native/core/StatusBarModule.cpp +23 -0
  272. package/native/core/StatusBarModule.h +42 -0
  273. package/native/core/TestDialog.cpp +148 -0
  274. package/native/core/TestDialog.h +96 -0
  275. package/native/core/TestKeys.cpp +78 -0
  276. package/native/core/TestKeys.h +50 -0
  277. package/native/core/TestQuitFile.cpp +33 -0
  278. package/native/core/TestQuitFile.h +60 -0
  279. package/native/core/TestSettle.h +192 -0
  280. package/native/core/TitleBarRegions.h +31 -0
  281. package/native/core/TurboModuleProxy.cpp +51 -0
  282. package/native/core/TurboModuleProxy.h +46 -0
  283. package/native/core/UIManagerAccess.cpp +43 -0
  284. package/native/core/UIManagerAccess.h +43 -0
  285. package/native/core/WindowBoundsCache.cpp +319 -0
  286. package/native/core/WindowControl.h +235 -0
  287. package/native/core/WindowHost.h +158 -0
  288. package/native/core/WindowMethods.cpp +167 -0
  289. package/native/core/WindowMethods.h +84 -0
  290. package/native/core/WindowsModule.cpp +448 -0
  291. package/native/core/WindowsModule.h +133 -0
  292. package/native/core/WorkletsModule.cpp +199 -0
  293. package/native/core/WorkletsModule.h +57 -0
  294. package/native/core/portability_probe.cpp +210 -0
  295. package/native/tests/EventRecorder.h +124 -0
  296. package/native/tests/TestHarness.cpp +109 -0
  297. package/native/tests/TestHarness.h +89 -0
  298. package/native/tests/TreeDump.h +49 -0
  299. package/native/tests/test_app_identity.cpp +114 -0
  300. package/native/tests/test_app_paths.cpp +48 -0
  301. package/native/tests/test_appearance.cpp +107 -0
  302. package/native/tests/test_backface.cpp +79 -0
  303. package/native/tests/test_blobs.cpp +157 -0
  304. package/native/tests/test_controls.cpp +185 -0
  305. package/native/tests/test_devbundle.cpp +103 -0
  306. package/native/tests/test_drag_and_drop.cpp +143 -0
  307. package/native/tests/test_gestures.cpp +331 -0
  308. package/native/tests/test_hover.cpp +92 -0
  309. package/native/tests/test_image_cache.cpp +109 -0
  310. package/native/tests/test_js_runtime_access.cpp +137 -0
  311. package/native/tests/test_key_events.cpp +235 -0
  312. package/native/tests/test_momentum.cpp +138 -0
  313. package/native/tests/test_quit_file.cpp +104 -0
  314. package/native/tests/test_scroll_animation.cpp +120 -0
  315. package/native/tests/test_scroll_bounds.cpp +66 -0
  316. package/native/tests/test_scroll_indicator.cpp +149 -0
  317. package/native/tests/test_scroll_snap.cpp +112 -0
  318. package/native/tests/test_settle.cpp +115 -0
  319. package/native/tests/test_share.cpp +75 -0
  320. package/native/tests/test_sourcecode.cpp +62 -0
  321. package/native/tests/test_window_close.cpp +119 -0
  322. package/native/tests/test_window_limits.cpp +123 -0
  323. package/package.json +43 -0
  324. package/react-native.config.js +86 -0
  325. package/supported-versions.json +66 -0
@@ -0,0 +1,592 @@
1
+ #include "CoreModules.h"
2
+
3
+ #include "ShareFallback.h"
4
+ #include "TestDialog.h"
5
+
6
+ #include <react/bridging/Promise.h>
7
+
8
+ #include <glog/logging.h>
9
+
10
+ #include <mutex>
11
+
12
+ namespace basalt {
13
+
14
+ using facebook::jsi::Array;
15
+ using facebook::jsi::Function;
16
+ using facebook::jsi::Object;
17
+ using facebook::jsi::Runtime;
18
+ using facebook::jsi::String;
19
+ using facebook::jsi::Value;
20
+
21
+ namespace {
22
+
23
+ // A promise already settled. These answers are all in memory or one system call
24
+ // away, so there is nothing to wait for -- and going through JavaScript's own
25
+ // Promise.resolve needs no invoker and no thread hop.
26
+ Value resolved(Runtime &rt, Value &&value) {
27
+ auto promise = rt.global().getPropertyAsObject(rt, "Promise");
28
+ return promise.getPropertyAsFunction(rt, "resolve").callWithThis(rt, promise, value);
29
+ }
30
+
31
+ Value rejected(Runtime &rt, const std::string &message) {
32
+ auto promise = rt.global().getPropertyAsObject(rt, "Promise");
33
+ auto error = rt.global()
34
+ .getPropertyAsFunction(rt, "Error")
35
+ .callAsConstructor(rt, String::createFromUtf8(rt, message));
36
+ return promise.getPropertyAsFunction(rt, "reject").callWithThis(rt, promise, error);
37
+ }
38
+
39
+ std::string optionalString(Runtime &rt, const Object &object, const char *key) {
40
+ const Value value = object.getProperty(rt, key);
41
+ return value.isString() ? value.asString(rt).utf8(rt) : std::string{};
42
+ }
43
+
44
+ } // namespace
45
+
46
+ // ---------------------------------------------------------------------------
47
+ // Clipboard
48
+ // ---------------------------------------------------------------------------
49
+
50
+ Object DesktopClipboardModule::getConstants(Runtime &rt) {
51
+ return Object(rt);
52
+ }
53
+
54
+ Value DesktopClipboardModule::getString(Runtime &rt) {
55
+ return resolved(rt, Value(String::createFromUtf8(rt, clipboardText())));
56
+ }
57
+
58
+ void DesktopClipboardModule::setString(Runtime &rt, String content) {
59
+ setClipboardText(content.utf8(rt));
60
+ }
61
+
62
+ // ---------------------------------------------------------------------------
63
+ // Vibration
64
+ // ---------------------------------------------------------------------------
65
+
66
+ Object DesktopVibrationModule::getConstants(Runtime &rt) {
67
+ return Object(rt);
68
+ }
69
+
70
+ void DesktopVibrationModule::vibrate(Runtime &rt, double pattern) {
71
+ (void)rt;
72
+ (void)pattern;
73
+ }
74
+
75
+ void DesktopVibrationModule::vibrateByPattern(Runtime &rt, Array pattern, double repeat) {
76
+ (void)rt;
77
+ (void)pattern;
78
+ (void)repeat;
79
+ }
80
+
81
+ void DesktopVibrationModule::cancel(Runtime &rt) {
82
+ (void)rt;
83
+ }
84
+
85
+ // ---------------------------------------------------------------------------
86
+ // Alert
87
+ // ---------------------------------------------------------------------------
88
+
89
+ void DesktopAlertModule::alertWithArgs(Runtime &rt, Object args, Function callback) {
90
+ AlertRequest request;
91
+ request.title = optionalString(rt, args, "title");
92
+ request.message = optionalString(rt, args, "message");
93
+
94
+ // `buttons` is [{text}, ...] in the order Alert.alert was given them, and the
95
+ // callback reports an index into that same list.
96
+ const Value buttons = args.getProperty(rt, "buttons");
97
+ if (buttons.isObject() && buttons.asObject(rt).isArray(rt)) {
98
+ Array list = buttons.asObject(rt).asArray(rt);
99
+ const size_t count = list.size(rt);
100
+ for (size_t i = 0; i < count; i++) {
101
+ Object button = list.getValueAtIndex(rt, i).asObject(rt);
102
+ std::string text = optionalString(rt, button, "text");
103
+ if (text.empty()) {
104
+ text = "OK";
105
+ }
106
+ request.buttons.push_back(std::move(text));
107
+ }
108
+ }
109
+ if (request.buttons.empty()) {
110
+ // What Alert.alert() with no buttons means on every platform.
111
+ request.buttons.emplace_back("OK");
112
+ }
113
+
114
+ // `type` is 'default' | 'plain-text' | 'secure-text' | 'login-password'. Only
115
+ // a single text field is offered here: a login-password prompt is two fields
116
+ // and a layout, and answering it with one would silently lose the password.
117
+ const std::string type = optionalString(rt, args, "type");
118
+ if (type == "plain-text" || type == "secure-text") {
119
+ request.hasTextInput = true;
120
+ request.defaultText = optionalString(rt, args, "defaultValue");
121
+ request.placeholder = optionalString(rt, args, "keyboardType");
122
+ } else if (!type.empty() && type != "default") {
123
+ LOG(WARNING) << "Alert type '" << type << "' is not supported; showing a plain alert";
124
+ }
125
+
126
+ // The callback has to survive until a human presses something, and it belongs
127
+ // to the runtime. A shared_ptr captured by the platform's completion handler
128
+ // is what keeps it alive without keeping the runtime alive.
129
+ auto shared = std::make_shared<Function>(std::move(callback));
130
+ auto invoker = jsInvoker_;
131
+
132
+ presentAlert(request, [shared, invoker](int buttonIndex, const std::string &text) {
133
+ if (invoker == nullptr) {
134
+ return;
135
+ }
136
+ // Back onto the JavaScript thread: the platform calls this from its own
137
+ // main thread, and a jsi::Function may only be called on the runtime's.
138
+ invoker->invokeAsync([shared, buttonIndex, text](Runtime &rt) {
139
+ // `(id, value)`, which is what NativeAlertManager's own spec declares --
140
+ // two arguments, not three. The three-argument form belongs to Android's
141
+ // DialogManagerAndroid, which is a different module. This sent that one
142
+ // for three phases and nothing noticed, because `Alert.alert()` never
143
+ // reached the module at all: it branches on Platform.OS being exactly ios
144
+ // or android and returns having done nothing otherwise. See
145
+ // src/overrides/Alert.js.
146
+ shared->call(rt, Value(buttonIndex), String::createFromUtf8(rt, text));
147
+ });
148
+ });
149
+ }
150
+
151
+ // ---------------------------------------------------------------------------
152
+ // Linking
153
+ // ---------------------------------------------------------------------------
154
+
155
+ namespace {
156
+
157
+ // Written once by the host before the surface starts, read from the JavaScript
158
+ // thread afterwards. A process-wide string rather than something threaded
159
+ // through the module's constructor, because a TurboModule is built by a factory
160
+ // that takes only a CallInvoker.
161
+ std::string &initialUrlStorage() {
162
+ static std::string url;
163
+ return url;
164
+ }
165
+
166
+ } // namespace
167
+
168
+ void setInitialUrl(const std::string &url) {
169
+ initialUrlStorage() = url;
170
+ }
171
+
172
+ const std::string &initialUrl() {
173
+ return initialUrlStorage();
174
+ }
175
+
176
+ Value DesktopLinkingModule::getInitialURL(Runtime &rt) {
177
+ const std::string &url = initialUrl();
178
+ // Null rather than an empty string when there was none, which is what React
179
+ // Native's JavaScript checks for.
180
+ if (url.empty()) {
181
+ return resolved(rt, Value::null());
182
+ }
183
+ return resolved(rt, String::createFromUtf8(rt, url));
184
+ }
185
+
186
+ Value DesktopLinkingModule::canOpenURL(Runtime &rt, String url) {
187
+ return resolved(rt, Value(canOpenUrl(url.utf8(rt))));
188
+ }
189
+
190
+ Value DesktopLinkingModule::openURL(Runtime &rt, String url) {
191
+ const std::string target = url.utf8(rt);
192
+ if (!openUrl(target)) {
193
+ // Rejecting rather than resolving false: that is React Native's contract,
194
+ // and an app that awaits openURL expects a throw when it fails.
195
+ return rejected(rt, "Unable to open URL: " + target);
196
+ }
197
+ return resolved(rt, Value(true));
198
+ }
199
+
200
+ Value DesktopLinkingModule::openSettings(Runtime &rt) {
201
+ // There is no per-application settings page on a desktop to open.
202
+ return rejected(rt, "openSettings is not supported on this platform");
203
+ }
204
+
205
+ void DesktopLinkingModule::addListener(Runtime &rt, String eventName) {
206
+ (void)rt;
207
+ (void)eventName;
208
+ // Incoming URLs would arrive here. Nothing delivers them yet; see
209
+ // getInitialURL above.
210
+ }
211
+
212
+ void DesktopLinkingModule::removeListeners(Runtime &rt, double count) {
213
+ (void)rt;
214
+ (void)count;
215
+ }
216
+
217
+ // ---------------------------------------------------------------------------
218
+ // I18nManager
219
+ // ---------------------------------------------------------------------------
220
+
221
+ namespace {
222
+
223
+ struct I18nState {
224
+ std::mutex mutex;
225
+ bool allowRTL{false};
226
+ bool forceRTL{false};
227
+ bool swapLeftAndRight{true};
228
+ };
229
+
230
+ I18nState &i18n() {
231
+ static I18nState state;
232
+ return state;
233
+ }
234
+
235
+ } // namespace
236
+
237
+ Object DesktopI18nManagerModule::getConstants(Runtime &rt) {
238
+ I18nState &state = i18n();
239
+ const std::lock_guard<std::mutex> lock(state.mutex);
240
+
241
+ Object constants(rt);
242
+ // `isRTL` is what the layout actually is. Only `forceRTL` can make it true
243
+ // here: deciding it from the system locale would need a locale database this
244
+ // does not have, and guessing wrong flips an app's entire layout.
245
+ constants.setProperty(rt, "isRTL", state.forceRTL);
246
+ constants.setProperty(rt, "doLeftAndRightSwapInRTL", state.swapLeftAndRight);
247
+ // Empty rather than a guess. React Native's JavaScript treats it as opaque
248
+ // and only apps read it.
249
+ constants.setProperty(rt, "localeIdentifier", String::createFromUtf8(rt, ""));
250
+ return constants;
251
+ }
252
+
253
+ void DesktopI18nManagerModule::allowRTL(Runtime &rt, bool allow) {
254
+ (void)rt;
255
+ I18nState &state = i18n();
256
+ const std::lock_guard<std::mutex> lock(state.mutex);
257
+ state.allowRTL = allow;
258
+ }
259
+
260
+ void DesktopI18nManagerModule::forceRTL(Runtime &rt, bool force) {
261
+ (void)rt;
262
+ I18nState &state = i18n();
263
+ const std::lock_guard<std::mutex> lock(state.mutex);
264
+ state.forceRTL = force;
265
+ // Deliberately not restarting or relaying out. On iOS and Android this takes
266
+ // effect after a reload, and React Native's own documentation says so -- an
267
+ // app that flipped direction mid-session would be a surprise rather than a
268
+ // feature.
269
+ }
270
+
271
+ void DesktopI18nManagerModule::swapLeftAndRightInRTL(Runtime &rt, bool flipStyles) {
272
+ (void)rt;
273
+ I18nState &state = i18n();
274
+ const std::lock_guard<std::mutex> lock(state.mutex);
275
+ state.swapLeftAndRight = flipStyles;
276
+ }
277
+
278
+ // ---------------------------------------------------------------------------
279
+ // AccessibilityManager -- the iOS spelling, and the one that gets used
280
+ // ---------------------------------------------------------------------------
281
+
282
+ namespace {
283
+
284
+ // Every getter is (onSuccess, onError) and every answer here is false, for the
285
+ // reason given at the Android module below.
286
+ void answerState(Runtime &rt, Function &onSuccess, bool value) {
287
+ onSuccess.call(rt, Value(value));
288
+ }
289
+
290
+ } // namespace
291
+
292
+ void DesktopAccessibilityManagerModule::getCurrentBoldTextState(Runtime &rt,
293
+ Function onSuccess,
294
+ Function onError) {
295
+ (void)onError;
296
+ answerState(rt, onSuccess, false);
297
+ }
298
+
299
+ void DesktopAccessibilityManagerModule::getCurrentGrayscaleState(Runtime &rt,
300
+ Function onSuccess,
301
+ Function onError) {
302
+ (void)onError;
303
+ answerState(rt, onSuccess, false);
304
+ }
305
+
306
+ void DesktopAccessibilityManagerModule::getCurrentInvertColorsState(Runtime &rt,
307
+ Function onSuccess,
308
+ Function onError) {
309
+ (void)onError;
310
+ answerState(rt, onSuccess, false);
311
+ }
312
+
313
+ void DesktopAccessibilityManagerModule::getCurrentReduceMotionState(Runtime &rt,
314
+ Function onSuccess,
315
+ Function onError) {
316
+ (void)onError;
317
+ answerState(rt, onSuccess, false);
318
+ }
319
+
320
+ void DesktopAccessibilityManagerModule::getCurrentDarkerSystemColorsState(Runtime &rt,
321
+ Function onSuccess,
322
+ Function onError) {
323
+ (void)onError;
324
+ answerState(rt, onSuccess, false);
325
+ }
326
+
327
+ void DesktopAccessibilityManagerModule::getCurrentPrefersCrossFadeTransitionsState(
328
+ Runtime &rt,
329
+ Function onSuccess,
330
+ Function onError) {
331
+ (void)onError;
332
+ answerState(rt, onSuccess, false);
333
+ }
334
+
335
+ void DesktopAccessibilityManagerModule::getCurrentReduceTransparencyState(Runtime &rt,
336
+ Function onSuccess,
337
+ Function onError) {
338
+ (void)onError;
339
+ answerState(rt, onSuccess, false);
340
+ }
341
+
342
+ void DesktopAccessibilityManagerModule::getCurrentVoiceOverState(Runtime &rt,
343
+ Function onSuccess,
344
+ Function onError) {
345
+ (void)onError;
346
+ // Whether a screen reader is running. False rather than asking, for the same
347
+ // reason as the rest: saying yes wrongly makes React Native's own components
348
+ // announce things and alter focus order for a user who is not there.
349
+ answerState(rt, onSuccess, false);
350
+ }
351
+
352
+ void DesktopAccessibilityManagerModule::setAccessibilityContentSizeMultipliers(
353
+ Runtime &rt,
354
+ Object jsMultipliers) {
355
+ (void)rt;
356
+ (void)jsMultipliers;
357
+ // Dynamic Type's scale factors. Nothing here scales text for accessibility
358
+ // settings, which is also why the text layer passes fontSizeMultiplier as 1.
359
+ }
360
+
361
+ void DesktopAccessibilityManagerModule::setAccessibilityFocus(Runtime &rt, double reactTag) {
362
+ (void)rt;
363
+ (void)reactTag;
364
+ }
365
+
366
+ void DesktopAccessibilityManagerModule::announceForAccessibility(Runtime &rt,
367
+ String announcement) {
368
+ (void)rt;
369
+ (void)announcement;
370
+ }
371
+
372
+ void DesktopAccessibilityManagerModule::announceForAccessibilityWithOptions(Runtime &rt,
373
+ String announcement,
374
+ Object options) {
375
+ (void)rt;
376
+ (void)announcement;
377
+ (void)options;
378
+ }
379
+
380
+ // ---------------------------------------------------------------------------
381
+ // AccessibilityInfo -- the Android spelling
382
+ // ---------------------------------------------------------------------------
383
+
384
+ namespace {
385
+
386
+ void answer(Runtime &rt, Function &onSuccess, bool value) {
387
+ onSuccess.call(rt, Value(value));
388
+ }
389
+
390
+ } // namespace
391
+
392
+ // Every one of these is false, and each is false for a reason rather than as a
393
+ // placeholder.
394
+ //
395
+ // Neither desktop exposes "is a screen reader running" without asking the
396
+ // accessibility bus -- AT-SPI on Linux, and on macOS a check Apple has
397
+ // deprecated twice -- and answering *true* wrongly is worse than answering
398
+ // false: it makes React Native's own components change behaviour, announce
399
+ // things and alter focus order for a user who is not there.
400
+ void DesktopAccessibilityInfoModule::isReduceMotionEnabled(Runtime &rt, Function onSuccess) {
401
+ answer(rt, onSuccess, false);
402
+ }
403
+
404
+ void DesktopAccessibilityInfoModule::isInvertColorsEnabled(Runtime &rt, Function onSuccess) {
405
+ answer(rt, onSuccess, false);
406
+ }
407
+
408
+ void DesktopAccessibilityInfoModule::isHighTextContrastEnabled(Runtime &rt, Function onSuccess) {
409
+ answer(rt, onSuccess, false);
410
+ }
411
+
412
+ void DesktopAccessibilityInfoModule::isTouchExplorationEnabled(Runtime &rt, Function onSuccess) {
413
+ answer(rt, onSuccess, false);
414
+ }
415
+
416
+ void DesktopAccessibilityInfoModule::isAccessibilityServiceEnabled(Runtime &rt,
417
+ Function onSuccess) {
418
+ answer(rt, onSuccess, false);
419
+ }
420
+
421
+ void DesktopAccessibilityInfoModule::isGrayscaleEnabled(Runtime &rt, Function onSuccess) {
422
+ answer(rt, onSuccess, false);
423
+ }
424
+
425
+ void DesktopAccessibilityInfoModule::setAccessibilityFocus(Runtime &rt, double reactTag) {
426
+ (void)rt;
427
+ (void)reactTag;
428
+ // Moving a screen reader's cursor needs the platform's accessibility API to
429
+ // post a focus notification for a specific view, which neither mounting
430
+ // manager exposes by tag yet. See docs/BACKLOG.md.
431
+ }
432
+
433
+ void DesktopAccessibilityInfoModule::announceForAccessibility(Runtime &rt, String announcement) {
434
+ (void)rt;
435
+ (void)announcement;
436
+ // Same gap: an announcement is a notification posted to the accessibility
437
+ // bus, and nothing here has a handle on it.
438
+ }
439
+
440
+ void DesktopAccessibilityInfoModule::getRecommendedTimeoutMillis(Runtime &rt,
441
+ double mSec,
442
+ Function onSuccess) {
443
+ // The original timeout, unmodified. This exists so an app can be told to give
444
+ // a user longer; nothing here knows of a reason to.
445
+ onSuccess.call(rt, Value(mSec));
446
+ }
447
+
448
+ // ---------------------------------------------------------------------------
449
+ // ToastAndroid
450
+ // ---------------------------------------------------------------------------
451
+
452
+ Object DesktopToastModule::getConstants(Runtime &rt) {
453
+ Object constants(rt);
454
+ // The values React Native's JavaScript passes back in. They have to exist and
455
+ // be distinct; nothing here reads them.
456
+ constants.setProperty(rt, "SHORT", 0.0);
457
+ constants.setProperty(rt, "LONG", 1.0);
458
+ constants.setProperty(rt, "TOP", 48.0);
459
+ constants.setProperty(rt, "BOTTOM", 80.0);
460
+ constants.setProperty(rt, "CENTER", 17.0);
461
+ return constants;
462
+ }
463
+
464
+ void DesktopToastModule::show(Runtime &rt, String message, double duration) {
465
+ (void)duration;
466
+ LOG(INFO) << "toast: " << message.utf8(rt);
467
+ }
468
+
469
+ void DesktopToastModule::showWithGravity(Runtime &rt,
470
+ String message,
471
+ double duration,
472
+ double gravity) {
473
+ (void)duration;
474
+ (void)gravity;
475
+ LOG(INFO) << "toast: " << message.utf8(rt);
476
+ }
477
+
478
+ void DesktopToastModule::showWithGravityAndOffset(Runtime &rt,
479
+ String message,
480
+ double duration,
481
+ double gravity,
482
+ double xOffset,
483
+ double yOffset) {
484
+ (void)duration;
485
+ (void)gravity;
486
+ (void)xOffset;
487
+ (void)yOffset;
488
+ LOG(INFO) << "toast: " << message.utf8(rt);
489
+ }
490
+
491
+ // ---------------------------------------------------------------------------
492
+ // DevSettings, for release bundles only
493
+ // ---------------------------------------------------------------------------
494
+ //
495
+ // Every method here does nothing, and that is what these mean without a dev
496
+ // server: there is nothing to reload from, no inspector to toggle, no debugger
497
+ // to open, and no dev menu to add an item to. In dev mode the host does not
498
+ // offer this module at all and upstream's real one is used instead.
499
+
500
+ void DesktopDevSettingsModule::reload(Runtime &rt) {
501
+ (void)rt;
502
+ LOG(WARNING) << "DevSettings.reload() has nothing to reload from in a release bundle";
503
+ }
504
+
505
+ void DesktopDevSettingsModule::reloadWithReason(Runtime &rt, String reason) {
506
+ LOG(WARNING) << "DevSettings.reload() ignored (" << reason.utf8(rt) << ")";
507
+ }
508
+
509
+ void DesktopDevSettingsModule::onFastRefresh(Runtime &rt) {
510
+ (void)rt;
511
+ }
512
+
513
+ void DesktopDevSettingsModule::setHotLoadingEnabled(Runtime &rt, bool isHotLoadingEnabled) {
514
+ (void)rt;
515
+ (void)isHotLoadingEnabled;
516
+ }
517
+
518
+ void DesktopDevSettingsModule::setProfilingEnabled(Runtime &rt, bool isProfilingEnabled) {
519
+ (void)rt;
520
+ (void)isProfilingEnabled;
521
+ }
522
+
523
+ void DesktopDevSettingsModule::toggleElementInspector(Runtime &rt) {
524
+ (void)rt;
525
+ }
526
+
527
+ void DesktopDevSettingsModule::addMenuItem(Runtime &rt, String title) {
528
+ (void)rt;
529
+ (void)title;
530
+ }
531
+
532
+ void DesktopDevSettingsModule::openDebugger(Runtime &rt) {
533
+ (void)rt;
534
+ }
535
+
536
+ void DesktopDevSettingsModule::addListener(Runtime &rt, String eventName) {
537
+ (void)rt;
538
+ (void)eventName;
539
+ }
540
+
541
+ void DesktopDevSettingsModule::removeListeners(Runtime &rt, double count) {
542
+ (void)rt;
543
+ (void)count;
544
+ }
545
+
546
+ void DesktopDevSettingsModule::setIsShakeToShowDevMenuEnabled(Runtime &rt, bool enabled) {
547
+ (void)rt;
548
+ (void)enabled;
549
+ }
550
+
551
+ // ---------------------------------------------------------------------------
552
+ // Share
553
+ // ---------------------------------------------------------------------------
554
+
555
+ Object DesktopShareModule::getConstants(Runtime &rt) {
556
+ return Object(rt);
557
+ }
558
+
559
+ Value DesktopShareModule::share(Runtime &rt, Object content, std::optional<String> dialogTitle) {
560
+ ShareRequest request;
561
+ request.message = optionalString(rt, content, "message");
562
+ request.url = optionalString(rt, content, "url");
563
+ request.title = optionalString(rt, content, "title");
564
+ if (dialogTitle.has_value()) {
565
+ request.dialogTitle = dialogTitle->utf8(rt);
566
+ }
567
+
568
+ // Held by the callback, which is what keeps the promise alive until the
569
+ // picker is done with it.
570
+ auto promise = std::make_shared<facebook::react::AsyncPromise<folly::dynamic>>(rt, jsInvoker_);
571
+
572
+ shareContent(request, [promise](ShareOutcome outcome, const std::string &message) {
573
+ switch (outcome) {
574
+ case ShareOutcome::Shared:
575
+ // The shape Android's ShareModule resolves with. `activityType` is
576
+ // iOS's and React Native's JavaScript fills in null for it.
577
+ promise->resolve(folly::dynamic::object("action", "sharedAction"));
578
+ return;
579
+ case ShareOutcome::Dismissed:
580
+ promise->resolve(folly::dynamic::object("action", "dismissedAction"));
581
+ return;
582
+ case ShareOutcome::Failed:
583
+ promise->reject(facebook::react::Error(
584
+ message.empty() ? std::string("sharing failed") : message));
585
+ return;
586
+ }
587
+ });
588
+
589
+ return Value(rt, facebook::react::bridging::toJs(rt, *promise, jsInvoker_));
590
+ }
591
+
592
+ } // namespace basalt