@ng-native/desktop 0.26.0 → 0.27.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 (256) hide show
  1. package/README.md +6 -3
  2. package/bin/app-config.mjs +1 -0
  3. package/bin/archive.mjs +166 -0
  4. package/bin/autolink.mjs +61 -30
  5. package/bin/cli.mjs +127 -27
  6. package/bin/host.mjs +255 -58
  7. package/bin/package-linux.mjs +1394 -0
  8. package/bin/package.mjs +171 -35
  9. package/bin/plist.mjs +6 -2
  10. package/bin/png-icon.mjs +315 -0
  11. package/bin/prebuilt.mjs +147 -26
  12. package/bin/toolchain.mjs +258 -19
  13. package/native/CMakeLists.txt +64 -6
  14. package/native/appkit/CMakeLists.txt +2 -1
  15. package/native/appkit/appkit-backend.h +1 -0
  16. package/native/appkit/appkit-backend.mm +13 -0
  17. package/native/appkit/header-toolbar.mm +28 -25
  18. package/native/appkit/host-view.h +10 -0
  19. package/native/appkit/host-view.mm +146 -40
  20. package/native/appkit/input-replay.h +6 -0
  21. package/native/appkit/input-replay.mm +21 -12
  22. package/native/appkit/main.mm +11 -7
  23. package/native/appkit/native-controls.mm +13 -1
  24. package/native/appkit/split-view.mm +7 -13
  25. package/native/appkit/text-input-field.h +4 -0
  26. package/native/appkit/text-input-field.mm +20 -1
  27. package/native/cmake/curl.cmake +79 -0
  28. package/native/cmake/libraries/react-native-reanimated.cmake +5 -0
  29. package/native/cmake/libraries/react-native-worklets.cmake +5 -0
  30. package/native/cmake/linked-modules.cmake +20 -4
  31. package/native/cmake/react-native.cmake +18 -1
  32. package/native/core/include/ngn/accent-colors.h +38 -0
  33. package/native/core/include/ngn/accessibility-relations.h +65 -0
  34. package/native/core/include/ngn/accessibility.h +26 -0
  35. package/native/core/include/ngn/animated-frame-loop.h +56 -0
  36. package/native/core/include/ngn/app-info.h +24 -8
  37. package/native/core/include/ngn/app-menus.h +14 -1
  38. package/native/core/include/ngn/app-windows.h +15 -2
  39. package/native/core/include/ngn/aria-role.h +96 -0
  40. package/native/core/include/ngn/audio.h +2 -0
  41. package/native/core/include/ngn/camera.h +9 -0
  42. package/native/core/include/ngn/control-sizes.h +7 -2
  43. package/native/core/include/ngn/crash-report.h +31 -0
  44. package/native/core/include/ngn/curl-network.h +93 -0
  45. package/native/core/include/ngn/dbus-menu.h +39 -0
  46. package/native/core/include/ngn/default-menu.h +36 -0
  47. package/native/core/include/ngn/desktop-expo.h +7 -1
  48. package/native/core/include/ngn/desktop-modules.h +22 -0
  49. package/native/core/include/ngn/desktop-props.h +21 -1
  50. package/native/core/include/ngn/desktop-view-props.h +6 -0
  51. package/native/core/include/ngn/focus-order.h +10 -0
  52. package/native/core/include/ngn/header-bar.h +22 -0
  53. package/native/core/include/ngn/host-os.h +6 -0
  54. package/native/core/include/ngn/host-reload.h +21 -0
  55. package/native/core/include/ngn/host-state.h +23 -0
  56. package/native/core/include/ngn/image-source.h +26 -1
  57. package/native/core/include/ngn/input-script.h +3 -3
  58. package/native/core/include/ngn/input.h +4 -1
  59. package/native/core/include/ngn/launch-frame.h +21 -0
  60. package/native/core/include/ngn/launch-settings.h +23 -5
  61. package/native/core/include/ngn/mounting-backend.h +5 -0
  62. package/native/core/include/ngn/mounting-manager.h +1 -0
  63. package/native/core/include/ngn/native-controls.h +26 -5
  64. package/native/core/include/ngn/notification-schedule.h +74 -0
  65. package/native/core/include/ngn/notifications.h +2 -1
  66. package/native/core/include/ngn/openssl-update-crypto.h +15 -0
  67. package/native/core/include/ngn/photo-library.h +60 -20
  68. package/native/core/include/ngn/posix-locale.h +43 -0
  69. package/native/core/include/ngn/runtime.h +5 -0
  70. package/native/core/include/ngn/safe-areas.h +14 -2
  71. package/native/core/include/ngn/split-view.h +78 -0
  72. package/native/core/include/ngn/surface-metrics.h +7 -0
  73. package/native/core/include/ngn/system.h +14 -0
  74. package/native/core/include/ngn/text-input.h +13 -0
  75. package/native/core/include/ngn/text-units.h +38 -0
  76. package/native/core/include/ngn/updates.h +14 -2
  77. package/native/core/include/ngn/view-box.h +40 -0
  78. package/native/core/include/ngn/view-transform.h +15 -0
  79. package/native/core/include/ngn/web-browser.h +46 -0
  80. package/native/core/src/accent-colors.cpp +88 -0
  81. package/native/core/src/accessibility-relations.cpp +138 -0
  82. package/native/core/src/accessibility.cpp +50 -0
  83. package/native/core/src/animated-frame-loop.cpp +166 -0
  84. package/native/core/src/app-menus.cpp +26 -9
  85. package/native/core/src/app-windows.cpp +27 -6
  86. package/native/core/src/aria-role.cpp +127 -0
  87. package/native/core/src/control-sizes.cpp +9 -5
  88. package/native/core/src/crash-report.cpp +196 -0
  89. package/native/core/src/curl-network.cpp +1562 -0
  90. package/native/core/src/dbus-menu.cpp +71 -0
  91. package/native/core/src/default-menu.cpp +134 -0
  92. package/native/core/src/desktop-view-props.cpp +14 -0
  93. package/native/core/src/focus-order.cpp +19 -0
  94. package/native/core/src/header-bar.cpp +20 -0
  95. package/native/core/src/host-os.cpp +19 -0
  96. package/native/core/src/host-reload.cpp +45 -0
  97. package/native/core/src/host-state.cpp +8 -0
  98. package/native/core/src/image-source.cpp +90 -0
  99. package/native/core/src/input-dispatcher.cpp +27 -5
  100. package/native/core/src/input-script.cpp +3 -2
  101. package/native/core/src/launch-settings.cpp +76 -0
  102. package/native/core/src/libraries/react-native-reanimated.cpp +6 -1
  103. package/native/core/src/modules/app-info.cpp +55 -6
  104. package/native/core/src/modules/app-modules.cpp +1 -1
  105. package/native/core/src/modules/audio.cpp +4 -2
  106. package/native/core/src/modules/camera.cpp +8 -11
  107. package/native/core/src/modules/desktop-expo.cpp +10 -5
  108. package/native/core/src/modules/desktop-modules.cpp +106 -41
  109. package/native/core/src/modules/file-photo-picker.cpp +408 -0
  110. package/native/core/src/modules/notifications.cpp +13 -17
  111. package/native/core/src/modules/photo-library.cpp +42 -13
  112. package/native/core/src/modules/web-browser.cpp +89 -0
  113. package/native/core/src/mounting-manager.cpp +12 -0
  114. package/native/core/src/native-controls.cpp +42 -1
  115. package/native/core/src/notification-schedule.cpp +429 -0
  116. package/native/core/src/openssl-update-crypto.cpp +83 -0
  117. package/native/core/src/posix-locale.cpp +192 -0
  118. package/native/core/src/runtime.cpp +30 -1
  119. package/native/core/src/safe-areas.cpp +19 -4
  120. package/native/core/src/spawn-rules.cpp +4 -1
  121. package/native/core/src/split-view.cpp +93 -0
  122. package/native/core/src/system.cpp +19 -0
  123. package/native/core/src/text-input.cpp +18 -1
  124. package/native/core/src/text-units.cpp +99 -0
  125. package/native/core/src/updates.cpp +76 -17
  126. package/native/core/src/view-box.cpp +75 -40
  127. package/native/core/src/view-transform.cpp +28 -0
  128. package/native/docker/Dockerfile +38 -0
  129. package/native/docker/Dockerfile.fedora +36 -0
  130. package/native/docker/glibc-floor.sh +49 -0
  131. package/native/gtk/CMakeLists.txt +137 -0
  132. package/native/gtk/accent-colour.cpp +57 -0
  133. package/native/gtk/accent-colour.h +41 -0
  134. package/native/gtk/accessibility-settings.cpp +159 -0
  135. package/native/gtk/accessibility-settings.h +62 -0
  136. package/native/gtk/accessible-text.cpp +151 -0
  137. package/native/gtk/accessible-text.h +49 -0
  138. package/native/gtk/accessible.cpp +306 -0
  139. package/native/gtk/accessible.h +75 -0
  140. package/native/gtk/alerts.cpp +267 -0
  141. package/native/gtk/alerts.h +30 -0
  142. package/native/gtk/animation-frames.cpp +159 -0
  143. package/native/gtk/animation-frames.h +20 -0
  144. package/native/gtk/app-info.cpp +91 -0
  145. package/native/gtk/app-info.h +25 -0
  146. package/native/gtk/app-windows.cpp +439 -0
  147. package/native/gtk/app-windows.h +150 -0
  148. package/native/gtk/audio.cpp +370 -0
  149. package/native/gtk/audio.h +54 -0
  150. package/native/gtk/auth-session.cpp +73 -0
  151. package/native/gtk/auth-session.h +16 -0
  152. package/native/gtk/battery.cpp +110 -0
  153. package/native/gtk/battery.h +19 -0
  154. package/native/gtk/box-paint.cpp +262 -0
  155. package/native/gtk/box-paint.h +32 -0
  156. package/native/gtk/cairo-canvas.cpp +755 -0
  157. package/native/gtk/cairo-canvas.h +49 -0
  158. package/native/gtk/camera.cpp +909 -0
  159. package/native/gtk/camera.h +69 -0
  160. package/native/gtk/capture.cpp +46 -0
  161. package/native/gtk/capture.h +19 -0
  162. package/native/gtk/clock-format.cpp +151 -0
  163. package/native/gtk/clock-format.h +36 -0
  164. package/native/gtk/crypto.cpp +75 -0
  165. package/native/gtk/crypto.h +14 -0
  166. package/native/gtk/dbus-properties.cpp +131 -0
  167. package/native/gtk/dbus-properties.h +61 -0
  168. package/native/gtk/drag-and-drop.cpp +339 -0
  169. package/native/gtk/drag-and-drop.h +30 -0
  170. package/native/gtk/file-dialogs.cpp +239 -0
  171. package/native/gtk/file-dialogs.h +21 -0
  172. package/native/gtk/file-system.cpp +212 -0
  173. package/native/gtk/file-system.h +25 -0
  174. package/native/gtk/focus.cpp +282 -0
  175. package/native/gtk/focus.h +37 -0
  176. package/native/gtk/fonts.cpp +89 -0
  177. package/native/gtk/fonts.h +22 -0
  178. package/native/gtk/gst-frames.cpp +150 -0
  179. package/native/gtk/gst-frames.h +47 -0
  180. package/native/gtk/gst-playback.cpp +496 -0
  181. package/native/gtk/gst-playback.h +81 -0
  182. package/native/gtk/gtk-backend.cpp +690 -0
  183. package/native/gtk/gtk-backend.h +134 -0
  184. package/native/gtk/host-sources.cpp +354 -0
  185. package/native/gtk/host-sources.h +46 -0
  186. package/native/gtk/image-manipulator.cpp +254 -0
  187. package/native/gtk/image-manipulator.h +30 -0
  188. package/native/gtk/image-view.cpp +256 -0
  189. package/native/gtk/image-view.h +54 -0
  190. package/native/gtk/input-replay.cpp +299 -0
  191. package/native/gtk/input-replay.h +36 -0
  192. package/native/gtk/launcher-badge.cpp +29 -0
  193. package/native/gtk/launcher-badge.h +21 -0
  194. package/native/gtk/locales.cpp +131 -0
  195. package/native/gtk/locales.h +23 -0
  196. package/native/gtk/location.cpp +274 -0
  197. package/native/gtk/location.h +19 -0
  198. package/native/gtk/main.cpp +1092 -0
  199. package/native/gtk/menus.cpp +447 -0
  200. package/native/gtk/menus.h +100 -0
  201. package/native/gtk/native-controls.cpp +831 -0
  202. package/native/gtk/native-controls.h +58 -0
  203. package/native/gtk/network-state.cpp +72 -0
  204. package/native/gtk/network-state.h +24 -0
  205. package/native/gtk/notifications.cpp +235 -0
  206. package/native/gtk/notifications.h +30 -0
  207. package/native/gtk/pango-text.cpp +274 -0
  208. package/native/gtk/pango-text.h +73 -0
  209. package/native/gtk/portal.cpp +451 -0
  210. package/native/gtk/portal.h +71 -0
  211. package/native/gtk/printing.cpp +338 -0
  212. package/native/gtk/printing.h +34 -0
  213. package/native/gtk/proxy-resolver.cpp +74 -0
  214. package/native/gtk/proxy-resolver.h +20 -0
  215. package/native/gtk/screens.cpp +1461 -0
  216. package/native/gtk/screens.h +274 -0
  217. package/native/gtk/scroll-view.cpp +414 -0
  218. package/native/gtk/scroll-view.h +82 -0
  219. package/native/gtk/secret-store.cpp +120 -0
  220. package/native/gtk/secret-store.h +27 -0
  221. package/native/gtk/settings-portal.cpp +129 -0
  222. package/native/gtk/settings-portal.h +47 -0
  223. package/native/gtk/split-view.cpp +1105 -0
  224. package/native/gtk/split-view.h +195 -0
  225. package/native/gtk/status-notifier.cpp +487 -0
  226. package/native/gtk/status-notifier.h +43 -0
  227. package/native/gtk/surface-input.cpp +251 -0
  228. package/native/gtk/surface-input.h +57 -0
  229. package/native/gtk/system-access.cpp +295 -0
  230. package/native/gtk/system-access.h +37 -0
  231. package/native/gtk/text-field.cpp +827 -0
  232. package/native/gtk/text-field.h +78 -0
  233. package/native/gtk/video.cpp +527 -0
  234. package/native/gtk/video.h +47 -0
  235. package/native/gtk/view-widget.cpp +431 -0
  236. package/native/gtk/view-widget.h +105 -0
  237. package/native/gtk/window-scale.cpp +95 -0
  238. package/native/gtk/window-scale.h +35 -0
  239. package/native/scripts/atspi-check.py +310 -0
  240. package/native/scripts/atspi-check.test.py +48 -0
  241. package/native/scripts/build.sh +20 -3
  242. package/native/scripts/compilers.sh +17 -0
  243. package/native/scripts/deb-depends-check.sh +22 -0
  244. package/native/scripts/fetch.sh +23 -2
  245. package/native/scripts/launch-cell.sh +157 -0
  246. package/native/scripts/launch-probe.sh +14 -3
  247. package/native/scripts/make-prebuilt.mjs +133 -44
  248. package/native/scripts/prebuilt-host-cache.mjs +71 -40
  249. package/native/scripts/reset-for-compilers.sh +44 -0
  250. package/native/scripts/start-xvfb.sh +35 -0
  251. package/native/shim/paragraph-platform/react/renderer/components/text/HostPlatformParagraphProps.h +35 -0
  252. package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +5 -2
  253. package/native/shim/worklets/linux-reanimated-props.h +14 -0
  254. package/native/shim/worklets/linux-worklets.h +23 -0
  255. package/package.json +6 -3
  256. package/prebuilt.json +70 -6
