@ng-native/desktop 0.23.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 (54) hide show
  1. package/native/CMakeLists.txt +3 -2
  2. package/native/appkit/CMakeLists.txt +25 -4
  3. package/native/appkit/camera-sheet.h +59 -0
  4. package/native/appkit/camera-sheet.mm +344 -0
  5. package/native/appkit/camera-view.mm +5 -1
  6. package/native/appkit/camera.h +22 -0
  7. package/native/appkit/camera.mm +203 -69
  8. package/native/appkit/cg-canvas.h +8 -1
  9. package/native/appkit/cg-canvas.mm +166 -21
  10. package/native/appkit/header-toolbar.mm +4 -1
  11. package/native/appkit/host-view.mm +29 -1
  12. package/native/appkit/main.mm +29 -69
  13. package/native/appkit/photo-library.mm +6 -6
  14. package/native/appkit/surface-view.mm +5 -1
  15. package/native/appkit/svg-view.h +2 -1
  16. package/native/appkit/svg-view.mm +49 -3
  17. package/native/appkit/tab-walk.h +31 -0
  18. package/native/appkit/tab-walk.mm +64 -0
  19. package/native/appkit/text-input-field.h +5 -0
  20. package/native/appkit/text-input-field.mm +101 -20
  21. package/native/appkit/text-layout.h +1 -1
  22. package/native/appkit/text-layout.mm +16 -8
  23. package/native/appkit/web-view-component.h +4 -3
  24. package/native/appkit/web-view-component.mm +8 -2
  25. package/native/appkit/web-view.mm +7 -0
  26. package/native/core/include/ngn/app-menus.h +8 -3
  27. package/native/core/include/ngn/back-swipe.h +16 -7
  28. package/native/core/include/ngn/camera.h +103 -9
  29. package/native/core/include/ngn/core-modules.h +3 -0
  30. package/native/core/include/ngn/dom-web-view.h +53 -0
  31. package/native/core/include/ngn/photo-library.h +7 -3
  32. package/native/core/include/ngn/runtime.h +10 -8
  33. package/native/core/include/ngn/safe-areas.h +5 -0
  34. package/native/core/include/ngn/surface-metrics.h +51 -0
  35. package/native/core/include/ngn/svg.h +49 -8
  36. package/native/core/include/ngn/text-input.h +9 -0
  37. package/native/core/include/ngn/web-view.h +6 -2
  38. package/native/core/src/app-menus.cpp +10 -3
  39. package/native/core/src/back-swipe.cpp +12 -5
  40. package/native/core/src/dom-web-view.cpp +45 -0
  41. package/native/core/src/libraries/rnsvg.cpp +13 -0
  42. package/native/core/src/modules/app-modules.cpp +20 -13
  43. package/native/core/src/modules/camera.cpp +203 -23
  44. package/native/core/src/modules/photo-library.cpp +22 -8
  45. package/native/core/src/mounting-manager.cpp +4 -0
  46. package/native/core/src/runtime.cpp +6 -8
  47. package/native/core/src/safe-areas.cpp +7 -0
  48. package/native/core/src/svg.cpp +324 -17
  49. package/native/core/src/text-input.cpp +13 -0
  50. package/native/core/src/web-view.cpp +1 -1
  51. package/native/scripts/build.sh +5 -1
  52. package/native/scripts/launch-probe.sh +60 -0
  53. package/package.json +2 -2
  54. package/prebuilt.json +6 -6
@@ -10,6 +10,7 @@
10
10
  #include <algorithm>
11
11
  #include <filesystem>
12
12
  #include <fstream>
13
+ #include <iterator>
13
14
  #include <random>
14
15
 
15
16
  using namespace facebook::react;