@@ -0,0 +1,192 @@
1
+ #include "ngn/posix-locale.h"
2
+
3
+ #include <algorithm>
4
+ #include <cctype>
5
+ #include <set>
6
+
7
+ namespace ngn {
8
+
9
+ namespace {
10
+
11
+ std::string lower(std::string text) {
12
+ for (auto &c : text) {
13
+ c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
14
+ }
15
+ return text;
16
+ }
17
+
18
+ std::string upper(std::string text) {
19
+ for (auto &c : text) {
20
+ c = static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
21
+ }
22
+ return text;
23
+ }
24
+
25
+ struct LocaleName {
26
+ std::string language;
27
+ std::string region;
28
+ std::string modifier;
29
+ };
30
+
31
+ // "ll_CC.codeset@modifier", each part after the language optional.
32
+ LocaleName partsOf(const std::string &name) {
33
+ LocaleName parts;
34
+ auto at = name.find('@');
35
+ if (at != std::string::npos) {
36
+ parts.modifier = name.substr(at + 1);
37
+ }
38
+ std::string base = name.substr(0, std::min(at, name.find('.')));
39
+ auto underscore = base.find('_');
40
+ parts.language = base.substr(0, underscore);
41
+ if (underscore != std::string::npos) {
42
+ parts.region = base.substr(underscore + 1);
43
+ }
44
+ return parts;
45
+ }
46
+
47
+ // The day of the week of a yyyymmdd date, 0 for Sunday (Sakamoto's method).
48
+ int weekdayOf(unsigned date) {
49
+ int year = static_cast<int>(date / 10000), month = static_cast<int>(date / 100 % 100), day = static_cast<int>(date % 100);
50
+ static const int offsets[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
51
+ if (month < 1 || month > 12) {
52
+ return 0;
53
+ }
54
+ if (month < 3) {
55
+ year -= 1;
56
+ }
57
+ return (year + year / 4 - year / 100 + year / 400 + offsets[month - 1] + day) % 7;
58
+ }
59
+
60
+ } // namespace
61
+
62
+ std::optional<std::string> languageTagOf(const std::string &posixLocale) {
63
+ auto parts = partsOf(posixLocale);
64
+ if (parts.language.empty() || parts.language == "C" || parts.language == "POSIX" ||
65
+ !std::all_of(parts.language.begin(), parts.language.end(), [](char c) { return std::isalpha(static_cast<unsigned char>(c)); })) {
66
+ return std::nullopt;
67
+ }
68
+ std::string tag = lower(parts.language);
69
+ // The modifiers that name a script, and the one variant glibc's locales use; others (@euro) say
70
+ // nothing a tag carries.
71
+ auto modifier = lower(parts.modifier);
72
+ if (modifier == "latin") {
73
+ tag += "-Latn";
74
+ } else if (modifier == "cyrillic") {
75
+ tag += "-Cyrl";
76
+ } else if (modifier == "devanagari") {
77
+ tag += "-Deva";
78
+ }
79
+ if (!parts.region.empty()) {
80
+ tag += "-" + upper(parts.region);
81
+ }
82
+ if (modifier == "valencia") {
83
+ tag += "-valencia";
84
+ }
85
+ return tag;
86
+ }
87
+
88
+ std::vector<std::string> preferredLanguageTags(const std::string &languageList, const std::string &messagesLocale) {
89
+ std::vector<std::string> tags;
90
+ std::set<std::string> seen;
91
+ auto add = [&](const std::string &name) {
92
+ if (auto tag = languageTagOf(name); tag && seen.insert(*tag).second) {
93
+ tags.push_back(*tag);
94
+ }
95
+ };
96
+ if (languageTagOf(messagesLocale)) {
97
+ size_t start = 0;
98
+ while (start <= languageList.size()) {
99
+ auto colon = languageList.find(':', start);
100
+ auto name = languageList.substr(start, colon == std::string::npos ? std::string::npos : colon - start);
101
+ // gettext stops at C or POSIX: what follows is never a preference, and neither is the
102
+ // messages locale after it.
103
+ auto language = partsOf(name).language;
104
+ if (language == "C" || language == "POSIX") {
105
+ return tags;
106
+ }
107
+ add(name);
108
+ if (colon == std::string::npos) {
109
+ break;
110
+ }
111
+ start = colon + 1;
112
+ }
113
+ }
114
+ add(messagesLocale);
115
+ return tags;
116
+ }
117
+
118
+ std::string regionOfLocale(const std::string &posixLocale) {
119
+ auto region = partsOf(posixLocale).region;
120
+ return languageTagOf(posixLocale) ? upper(region) : "";
121
+ }
122
+
123
+ bool rightToLeftLanguage(const std::string &tag) {
124
+ static const std::set<std::string> languages{"ar", "arc", "ckb", "dv", "fa", "he", "iw", "ks", "ku", "ps", "sd", "syr", "ug", "ur", "yi"};
125
+ static const std::set<std::string> rightToLeftScripts{"Arab", "Hebr", "Syrc", "Thaa", "Adlm", "Nkoo", "Rohg", "Mand", "Samr"};
126
+ std::vector<std::string> subtags;
127
+ size_t start = 0;
128
+ while (start <= tag.size()) {
129
+ auto end = tag.find_first_of("-_", start);
130
+ subtags.push_back(tag.substr(start, end == std::string::npos ? std::string::npos : end - start));
131
+ if (end == std::string::npos) {
132
+ break;
133
+ }
134
+ start = end + 1;
135
+ }
136
+ std::string language = lower(subtags[0]);
137
+ // An explicit script decides: ku-Latn-TR runs left to right, pa-Arab right to left.
138
+ for (size_t i = 1; i < subtags.size(); ++i) {
139
+ const auto &subtag = subtags[i];
140
+ if (subtag.size() == 4 && std::all_of(subtag.begin(), subtag.end(), [](char c) { return std::isalpha(static_cast<unsigned char>(c)); })) {
141
+ return rightToLeftScripts.count(std::string(1, static_cast<char>(std::toupper(static_cast<unsigned char>(subtag[0])))) + lower(subtag.substr(1))) > 0;
142
+ }
143
+ }
144
+ // The script a region writes its language in, where it is not the language's usual one: glibc's
145
+ // ku_TR is Latin and pa_PK is Arabic (Shahmukhi).
146
+ std::string region = subtags.size() > 1 ? upper(subtags[1]) : "";
147
+ if (language == "ku" && region == "TR") {
148
+ return false;
149
+ }
150
+ if (language == "pa" && region == "PK") {
151
+ return true;
152
+ }
153
+ return languages.count(language) > 0;
154
+ }
155
+
156
+ int firstWeekdayOf(unsigned weekFirstDay, int firstWeekday) {
157
+ int base = weekdayOf(weekFirstDay);
158
+ int day = std::clamp(firstWeekday, 1, 7);
159
+ return (base + day - 1) % 7 + 1;
160
+ }
161
+
162
+ bool uses24HourClockIn(const std::string &timeFormat) {
163
+ // %I and %r are the 12-hour clock's, %l a glibc extension of it; %H, %k, %R and %T the 24-hour.
164
+ for (size_t i = 0; i + 1 < timeFormat.size(); ++i) {
165
+ if (timeFormat[i] != '%') {
166
+ continue;
167
+ }
168
+ char c = timeFormat[++i];
169
+ // A flag or width (%-I, %_H) before the conversion.
170
+ while ((c == '-' || c == '_' || c == '0' || c == '^' || c == '#' || c == 'E' || c == 'O') && i + 1 < timeFormat.size()) {
171
+ c = timeFormat[++i];
172
+ }
173
+ if (c == 'I' || c == 'r' || c == 'l' || c == 'p' || c == 'P') {
174
+ return false;
175
+ }
176
+ }
177
+ return true;
178
+ }
179
+
180
+ std::string measurementSystemOf(int measurement, const std::string &region) {
181
+ if (measurement == 2) {
182
+ return "U.S.";
183
+ }
184
+ return region == "GB" ? "U.K." : "Metric";
185
+ }
186
+
187
+ std::string temperatureUnitOf(const std::string &region) {
188
+ static const std::set<std::string> fahrenheit{"BS", "BZ", "KY", "PR", "PW", "US"};
189
+ return fahrenheit.count(region) > 0 ? "fahrenheit" : "celsius";
190
+ }
191
+
192
+ } // namespace ngn
@@ -1,5 +1,7 @@
1
1
  #include "ngn/runtime.h"
2
2
 
3
+ #include "ngn/animated-frame-loop.h"
4
+ #include "ngn/host-reload.h"
3
5
  #include "ngn/worklet-host.h"
4
6
  #include "red-box-errors.h"
5
7
 
@@ -34,6 +36,13 @@ class FeatureFlags final : public ReactNativeFeatureFlagsDefaults {
34
36
  bool enableBridgelessArchitecture() override {
35
37
  return true;
36
38
  }
39
+ // The animated module is React Native's C++ one (createHost), which keeps the shadow tree in step
40
+ // with what it animates. The flag also names the module JavaScript asks for: without it, a bundle
41
+ // that resolves React Native's iOS files asks for iOS's NativeAnimatedTurboModule, finds none, and
42
+ // every animation runs from JavaScript.
43
+ bool cxxNativeAnimatedEnabled() override {
44
+ return true;
45
+ }
37
46
  };
38
47
 
39
48
  // React Native's dev UI as the host has it: the debugger's pause, handed to the runtime's owner.
@@ -143,6 +152,8 @@ void Runtime::createHost() {
143
152
  config.devServerPort = devServer_->port;
144
153
  }
145
154
 
155
+ // Its own, for this instance: the last one's was closed with its host.
156
+ animatedFrames_ = std::make_shared<AnimatedFrameLoop>(workletHost().frames);
146
157
  host_ = std::make_unique<ReactHost>(
147
158
  config,
148
159
  mounting_,
@@ -153,14 +164,28 @@ void Runtime::createHost() {
153
164
  std::make_shared<DevUI>(onDebuggerPaused, onDebuggerResumed),
154
165
  modules_->providers(),
155
166
  nullptr,
156
- nullptr,
167
+ // React Native's animated module, on the host's frames: Animated's native driver, and the
168
+ // engine's native paint and the animations it hands native, play without a commit a frame.
169
+ animatedNodesManagerProvider(animatedFrames_),
157
170
  devServer_ ? ReactInstance::BindingsInstallFunc([this](jsi::Runtime &runtime) { installErrorListener(runtime); })
158
171
  : nullptr);
172
+ // React Native's own reloads (DevSettings, the dev server's, the debugger's) come here instead
173
+ // (host-reload.h).
174
+ routeHostReload(host_.get(), [this] { reload(); });
159
175
  // Reanimated reaches the UIManager through here as it installs (worklet-host.h).
160
176
  auto *host = host_.get();
161
177
  workletHost().runOnScheduler.set([host](std::function<void(Scheduler &)> task) { host->runOnScheduler(std::move(task)); });
162
178
  }
163
179
 
180
+ // Before the host goes, on the thread that destroys it: React Native's animated manager renders on
181
+ // the UI thread through the loop, and a render in flight must return before the manager is gone.
182
+ // Not left to the manager's destructor, whose stop does nothing where a render stopped itself.
183
+ void Runtime::closeAnimatedFrames() {
184
+ if (animatedFrames_) {
185
+ animatedFrames_->close();
186
+ }
187
+ }
188
+
164
189
  Runtime::~Runtime() {
165
190
  shutdown();
166
191
  *alive_ = false;
@@ -337,6 +362,8 @@ void Runtime::reload(std::function<void(bool)> done) {
337
362
  if (host_) {
338
363
  host_->stopAllSurfaces();
339
364
  workletHost().runOnScheduler.set(nullptr);
365
+ routeHostReload(host_.get(), nullptr);
366
+ closeAnimatedFrames();
340
367
  host_.reset();
341
368
  createHost();
342
369
  direction_.instanceStarted();
@@ -415,6 +442,8 @@ void Runtime::shutdown() {
415
442
  if (host_) {
416
443
  workletHost().runOnScheduler.set(nullptr);
417
444
  host_->stopAllSurfaces();
445
+ routeHostReload(host_.get(), nullptr);
446
+ closeAnimatedFrames();
418
447
  host_.reset();
419
448
  }
420
449
  }
@@ -24,6 +24,13 @@ double titlebarLeading(double minX, double maxX, double width, bool rightToLeft)
24
24
  return rightToLeft ? width - minX : maxX;
25
25
  }
26
26
 
27
+ double titlebarTrailing(double minX, double maxX, double width, bool rightToLeft) {
28
+ if (maxX <= 0 || minX >= width) {
29
+ return 0;
30
+ }
31
+ return rightToLeft ? maxX : width - minX;
32
+ }
33
+
27
34
  void SafeAreas::created(const ShadowView &view) {
28
35
  std::string_view name = view.componentName;
29
36
  if (name == "RNCSafeAreaProvider") {
@@ -78,7 +85,9 @@ bool SafeAreas::settle(const ViewTree &tree) {
78
85
  }
79
86
  auto insets = insetsWithin(*container, unmoved);
80
87
  bool changed = !tracked.known || insets != tracked.insets ||
81
- (tracked.kind == Kind::Provider && (frame != tracked.frame || container->titlebarLeading != tracked.titlebarLeading));
88
+ (tracked.kind == Kind::Provider &&
89
+ (frame != tracked.frame || container->titlebarLeading != tracked.titlebarLeading ||
90
+ container->titlebarTrailing != tracked.titlebarTrailing));
82
91
  if (!changed) {
83
92
  continue;
84
93
  }
@@ -87,8 +96,9 @@ bool SafeAreas::settle(const ViewTree &tree) {
87
96
  tracked.insets = insets;
88
97
  tracked.frame = frame;
89
98
  tracked.titlebarLeading = container->titlebarLeading;
99
+ tracked.titlebarTrailing = container->titlebarTrailing;
90
100
  if (tracked.kind == Kind::Provider) {
91
- emitInsetsChange(*node, insets, frame, container->titlebarLeading);
101
+ emitInsetsChange(*node, insets, frame, container->titlebarLeading, container->titlebarTrailing);
92
102
  } else {
93
103
  setStateInsets(*node, insets);
94
104
  }
@@ -96,7 +106,12 @@ bool SafeAreas::settle(const ViewTree &tree) {
96
106
  return told;
97
107
  }
98
108
 
99
- void SafeAreas::emitInsetsChange(const ViewTree::Node &provider, EdgeInsets insets, Rect frame, double titlebarLeading) {
109
+ void SafeAreas::emitInsetsChange(
110
+ const ViewTree::Node &provider,
111
+ EdgeInsets insets,
112
+ Rect frame,
113
+ double titlebarLeading,
114
+ double titlebarTrailing) {
100
115
  if (!provider.view.eventEmitter) {
101
116
  return;
102
117
  }
@@ -107,7 +122,7 @@ void SafeAreas::emitInsetsChange(const ViewTree::Node &provider, EdgeInsets inse
107
122
  folly::dynamic::object("top", insets.top)("right", insets.right)("bottom", insets.bottom)("left", insets.left))(
108
123
  "frame",
109
124
  folly::dynamic::object("x", frame.origin.x)("y", frame.origin.y)("width", frame.size.width)(
110
- "height", frame.size.height))("titlebarLeading", titlebarLeading));
125
+ "height", frame.size.height))("titlebarLeading", titlebarLeading)("titlebarTrailing", titlebarTrailing));
111
126
  }
112
127
 
113
128
  void SafeAreas::setStateInsets(const ViewTree::Node &view, EdgeInsets insets) {
@@ -11,7 +11,10 @@ namespace {
11
11
  const std::set<std::string> kRefusedPrograms{
12
12
  "sh", "bash", "zsh", "dash", "ksh", "mksh", "csh", "tcsh", "fish", "nu",
13
13
  "env", "xargs", "sudo", "doas", "su", "osascript", "cmd", "powershell", "pwsh",
14
- "nice", "nohup"};
14
+ "nice", "nohup",
15
+ // Linux's: escalation (pkexec), a shell of its own (busybox), and leaving a Flatpak sandbox,
16
+ // the session or the mount namespace (flatpak-spawn --host, systemd-run, nsenter, chroot).
17
+ "pkexec", "busybox", "flatpak-spawn", "systemd-run", "nsenter", "chroot"};
15
18
 
16
19
  std::string lower(std::string s) {
17
20
  std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
@@ -325,6 +325,99 @@ bool SidebarCollapse::toolkitChanged(bool collapsed) {
325
325
  return collapsed != prop_;
326
326
  }
327
327
 
328
+ std::optional<std::string> sidebarCollapsedKey(const std::string &autosaveName) {
329
+ if (autosaveName.empty()) {
330
+ return std::nullopt;
331
+ }
332
+ return "NgNativeSidebarCollapsed " + autosaveName;
333
+ }
334
+
335
+ std::optional<bool> savedSidebarCollapsed(const std::optional<folly::dynamic> &value) {
336
+ if (!value || !value->isBool()) {
337
+ return std::nullopt;
338
+ }
339
+ return value->asBool();
340
+ }
341
+
342
+ Float sidebarCompactWidth(const SidebarWidths &widths) {
343
+ return widths.minimum + kSplitContentMinWidth;
344
+ }
345
+
346
+ FoldingSplit::Showing FoldingSplit::showing() const {
347
+ if (compact_) {
348
+ return {.stacked = true, .content = !sidebarInFront_};
349
+ }
350
+ return {.stacked = collapsed_, .content = true};
351
+ }
352
+
353
+ void FoldingSplit::setCompact(bool compact) {
354
+ if (compact != compact_) {
355
+ compact_ = compact;
356
+ sidebarInFront_ = false;
357
+ }
358
+ }
359
+
360
+ void FoldingSplit::setCollapsed(bool collapsed) {
361
+ collapsed_ = collapsed;
362
+ }
363
+
364
+ void FoldingSplit::chose() {
365
+ sidebarInFront_ = false;
366
+ }
367
+
368
+ std::optional<bool> FoldingSplit::toggle() {
369
+ if (compact_) {
370
+ sidebarInFront_ = !sidebarInFront_;
371
+ return std::nullopt;
372
+ }
373
+ collapsed_ = !collapsed_;
374
+ return collapsed_;
375
+ }
376
+
377
+ void SourceListFolds::setList(const SourceList &list) {
378
+ std::unordered_set<Tag> live;
379
+ for (const auto &group : list.groups) {
380
+ live.insert(group.tag);
381
+ }
382
+ std::erase_if(folded_, [&live](Tag tag) { return !live.contains(tag); });
383
+ }
384
+
385
+ void SourceListFolds::fold(Tag section, bool folded) {
386
+ if (folded) {
387
+ folded_.insert(section);
388
+ } else {
389
+ folded_.erase(section);
390
+ }
391
+ }
392
+
393
+ bool SourceListFolds::folded(Tag section) const {
394
+ return folded_.contains(section);
395
+ }
396
+
397
+ std::optional<Tag> selectedRow(const SourceList &list) {
398
+ std::optional<Tag> selected;
399
+ for (const auto &group : list.groups) {
400
+ for (const auto &row : group.rows) {
401
+ if (row.selected) {
402
+ selected = row.tag;
403
+ }
404
+ }
405
+ }
406
+ return selected;
407
+ }
408
+
409
+ bool onlySelectionDiffers(const SourceList &a, const SourceList &b) {
410
+ auto unselected = [](SourceList list) {
411
+ for (auto &group : list.groups) {
412
+ for (auto &row : group.rows) {
413
+ row.selected = false;
414
+ }
415
+ }
416
+ return list;
417
+ };
418
+ return a != b && unselected(a) == unselected(b);
419
+ }
420
+
328
421
  bool FrameSizes::report(Tag tag, Size size) {
329
422
  bool first = pending_.empty();
330
423
  pending_[tag] = size;
@@ -4,6 +4,25 @@
4
4
 
5
5
  namespace ngn {
6
6
 
7
+ AlertLayout gnomeAlertLayout(const AlertRequest &request) {
8
+ AlertLayout layout;
9
+ int count = static_cast<int>(request.buttons.size());
10
+ bool cancel = request.cancelIndex >= 0 && request.cancelIndex < count;
11
+ if (cancel) {
12
+ layout.order.push_back(request.cancelIndex);
13
+ layout.escapeIndex = request.cancelIndex;
14
+ }
15
+ for (int i = count - 1; i >= 0; i--) {
16
+ if (!cancel || i != request.cancelIndex) {
17
+ layout.order.push_back(i);
18
+ }
19
+ }
20
+ if (count > 0 && request.buttons[0].role != AlertButtonRole::Destructive && (!cancel || request.cancelIndex != 0)) {
21
+ layout.returnIndex = 0;
22
+ }
23
+ return layout;
24
+ }
25
+
7
26
  ColorSchemeOverride::ColorSchemeOverride(std::string systemScheme) : system_(std::move(systemScheme)) {}
8
27
 
9
28
  std::string ColorSchemeOverride::current() const {
@@ -1,4 +1,5 @@
1
1
  #include "ngn/text-input.h"
2
+ #include "ngn/desktop-view-props.h"
2
3
 
3
4
  #include <react/renderer/components/iostextinput/conversions.h>
4
5
  #include <react/renderer/components/iostextinput/propsConversions.h>
@@ -20,7 +21,10 @@ DesktopTextInputProps::DesktopTextInputProps(
20
21
  : BaseTextInputProps(context, sourceProps, rawProps),
21
22
  traits(convertRawProp(context, rawProps, sourceProps.traits, {})),
22
23
  selection(convertRawProp(context, rawProps, "selection", sourceProps.selection, std::optional<Selection>())),
23
- smartQuotes(convertRawProp(context, rawProps, "smartQuotes", sourceProps.smartQuotes, std::optional<bool>())) {}
24
+ smartQuotes(convertRawProp(context, rawProps, "smartQuotes", sourceProps.smartQuotes, std::optional<bool>())),
25
+ accessibilityDescribedBy(convertRawProp(
26
+ context, rawProps, "accessibilityDescribedBy", sourceProps.accessibilityDescribedBy, {})),
27
+ aria(parseAriaFields(context, sourceProps.aria, rawProps)) {}
24
28
 
25
29
  namespace {
26
30
 
@@ -136,4 +140,17 @@ bool controlledTextIsCurrent(int mostRecentEventCount, int fieldEventCount, bool
136
140
  return mostRecentEventCount >= fieldEventCount && !composing;
137
141
  }
138
142
 
143
+ std::optional<std::pair<int, int>> newSelection(const DesktopTextInputProps *before, const DesktopTextInputProps &now) {
144
+ if (!now.selection) {
145
+ return std::nullopt;
146
+ }
147
+ if (before && before->selection && before->selection->start == now.selection->start &&
148
+ before->selection->end == now.selection->end) {
149
+ return std::nullopt;
150
+ }
151
+ int start = std::max(0, std::min(now.selection->start, now.selection->end));
152
+ int end = std::max(0, std::max(now.selection->start, now.selection->end));
153
+ return std::make_pair(start, end);
154
+ }
155
+
139
156
  } // namespace ngn
@@ -0,0 +1,99 @@
1
+ #include "ngn/text-units.h"
2
+
3
+ #include <algorithm>
4
+
5
+ namespace ngn {
6
+
7
+ namespace {
8
+
9
+ bool continuation(char byte) {
10
+ return (static_cast<unsigned char>(byte) & 0xC0) == 0x80;
11
+ }
12
+
13
+ // The byte where character `index` starts, or the text's size past its end.
14
+ size_t byteOf(const std::string &text, int index) {
15
+ size_t byte = 0;
16
+ for (int i = 0; i < index && byte < text.size(); i++) {
17
+ byte++;
18
+ while (byte < text.size() && continuation(text[byte])) {
19
+ byte++;
20
+ }
21
+ }
22
+ return byte;
23
+ }
24
+
25
+ int characters(const std::string &text) {
26
+ return static_cast<int>(std::count_if(text.begin(), text.end(), [](char c) { return !continuation(c); }));
27
+ }
28
+
29
+ // Where each paragraph starts: 0, and after each delimiter Pango's paragraph boundary knows: LF, CR
30
+ // (CRLF is one), and U+2029 (E2 80 A9).
31
+ std::vector<int> paragraphStarts(const std::string &text) {
32
+ std::vector<int> starts{0};
33
+ int index = 0;
34
+ for (size_t i = 0; i < text.size(); i++) {
35
+ char c = text[i];
36
+ if (continuation(c)) {
37
+ continue;
38
+ }
39
+ index++;
40
+ bool separator = text.compare(i, 3, "\xE2\x80\xA9") == 0;
41
+ bool crlf = c == '\r' && i + 1 < text.size() && text[i + 1] == '\n';
42
+ if ((c == '\n' || c == '\r' || separator) && !crlf) {
43
+ starts.push_back(index);
44
+ }
45
+ }
46
+ return starts;
47
+ }
48
+
49
+ // The unit holding `offset`: from the last start at or before it to the next start after it.
50
+ TextSpan around(const std::vector<int> &starts, int length, int offset) {
51
+ int start = 0;
52
+ int end = length;
53
+ for (int at : starts) {
54
+ if (at <= offset) {
55
+ start = std::max(start, at);
56
+ } else if (at < end) {
57
+ end = at;
58
+ }
59
+ }
60
+ // An offset at the very end belongs to the last unit, which ends there.
61
+ return {std::min(start, length), end};
62
+ }
63
+
64
+ } // namespace
65
+
66
+ TextSpan textUnitAt(const std::string &text, const TextBreaks &breaks, int offset, TextUnit unit) {
67
+ int length = characters(text);
68
+ offset = std::clamp(offset, 0, length);
69
+ switch (unit) {
70
+ case TextUnit::Character:
71
+ return {offset, std::min(offset + 1, length)};
72
+ case TextUnit::Word:
73
+ return around(breaks.words, length, offset);
74
+ case TextUnit::Sentence:
75
+ return around(breaks.sentences, length, offset);
76
+ case TextUnit::Line:
77
+ return around(breaks.lines, length, offset);
78
+ case TextUnit::Paragraph: {
79
+ auto starts = paragraphStarts(text);
80
+ // The empty paragraph after a final line break is no unit to read.
81
+ if (starts.size() > 1 && starts.back() == length) {
82
+ starts.pop_back();
83
+ }
84
+ return around(starts, length, offset);
85
+ }
86
+ }
87
+ return {offset, offset};
88
+ }
89
+
90
+ std::string textBetween(const std::string &text, int start, int end) {
91
+ if (end <= start) {
92
+ return {};
93
+ }
94
+ size_t from = byteOf(text, std::max(start, 0));
95
+ size_t to = byteOf(text, end);
96
+ return text.substr(from, to - from);
97
+ }
98
+
99
+ } // namespace ngn