@@ -23,7 +24,8 @@ CameraProps::CameraProps(const PropsParserContext &context, const CameraProps &s
23
24
  HasDesktopProps{parseDesktopProps(context, sourceProps.desktop, rawProps)},
24
25
  facing(convertRawProp(context, rawProps, "facing", sourceProps.facing, std::string{"back"})),
25
26
  active(convertRawProp(context, rawProps, "active", sourceProps.active, true)),
26
- mirror(convertRawProp(context, rawProps, "mirror", sourceProps.mirror, false)) {}
27
+ mirror(convertRawProp(context, rawProps, "mirror", sourceProps.mirror, false)),
28
+ mute(convertRawProp(context, rawProps, "mute", sourceProps.mute, false)) {}
27
29
 
28
30
  void CameraViews::attach(int tag, std::shared_ptr<CameraCapture> capture) {
29
31
  std::lock_guard lock(mutex_);
@@ -33,10 +35,14 @@ void CameraViews::attach(int tag, std::shared_ptr<CameraCapture> capture) {
33
35
  void CameraViews::detach(int tag) {
34
36
  std::lock_guard lock(mutex_);
35
37
  captures_.erase(tag);
38
+ muted_.erase(tag);
36
39
  }
37
40
 
38
- std::shared_ptr<CameraCapture> CameraViews::find(int tag) const {
41
+ std::shared_ptr<CameraCapture> CameraViews::find(int tag, bool *muted) const {
39
42
  std::lock_guard lock(mutex_);
43
+ if (muted) {
44
+ *muted = muted_.contains(tag);
45
+ }
40
46
  auto found = captures_.find(tag);
41
47
  return found == captures_.end() ? nullptr : found->second;
42
48
  }
@@ -52,6 +58,20 @@ CameraMount cameraMount(CameraHardware::Access access, bool hasCamera, bool noPr
52
58
  return hasCamera ? CameraMount::Start : CameraMount::NoCamera;
53
59
  }
54
60
 
61
+ void CameraViews::mute(int tag, bool muted) {
62
+ std::lock_guard lock(mutex_);
63
+ if (muted) {
64
+ muted_.insert(tag);
65
+ } else {
66
+ muted_.erase(tag);
67
+ }
68
+ }
69
+
70
+ bool CameraViews::muted(int tag) const {
71
+ std::lock_guard lock(mutex_);
72
+ return muted_.contains(tag);
73
+ }
74
+
55
75
  int chooseCamera(const std::vector<CameraCandidate> &cameras) {
56
76
  int other = -1;
57
77
  for (size_t i = 0; i < cameras.size(); i++) {
@@ -77,15 +97,24 @@ std::string cameraMountError(CameraMount mount) {
77
97
  }
78
98
  }
79
99
 
80
- namespace {
81
-
82
- folly::dynamic permissionOf(CameraHardware::Access access) {
100
+ folly::dynamic cameraPermissionOf(CameraHardware::Access access) {
83
101
  using Access = CameraHardware::Access;
84
102
  const char *status = access == Access::Granted ? "granted" : access == Access::NotDetermined ? "undetermined" : "denied";
85
103
  return folly::dynamic::object("status", status)("granted", access == Access::Granted)("canAskAgain", access == Access::NotDetermined)(
86
104
  "expires", "never");
87
105
  }
88
106
 
107
+ void requestCameraPermission(CameraHardware &hardware, bool noPrompts, JsPromise promise) {
108
+ auto access = hardware.access();
109
+ if (noPrompts || access != CameraHardware::Access::NotDetermined) {
110
+ promise.resolve(cameraPermissionOf(access));
111
+ return;
112
+ }
113
+ hardware.requestAccess([promise](CameraHardware::Access decided) { promise.resolve(cameraPermissionOf(decided)); });
114
+ }
115
+
116
+ namespace {
117
+
89
118
  // A new file's name: a random UUID with `extension`, as expo names its pictures and videos.
90
119
  std::string newFileName(const std::string &extension) {
91
120
  static std::mutex mutex;
@@ -105,8 +134,157 @@ std::string contentsOf(const std::string &path) {
105
134
  return {std::istreambuf_iterator<char>(in), {}};
106
135
  }
107
136
 
137
+ // What expo-image-picker's mediaTypes (a MediaType, a list of them, or the deprecated
138
+ // MediaTypeOptions) let the camera take. As on iOS, live photos are photos, and a request that
139
+ // names neither photos nor videos (left out, or an empty list) takes photos.
140
+ struct MediaKinds {
141
+ bool photos{false};
142
+ bool videos{false};
143
+ };
144
+
145
+ MediaKinds mediaKindsOf(const folly::dynamic &options) {
146
+ MediaKinds kinds;
147
+ const auto *types = options.isObject() ? options.get_ptr("mediaTypes") : nullptr;
148
+ auto add = [&kinds](const folly::dynamic &type) {
149
+ if (!type.isString()) {
150
+ return;
151
+ }
152
+ kinds.photos = kinds.photos || type == "images" || type == "livePhotos" || type == "Images" || type == "All";
153
+ kinds.videos = kinds.videos || type == "videos" || type == "Videos" || type == "All";
154
+ };
155
+ if (types != nullptr && types->isArray()) {
156
+ for (const auto &type : *types) {
157
+ add(type);
158
+ }
159
+ } else if (types != nullptr) {
160
+ add(*types);
161
+ }
162
+ kinds.photos = kinds.photos || !kinds.videos;
163
+ return kinds;
164
+ }
165
+
166
+ // AVFoundation's session preset for expo-image-picker's videoQuality, which on iOS is
167
+ // UIImagePickerController's QualityType; High for any other value.
168
+ std::string videoPresetOf(const folly::dynamic &options) {
169
+ const auto *quality = options.isObject() ? options.get_ptr("videoQuality") : nullptr;
170
+ if (quality == nullptr || !quality->isNumber()) {
171
+ return "High";
172
+ }
173
+ static const char *const presets[] = {"High", "Medium", "Low", "640x480", "iFrame1280x720", "iFrame960x540"};
174
+ auto value = quality->asDouble();
175
+ for (size_t i = 0; i < std::size(presets); i++) {
176
+ if (value == static_cast<double>(i)) {
177
+ return presets[i];
178
+ }
179
+ }
180
+ return "High";
181
+ }
182
+
183
+ // Shows the sheet, once the microphone is settled, and answers what it took. A video has sound
184
+ // only with the microphone allowed.
185
+ void showPickerCamera(const PickerCamera &camera, const folly::dynamic &options, MediaKinds kinds, bool sound, JsPromise promise) {
186
+ CameraSheetRequest request{.photos = kinds.photos, .videos = kinds.videos};
187
+ request.video.sound = sound;
188
+ bool base64 = false;
189
+ bool exif = false;
190
+ if (options.isObject()) {
191
+ if (const auto *q = options.get_ptr("quality"); q && q->isNumber()) {
192
+ request.photo.quality = std::clamp(q->asDouble(), 0.0, 1.0);
193
+ }
194
+ if (const auto *d = options.get_ptr("videoMaxDuration"); d && d->isNumber()) {
195
+ request.video.maxDuration = std::max(0.0, d->asDouble());
196
+ }
197
+ base64 = options.getDefault("base64", false) == true;
198
+ exif = options.getDefault("exif", false) == true;
199
+ }
200
+ request.video.preset = videoPresetOf(options);
201
+ std::error_code ignored;
202
+ std::filesystem::create_directories(camera.folder, ignored);
203
+ request.photo.path = camera.folder + "/" + newFileName(".jpg");
204
+ request.video.path = camera.folder + "/" + newFileName(".mov");
205
+ auto photoPath = request.photo.path;
206
+ auto videoPath = request.video.path;
207
+ camera.sheet->shoot(request, [promise, photoPath, videoPath, base64, exif](CameraTake take, const std::string &error) {
208
+ if (!error.empty()) {
209
+ promise.reject("ImagePicker: " + error);
210
+ return;
211
+ }
212
+ if (!take.photo && !take.video) {
213
+ promise.resolve(folly::dynamic::object("canceled", true)("assets", nullptr));
214
+ return;
215
+ }
216
+ const auto &path = take.video ? videoPath : photoPath;
217
+ std::error_code sizeError;
218
+ auto size = std::filesystem::file_size(path, sizeError);
219
+ folly::dynamic asset = folly::dynamic::object("uri", fileUri(path))("assetId", nullptr)("fileName", nullptr)(
220
+ "fileSize", sizeError ? folly::dynamic(nullptr) : folly::dynamic(static_cast<int64_t>(size)))("exif", nullptr)("base64", nullptr);
221
+ if (take.video) {
222
+ // As iOS answers a recorded video: no EXIF and no base64, whatever was asked.
223
+ asset["type"] = "video";
224
+ asset["width"] = take.video->width;
225
+ asset["height"] = take.video->height;
226
+ asset["mimeType"] = "video/quicktime";
227
+ asset["duration"] = take.video->duration;
228
+ } else {
229
+ asset["type"] = "image";
230
+ asset["width"] = take.photo->width;
231
+ asset["height"] = take.photo->height;
232
+ asset["mimeType"] = "image/jpeg";
233
+ asset["duration"] = nullptr;
234
+ if (exif) {
235
+ asset["exif"] = take.photo->exif;
236
+ }
237
+ if (base64) {
238
+ asset["base64"] = base64Encode(contentsOf(path));
239
+ }
240
+ }
241
+ promise.resolve(folly::dynamic::object("canceled", false)("assets", folly::dynamic::array(std::move(asset))));
242
+ });
243
+ }
244
+
245
+ // iOS's words for a request for videos from an app that cannot ask for the microphone.
246
+ constexpr const char *kMissingMicrophone =
247
+ "ImagePicker: Missing microphone permission. Please enable it with the `expo-image-picker` config plugin";
248
+
108
249
  } // namespace
109
250
 
251
+ void launchPickerCamera(const PickerCamera &camera, bool noPrompts, const folly::dynamic &options, JsPromise promise) {
252
+ if (camera.hardware->access() != CameraHardware::Access::Granted) {
253
+ promise.reject("ImagePicker: Missing camera or camera roll permission");
254
+ return;
255
+ }
256
+ if (noPrompts) {
257
+ promise.resolve(folly::dynamic::object("canceled", true)("assets", nullptr));
258
+ return;
259
+ }
260
+ if (!camera.hardware->hasCamera()) {
261
+ promise.reject("ImagePicker: this Mac has no camera");
262
+ return;
263
+ }
264
+ auto kinds = mediaKindsOf(options);
265
+ if (!kinds.videos) {
266
+ showPickerCamera(camera, options, kinds, false, std::move(promise));
267
+ return;
268
+ }
269
+ // A video's sound, as iOS's camera has it: asked for when undetermined, and a video recorded with
270
+ // no sound when the microphone is refused. Only an app that cannot ask (no
271
+ // NSMicrophoneUsageDescription, so the request leaves it undetermined) is rejected, as iOS
272
+ // rejects it.
273
+ using Access = AudioInput::Access;
274
+ auto access = camera.microphone ? camera.microphone->access() : Access::Denied;
275
+ if (access != Access::NotDetermined) {
276
+ showPickerCamera(camera, options, kinds, access == Access::Granted, std::move(promise));
277
+ return;
278
+ }
279
+ camera.microphone->requestAccess([camera, options, kinds, promise](Access decided) {
280
+ if (decided == Access::NotDetermined) {
281
+ promise.reject(kMissingMicrophone);
282
+ return;
283
+ }
284
+ showPickerCamera(camera, options, kinds, decided == Access::Granted, promise);
285
+ });
286
+ }
287
+
110
288
  std::shared_ptr<NativeModule> makeCameraModule(
111
289
  std::shared_ptr<CameraHardware> hardware, std::shared_ptr<CameraViews> views, std::string pictures, bool noPrompts) {
112
290
  struct Camera : NativeModule {
@@ -114,15 +292,10 @@ std::shared_ptr<NativeModule> makeCameraModule(
114
292
  : NativeModule("NgNativeCamera") {
115
293
  using Access = CameraHardware::Access;
116
294
  promise("getCameraPermissionsAsync", [hardware](const folly::dynamic &, JsPromise promise) {
117
- promise.resolve(permissionOf(hardware->access()));
295
+ promise.resolve(cameraPermissionOf(hardware->access()));
118
296
  });
119
297
  promise("requestCameraPermissionsAsync", [hardware, noPrompts](const folly::dynamic &, JsPromise promise) {
120
- auto access = hardware->access();
121
- if (noPrompts || access != Access::NotDetermined) {
122
- promise.resolve(permissionOf(access));
123
- return;
124
- }
125
- hardware->requestAccess([promise](Access decided) { promise.resolve(permissionOf(decided)); });
298
+ requestCameraPermission(*hardware, noPrompts, std::move(promise));
126
299
  });
127
300
  promise("isAvailableAsync", [hardware](const folly::dynamic &, JsPromise promise) { promise.resolve(hardware->hasCamera()); });
128
301
  promise("takePicture", [hardware, views, pictures](const folly::dynamic &args, JsPromise promise) {
@@ -137,25 +310,34 @@ std::shared_ptr<NativeModule> makeCameraModule(
137
310
  promise.reject("Camera is not ready yet. Wait for 'onCameraReady' callback");
138
311
  return;
139
312
  }
140
- double quality = 1;
313
+ CameraPictureRequest request;
141
314
  bool base64 = false;
142
315
  if (options.isObject()) {
143
316
  if (const auto *q = options.get_ptr("quality"); q && q->isNumber()) {
144
- quality = std::clamp(q->asDouble(), 0.0, 1.0);
317
+ request.quality = std::clamp(q->asDouble(), 0.0, 1.0);
145
318
  }
146
319
  if (const auto *b = options.get_ptr("base64"); b && b->isBool()) {
147
320
  base64 = b->asBool();
148
321
  }
322
+ if (const auto *t = options.get_ptr("imageType"); t && !t->isNull()) {
323
+ if (!t->isString() || (t->asString() != "jpg" && t->asString() != "png")) {
324
+ promise.reject("Camera.takePicture: imageType must be 'jpg' or 'png'");
325
+ return;
326
+ }
327
+ request.format = t->asString();
328
+ }
149
329
  }
150
330
  std::error_code ignored;
151
331
  std::filesystem::create_directories(pictures, ignored);
152
- auto path = pictures + "/" + newFileName(".jpg");
153
- capture->takePicture(quality, path, [promise, path, base64](int width, int height, const std::string &error) {
332
+ request.path = pictures + "/" + newFileName("." + request.format);
333
+ auto path = request.path;
334
+ auto format = request.format;
335
+ capture->takePicture(request, [promise, path, format, base64](int width, int height, const std::string &error) {
154
336
  if (!error.empty()) {
155
337
  promise.reject("Camera.takePicture: " + error);
156
338
  return;
157
339
  }
158
- folly::dynamic picture = folly::dynamic::object("uri", fileUri(path))("width", width)("height", height)("format", "jpg");
340
+ folly::dynamic picture = folly::dynamic::object("uri", fileUri(path))("width", width)("height", height)("format", format);
159
341
  if (base64) {
160
342
  picture["base64"] = base64Encode(contentsOf(path));
161
343
  }
@@ -169,7 +351,8 @@ std::shared_ptr<NativeModule> makeCameraModule(
169
351
  promise.reject("Camera.record: camera permission has not been granted");
170
352
  return;
171
353
  }
172
- auto capture = views->find(tag);
354
+ bool muted = false;
355
+ auto capture = views->find(tag, &muted);
173
356
  if (!capture) {
174
357
  promise.reject("Camera is not ready yet. Wait for 'onCameraReady' callback");
175
358
  return;
@@ -179,7 +362,6 @@ std::shared_ptr<NativeModule> makeCameraModule(
179
362
  return;
180
363
  }
181
364
  CameraRecordingRequest request;
182
- bool mute = false;
183
365
  if (options.isObject()) {
184
366
  if (const auto *d = options.get_ptr("maxDuration"); d && d->isNumber()) {
185
367
  request.maxDuration = std::max(0.0, d->asDouble());
@@ -187,14 +369,12 @@ std::shared_ptr<NativeModule> makeCameraModule(
187
369
  if (const auto *f = options.get_ptr("maxFileSize"); f && f->isNumber()) {
188
370
  request.maxFileSize = std::max(0.0, f->asDouble());
189
371
  }
190
- if (const auto *m = options.get_ptr("mute"); m && m->isBool()) {
191
- mute = m->asBool();
192
- }
193
372
  if (const auto *c = options.get_ptr("codec"); c && c->isString()) {
194
373
  request.codec = c->asString();
195
374
  }
196
375
  }
197
- request.sound = !mute && hardware->microphoneAllowed();
376
+ // The view's `mute` prop, as on iOS, where record() takes no `mute`.
377
+ request.sound = !muted && hardware->microphoneAllowed();
198
378
  std::error_code ignored;
199
379
  std::filesystem::create_directories(pictures, ignored);
200
380
  request.path = pictures + "/" + newFileName(".mov");
@@ -1,5 +1,7 @@
1
1
  #include "ngn/photo-library.h"
2
2
 
3
+ #include "ngn/camera.h"
4
+
3
5
  #include <mutex>
4
6
  #include <set>
5
7
  #include <stdexcept>
@@ -327,9 +329,9 @@ std::shared_ptr<NativeModule> makeMediaLibraryModule(std::shared_ptr<PhotoLibrar
327
329
  return std::make_shared<MediaLibrary>(std::move(library), noPrompts, std::move(files));
328
330
  }
329
331
 
330
- std::shared_ptr<NativeModule> makeImagePickerModule(std::shared_ptr<PhotoLibrary> library, bool noPrompts) {
332
+ std::shared_ptr<NativeModule> makeImagePickerModule(std::shared_ptr<PhotoLibrary> library, bool noPrompts, std::optional<PickerCamera> camera) {
331
333
  struct ImagePicker : NativeModule {
332
- ImagePicker(std::shared_ptr<PhotoLibrary> photos, bool noPrompts) : NativeModule("NgNativeImagePicker") {
334
+ ImagePicker(std::shared_ptr<PhotoLibrary> photos, bool noPrompts, std::optional<PickerCamera> camera) : NativeModule("NgNativeImagePicker") {
333
335
  Permissions permissions{photos, noPrompts};
334
336
  promise("getMediaLibraryPermissionsAsync", [permissions](const folly::dynamic &args, JsPromise promise) {
335
337
  permissions.get(flagArg(args, 0), std::move(promise));
@@ -337,12 +339,24 @@ std::shared_ptr<NativeModule> makeImagePickerModule(std::shared_ptr<PhotoLibrary
337
339
  promise("requestMediaLibraryPermissionsAsync", [permissions](const folly::dynamic &args, JsPromise promise) {
338
340
  permissions.request(flagArg(args, 0), std::move(promise));
339
341
  });
340
- // No system camera to open on macOS.
341
- auto noCamera = [](const folly::dynamic &, JsPromise promise) { promise.resolve(permissionOf(Access::Denied)); };
342
- promise("getCameraPermissionsAsync", noCamera);
343
- promise("requestCameraPermissionsAsync", noCamera);
344
342
  folly::dynamic canceled = folly::dynamic::object("canceled", true)("assets", nullptr);
345
- promise("launchCameraAsync", [canceled](const folly::dynamic &, JsPromise promise) { promise.resolve(canceled); });
343
+ if (camera) {
344
+ promise("getCameraPermissionsAsync", [hardware = camera->hardware](const folly::dynamic &, JsPromise promise) {
345
+ promise.resolve(cameraPermissionOf(hardware->access()));
346
+ });
347
+ promise("requestCameraPermissionsAsync", [hardware = camera->hardware, noPrompts](const folly::dynamic &, JsPromise promise) {
348
+ requestCameraPermission(*hardware, noPrompts, std::move(promise));
349
+ });
350
+ promise("launchCameraAsync", [camera = *camera, noPrompts](const folly::dynamic &args, JsPromise promise) {
351
+ launchPickerCamera(camera, noPrompts, args.empty() ? folly::dynamic(nullptr) : args[0], std::move(promise));
352
+ });
353
+ } else {
354
+ // A host with no camera of its own to show.
355
+ auto noCamera = [](const folly::dynamic &, JsPromise promise) { promise.resolve(permissionOf(Access::Denied)); };
356
+ promise("getCameraPermissionsAsync", noCamera);
357
+ promise("requestCameraPermissionsAsync", noCamera);
358
+ promise("launchCameraAsync", [canceled](const folly::dynamic &, JsPromise promise) { promise.resolve(canceled); });
359
+ }
346
360
  promise("launchImageLibraryAsync", [photos, noPrompts, canceled](const folly::dynamic &args, JsPromise promise) {
347
361
  if (noPrompts) {
348
362
  promise.resolve(canceled);
@@ -365,7 +379,7 @@ std::shared_ptr<NativeModule> makeImagePickerModule(std::shared_ptr<PhotoLibrary
365
379
  });
366
380
  }
367
381
  };
368
- return std::make_shared<ImagePicker>(std::move(library), noPrompts);
382
+ return std::make_shared<ImagePicker>(std::move(library), noPrompts, std::move(camera));
369
383
  }
370
384
 
371
385
  } // namespace ngn
@@ -6,6 +6,7 @@
6
6
  #include <chrono>
7
7
 
8
8
  #include "ngn/desktop-modal.h"
9
+ #include "ngn/dom-web-view.h"
9
10
  #include "ngn/native-controls.h"
10
11
  #include "ngn/split-view.h"
11
12
  #include "ngn/apple-authentication.h"
@@ -70,6 +71,7 @@ MountingManager::MountingManager(
70
71
  concreteComponentDescriptorProvider<AppleButtonComponentDescriptor>(),
71
72
  concreteComponentDescriptorProvider<GlassViewComponentDescriptor>(),
72
73
  concreteComponentDescriptorProvider<GlassContainerComponentDescriptor>(),
74
+ concreteComponentDescriptorProvider<DomWebViewComponentDescriptor>(),
73
75
  concreteComponentDescriptorProvider<UnimplementedNativeViewComponentDescriptor>(),
74
76
  };
75
77
  for (auto &provider : expoUIComponentProviders()) {
@@ -220,12 +222,14 @@ void MountingManager::apply(SurfaceId surfaceId, const ShadowViewMutationList &m
220
222
  }
221
223
  if (old.state != view.state) {
222
224
  backend_->updateState(view);
225
+ svgs_.relaidOut(tree_, view.tag);
223
226
  if (auto sizes = controlSizes()) {
224
227
  sizes->relaidOut(view.tag);
225
228
  }
226
229
  }
227
230
  if (old.layoutMetrics != view.layoutMetrics) {
228
231
  backend_->updateLayout(view);
232
+ svgs_.relaidOut(tree_, view.tag);
229
233
  }
230
234
  break;
231
235
  }
@@ -62,10 +62,6 @@ class DevUI final : public IDevUIDelegate {
62
62
  std::function<void()> &resumed_;
63
63
  };
64
64
 
65
- LayoutConstraints constraints(const SurfaceMetrics &metrics) {
66
- return {.minimumSize = metrics.size, .maximumSize = metrics.size};
67
- }
68
-
69
65
  LayoutContext context(const SurfaceMetrics &metrics) {
70
66
  LayoutContext context;
71
67
  context.pointScaleFactor = metrics.pointScale;
@@ -239,6 +235,7 @@ bool Runtime::loadBundle() {
239
235
  }
240
236
  // With dev mode on, ReactHost downloads the source path through the dev server helper, which
241
237
  // takes the bundle URL as it is.
238
+ direction_.instanceStarted();
242
239
  return devServer_ ? host_->loadScript("", bundle_) : host_->loadScript(bundle_, bundle_);
243
240
  }
244
241
 
@@ -249,7 +246,7 @@ void Runtime::startSurface(SurfaceId surfaceId, const std::string &moduleName, c
249
246
  }
250
247
  std::lock_guard lock(mutex_);
251
248
  if (host_) {
252
- host_->startSurface(surfaceId, moduleName, folly::dynamic::object(), constraints(metrics), context(metrics));
249
+ host_->startSurface(surfaceId, moduleName, folly::dynamic::object(), surfaceConstraints(metrics, direction_.rightToLeft()), context(metrics));
253
250
  }
254
251
  }
255
252
 
@@ -272,7 +269,7 @@ void Runtime::updateSurface(SurfaceId surfaceId, const SurfaceMetrics &metrics)
272
269
  }
273
270
  std::lock_guard lock(mutex_);
274
271
  if (host_) {
275
- host_->setSurfaceConstraints(surfaceId, constraints(metrics), context(metrics));
272
+ host_->setSurfaceConstraints(surfaceId, surfaceConstraints(metrics, direction_.rightToLeft()), context(metrics));
276
273
  }
277
274
  }
278
275
 
@@ -340,6 +337,7 @@ void Runtime::reload(std::function<void(bool)> done) {
340
337
  workletHost().runOnScheduler.set(nullptr);
341
338
  host_.reset();
342
339
  createHost();
340
+ direction_.instanceStarted();
343
341
  *loaded = devServer_ ? host_->loadScript("", bundle_) : host_->loadScript(bundle_, bundle_);
344
342
  restarted = true;
345
343
  }
@@ -366,12 +364,12 @@ void Runtime::reload(std::function<void(bool)> done) {
366
364
  std::lock_guard lock(mutex_);
367
365
  for (const auto &[surfaceId, surface] : step->start) {
368
366
  host_->startSurface(
369
- surfaceId, surface.moduleName, folly::dynamic::object(), constraints(surface.metrics), context(surface.metrics));
367
+ surfaceId, surface.moduleName, folly::dynamic::object(), surfaceConstraints(surface.metrics, direction_.rightToLeft()), context(surface.metrics));
370
368
  started.insert(surfaceId);
371
369
  }
372
370
  // A surface resized after the reload started it takes its size now.
373
371
  for (const auto &[surfaceId, surface] : step->update) {
374
- host_->setSurfaceConstraints(surfaceId, constraints(surface.metrics), context(surface.metrics));
372
+ host_->setSurfaceConstraints(surfaceId, surfaceConstraints(surface.metrics, direction_.rightToLeft()), context(surface.metrics));
375
373
  }
376
374
  for (auto surfaceId : step->stop) {
377
375
  host_->stopSurface(surfaceId);
@@ -17,6 +17,13 @@ EdgeInsets insetsWithin(const ContainerInsets &container, const Rect &frame) {
17
17
  };
18
18
  }
19
19
 
20
+ double titlebarLeading(double minX, double maxX, double width, bool rightToLeft) {
21
+ if (maxX <= 0 || minX >= width) {
22
+ return 0;
23
+ }
24
+ return rightToLeft ? width - minX : maxX;
25
+ }
26
+
20
27
  void SafeAreas::created(const ShadowView &view) {
21
28
  std::string_view name = view.componentName;
22
29
  if (name == "RNCSafeAreaProvider") {