@ng-native/desktop 0.23.0 → 0.25.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 (73) hide show
  1. package/bin/package.mjs +65 -9
  2. package/bin/prebuilt.mjs +25 -4
  3. package/native/CMakeLists.txt +7 -2
  4. package/native/appkit/CMakeLists.txt +39 -5
  5. package/native/appkit/appkit-backend.mm +28 -3
  6. package/native/appkit/camera-sheet.h +59 -0
  7. package/native/appkit/camera-sheet.mm +344 -0
  8. package/native/appkit/camera-view.mm +5 -1
  9. package/native/appkit/camera.h +22 -0
  10. package/native/appkit/camera.mm +203 -69
  11. package/native/appkit/cg-canvas.h +8 -1
  12. package/native/appkit/cg-canvas.mm +166 -21
  13. package/native/appkit/header-toolbar.mm +4 -1
  14. package/native/appkit/host-view.mm +29 -1
  15. package/native/appkit/image-view.mm +31 -2
  16. package/native/appkit/main.mm +29 -69
  17. package/native/appkit/photo-library.mm +6 -6
  18. package/native/appkit/scroll-view.mm +57 -16
  19. package/native/appkit/scrollers.h +22 -2
  20. package/native/appkit/scrollers.mm +221 -2
  21. package/native/appkit/split-view.h +4 -0
  22. package/native/appkit/split-view.mm +57 -3
  23. package/native/appkit/surface-view.mm +5 -1
  24. package/native/appkit/svg-view.h +2 -1
  25. package/native/appkit/svg-view.mm +49 -3
  26. package/native/appkit/tab-walk.h +31 -0
  27. package/native/appkit/tab-walk.mm +64 -0
  28. package/native/appkit/text-input-field.h +5 -0
  29. package/native/appkit/text-input-field.mm +101 -20
  30. package/native/appkit/text-layout.h +7 -1
  31. package/native/appkit/text-layout.mm +161 -30
  32. package/native/appkit/web-view-component.h +4 -3
  33. package/native/appkit/web-view-component.mm +8 -2
  34. package/native/appkit/web-view.mm +7 -0
  35. package/native/cmake/react-native.cmake +9 -0
  36. package/native/cmake/runtime-dependencies.cmake +21 -0
  37. package/native/core/include/ngn/app-menus.h +8 -3
  38. package/native/core/include/ngn/back-swipe.h +16 -7
  39. package/native/core/include/ngn/camera.h +103 -9
  40. package/native/core/include/ngn/core-modules.h +3 -0
  41. package/native/core/include/ngn/dom-web-view.h +53 -0
  42. package/native/core/include/ngn/photo-library.h +7 -3
  43. package/native/core/include/ngn/runtime.h +10 -8
  44. package/native/core/include/ngn/safe-areas.h +5 -0
  45. package/native/core/include/ngn/scrollers.h +5 -0
  46. package/native/core/include/ngn/surface-metrics.h +51 -0
  47. package/native/core/include/ngn/svg.h +49 -8
  48. package/native/core/include/ngn/text-input.h +9 -0
  49. package/native/core/include/ngn/text-measurer.h +11 -0
  50. package/native/core/include/ngn/web-view.h +6 -2
  51. package/native/core/src/app-menus.cpp +10 -3
  52. package/native/core/src/back-swipe.cpp +12 -5
  53. package/native/core/src/dom-web-view.cpp +45 -0
  54. package/native/core/src/libraries/rnsvg.cpp +13 -0
  55. package/native/core/src/modules/app-modules.cpp +24 -15
  56. package/native/core/src/modules/camera.cpp +203 -23
  57. package/native/core/src/modules/photo-library.cpp +22 -8
  58. package/native/core/src/mounting-manager.cpp +4 -0
  59. package/native/core/src/runtime.cpp +6 -8
  60. package/native/core/src/safe-areas.cpp +7 -0
  61. package/native/core/src/scrollers.cpp +11 -0
  62. package/native/core/src/svg.cpp +324 -17
  63. package/native/core/src/text-input.cpp +13 -0
  64. package/native/core/src/text-layout-manager.cpp +13 -0
  65. package/native/core/src/web-view.cpp +1 -1
  66. package/native/scripts/build.sh +12 -2
  67. package/native/scripts/fetch-hermes.sh +70 -0
  68. package/native/scripts/launch-probe.sh +60 -0
  69. package/native/scripts/make-prebuilt.mjs +13 -6
  70. package/native/scripts/prebuilt-host-cache.mjs +1 -1
  71. package/native/shim/text-platform/react/renderer/textlayoutmanager/TextLayoutManager.h +52 -0
  72. package/package.json +2 -2
  73. package/prebuilt.json +6 -6
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env bash
2
+ # Fetches React Native's own prebuilt Hermes for Apple platforms, the one its iOS apps run, and
3
+ # prints the folder with its universal macOS hermesvm.framework, hermesc and headers.
4
+ #
5
+ # fetch-hermes.sh <node_modules/react-native> <debug|release>
6
+ #
7
+ # debug carries Hermes's debugger (CDP), as React Native's Debug builds do; release leaves it out.
8
+ # The tarball comes from Maven Central and is checked against the SHA-1 published beside it.
9
+ set -euo pipefail
10
+ here="$(cd "$(dirname "$0")" && pwd)"
11
+ RN_PKG="$(cd "${1:?usage: fetch-hermes.sh <node_modules/react-native> <debug|release>}" && pwd)"
12
+ FLAVOUR="${2:?usage: fetch-hermes.sh <node_modules/react-native> <debug|release>}"
13
+ case "$FLAVOUR" in debug | release) ;; *) echo "fetch-hermes.sh: debug or release, not $FLAVOUR" >&2; exit 2 ;; esac
14
+
15
+ RN_VERSION="$(node -p 'require(process.argv[1] + "/package.json").version' "$RN_PKG")"
16
+ CACHE="$("$here/cache-dir.sh" "$RN_VERSION")"
17
+ tag="$(cat "$RN_PKG/sdks/.hermesv1version")"
18
+ version="${tag#hermes-v}"
19
+ OUT="$CACHE/hermes-prebuilt-$version-$FLAVOUR"
20
+ framework="$OUT/destroot/Library/Frameworks/macosx/hermesvm.framework"
21
+
22
+ if [ ! -d "$framework" ] || [ ! -x "$OUT/destroot/bin/hermesc" ]; then
23
+ base="${NGN_HERMES_MAVEN:-https://repo1.maven.org/maven2}/com/facebook/hermes/hermes-ios/$version"
24
+ url="$base/hermes-ios-$version-hermes-ios-$FLAVOUR.tar.gz"
25
+ tmp="$(mktemp -d)"
26
+ trap 'rm -rf "$tmp"' EXIT
27
+ curl -fsSL --retry 3 -o "$tmp/hermes.tar.gz" "$url"
28
+ expected="$(curl -fsSL --retry 3 "$url.sha1" | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]')"
29
+ actual="$(shasum -a 1 "$tmp/hermes.tar.gz" | cut -d' ' -f1)"
30
+ if [ "${#expected}" != 40 ] || [ "$expected" != "$actual" ]; then
31
+ echo "fetch-hermes.sh: $url has SHA-1 $actual, Maven publishes '$expected'" >&2
32
+ exit 1
33
+ fi
34
+ mkdir -p "$tmp/x"
35
+ tar -xzf "$tmp/hermes.tar.gz" -C "$tmp/x"
36
+ [ -d "$tmp/x/destroot/Library/Frameworks/macosx/hermesvm.framework" ] ||
37
+ { echo "fetch-hermes.sh: $url has no macOS hermesvm.framework" >&2; exit 1; }
38
+ # Another build may fetch the same Hermes at once: publish under a lock, and keep a complete
39
+ # copy it published rather than remove a folder it is reading.
40
+ mkdir -p "$(dirname "$OUT")"
41
+ # A held lock is waited on for at most ten minutes. One left by a build killed before its trap ran
42
+ # is not taken over, since two builds taking it over at once could each remove the other's.
43
+ lock="$OUT.lock"
44
+ acquired=0
45
+ absent=0
46
+ for _ in $(seq 600); do
47
+ if mkdir "$lock" 2>/dev/null; then
48
+ acquired=1
49
+ break
50
+ fi
51
+ # No lock, yet mkdir failed: its holder may have just released it, so retry, a few times.
52
+ if [ ! -d "$lock" ]; then
53
+ absent=$((absent + 1))
54
+ [ "$absent" -lt 5 ] && continue
55
+ echo "fetch-hermes.sh: cannot create $lock" >&2
56
+ exit 1
57
+ fi
58
+ sleep 1
59
+ done
60
+ if [ "$acquired" != 1 ]; then
61
+ echo "fetch-hermes.sh: $lock is still held after ten minutes; delete it if no build is running" >&2
62
+ exit 1
63
+ fi
64
+ trap 'rm -rf "$tmp" "$lock"' EXIT
65
+ if [ ! -d "$framework" ] || [ ! -x "$OUT/destroot/bin/hermesc" ]; then
66
+ rm -rf "$OUT"
67
+ mv "$tmp/x" "$OUT"
68
+ fi
69
+ fi
70
+ echo "$OUT/destroot"
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env bash
2
+ # Launches a built host on a bundle file and checks that it starts: the app commits and the host
3
+ # draws its first frame, then it keeps running for a moment. Fails on a crash or an exit before
4
+ # then, an uncaught JavaScript error, or no first frame in time. Prints the host's log either way.
5
+ #
6
+ # launch-probe.sh <ngn-macos> <bundle.js> [seconds, default 60]
7
+ #
8
+ # A test launch (NGN_TESTS=1): the host keeps its state in a new directory, takes no focus and
9
+ # shows no system prompt, so the probe leaves nothing behind on the machine it runs on.
10
+ set -euo pipefail
11
+ host="${1:?usage: launch-probe.sh <ngn-macos> <bundle.js> [seconds]}"
12
+ bundle="${2:?usage: launch-probe.sh <ngn-macos> <bundle.js> [seconds]}"
13
+ limit="${3:-60}"
14
+
15
+ work="$(mktemp -d)"
16
+ log="$work/host.log"
17
+ pid=""
18
+ cleanup() {
19
+ if [ -n "$pid" ] && kill -0 "$pid" 2> /dev/null; then
20
+ kill "$pid" 2> /dev/null || true
21
+ wait "$pid" 2> /dev/null || true
22
+ fi
23
+ rm -rf "$work"
24
+ }
25
+ trap cleanup EXIT
26
+
27
+ mkdir "$work/state"
28
+ NGN_TESTS=1 NGN_STATE_DIR="$work/state" NGN_RUN_ID="probe-$$" NGN_TESTS_FAKE_SYSTEM_UI=1 NGN_LOG_COMMITS=1 \
29
+ "$host" "$bundle" --title "Launch probe" > "$log" 2>&1 &
30
+ pid=$!
31
+
32
+ fail() {
33
+ echo "launch-probe: $1" >&2
34
+ echo "--- host log ---" >&2
35
+ cat "$log" >&2
36
+ exit 1
37
+ }
38
+
39
+ # An uncaught error reaches React Native's default error handler, which logs it; console.error logs
40
+ # at level 3.
41
+ js_error() {
42
+ grep -qE '\[onJsError called\]|\[js:3\]' "$log"
43
+ }
44
+
45
+ start=$(date +%s)
46
+ while ! grep -q '^\[ngn\] first frame' "$log"; do
47
+ kill -0 "$pid" 2> /dev/null || { wait "$pid" && status=0 || status=$?; fail "the host exited ($status) before its first frame"; }
48
+ js_error && fail "a JavaScript error before the first frame"
49
+ [ $(($(date +%s) - start)) -lt "$limit" ] || fail "no first frame within ${limit}s"
50
+ sleep 0.2
51
+ done
52
+ grep -q '^\[ngn\] commit' "$log" || fail "the first frame came with no commit"
53
+
54
+ # Still running a moment after the first frame: a crash in the commits that follow fails too.
55
+ sleep 3
56
+ kill -0 "$pid" 2> /dev/null || { wait "$pid" && status=0 || status=$?; fail "the host exited ($status) after its first frame"; }
57
+ js_error && fail "a JavaScript error after the first frame"
58
+
59
+ cat "$log"
60
+ echo "launch-probe: $(grep '^\[ngn\] first frame' "$log"), $(grep -c '^\[ngn\] commit' "$log") commits"
@@ -40,7 +40,10 @@
40
40
  * The host has no app's linked code and is built from scratch in a directory of its own, so no other
41
41
  * build can replace it before it is archived. `ngn-macos` and `hermesc` have their local symbols
42
42
  * stripped and are signed with the hardened runtime, ad hoc (`codesign --sign -`) unless `NGN_SIGN_IDENTITY` names an identity: an
43
- * app re-signs the host when it packages, so the release needs no Developer ID. Nothing is uploaded.
43
+ * app re-signs the host when it packages, so the release needs no Developer ID. React Native's
44
+ * `hermesvm.framework`, which the binary links, is signed first with the same identity, and an ad
45
+ * hoc binary goes without library validation, which has no team to check it against (see
46
+ * AD_HOC_HOST_ENTITLEMENTS). Nothing is uploaded.
44
47
  */
45
48
  import { spawnSync } from 'node:child_process';
46
49
  import { createHash } from 'node:crypto';
@@ -62,6 +65,7 @@ import { parseArgs } from 'node:util';
62
65
 
63
66
  import { HOST_LIBRARIES, packageDir } from '../../bin/host.mjs';
64
67
  import {
68
+ AD_HOC_HOST_ENTITLEMENTS,
65
69
  FLAVOURS,
66
70
  flavourOf,
67
71
  prebuiltName,
@@ -316,11 +320,14 @@ try {
316
320
  verbatimSymlinks: true,
317
321
  });
318
322
  }
319
- signPrebuiltFiles(
320
- run,
321
- ['ngn-macos', 'hermesc'].map((file) => path.join(appkit, file)),
322
- process.env,
323
- );
323
+ // The framework first, which the binary's signature then covers with the same identity.
324
+ const framework = path.join(appkit, 'hermesvm.framework');
325
+ if (existsSync(framework)) signPrebuiltFiles(run, [framework], process.env);
326
+ const entitlements = path.join(staging, 'ad-hoc-host.entitlements');
327
+ writeFileSync(entitlements, AD_HOC_HOST_ENTITLEMENTS);
328
+ signPrebuiltFiles(run, [path.join(appkit, 'ngn-macos')], process.env, entitlements);
329
+ rmSync(entitlements);
330
+ signPrebuiltFiles(run, [path.join(appkit, 'hermesc')], process.env);
324
331
  }
325
332
  for (const file of HOST_FILES) {
326
333
  if (!existsSync(path.join(appkit, file))) throw new Error(`The host has no ${file}.`);
@@ -21,7 +21,7 @@ import {
21
21
  import path from 'node:path';
22
22
 
23
23
  /** What the cache holds, under `appkit/`: the files make-prebuilt.mjs archives. */
24
- export const HOST_FILES = ['ngn-macos', 'hermesc', 'Sparkle.framework'];
24
+ export const HOST_FILES = ['ngn-macos', 'hermesc', 'hermesvm.framework', 'Sparkle.framework'];
25
25
 
26
26
  /** Bumped when the cache's layout or what the key covers changes, so older caches miss. */
27
27
  const SCHEMA = 1;
@@ -0,0 +1,52 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ // React Native's cxx TextLayoutManager header (textlayoutmanager/platform/cxx), with measureLines
9
+ // added: React Native reads a text's baseline (`align-items: baseline`) and sends onTextLayout
10
+ // only when the class declares it (TextLayoutManagerExtended::supportsLineMeasurement). The core
11
+ // implements both over a backend's TextMeasurer (src/text-layout-manager.cpp). Keep it in step with
12
+ // React Native's header when React Native is upgraded.
13
+ #pragma once
14
+
15
+ #include <react/renderer/attributedstring/AttributedStringBox.h>
16
+ #include <react/renderer/attributedstring/ParagraphAttributes.h>
17
+ #include <react/renderer/core/LayoutConstraints.h>
18
+ #include <react/renderer/textlayoutmanager/TextLayoutContext.h>
19
+ #include <react/renderer/textlayoutmanager/TextMeasureCache.h>
20
+ #include <react/utils/ContextContainer.h>
21
+ #include <memory>
22
+
23
+ namespace facebook::react {
24
+
25
+ class TextLayoutManager {
26
+ public:
27
+ explicit TextLayoutManager(const std::shared_ptr<const ContextContainer> &contextContainer);
28
+ virtual ~TextLayoutManager() = default;
29
+
30
+ TextLayoutManager(const TextLayoutManager &) = delete;
31
+ TextLayoutManager &operator=(const TextLayoutManager &) = delete;
32
+ TextLayoutManager(TextLayoutManager &&) = delete;
33
+ TextLayoutManager &operator=(TextLayoutManager &&) = delete;
34
+
35
+ virtual TextMeasurement measure(
36
+ const AttributedStringBox &attributedStringBox,
37
+ const ParagraphAttributes &paragraphAttributes,
38
+ const TextLayoutContext &layoutContext,
39
+ const LayoutConstraints &layoutConstraints) const;
40
+
41
+ // The lines `attributedStringBox` lays out in, `size` big.
42
+ LinesMeasurements measureLines(
43
+ const AttributedStringBox &attributedStringBox,
44
+ const ParagraphAttributes &paragraphAttributes,
45
+ const Size &size) const;
46
+
47
+ protected:
48
+ std::shared_ptr<const ContextContainer> contextContainer_;
49
+ TextMeasureCache textMeasureCache_;
50
+ };
51
+
52
+ } // namespace facebook::react
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-native/desktop",
3
- "version": "0.23.0",
3
+ "version": "0.25.0",
4
4
  "description": "The macOS desktop host for Angular Native: React Native's C++ core and Hermes, mounting into AppKit views, and the ng-native-desktop command that builds and launches it.",
5
5
  "keywords": [
6
6
  "angular",
@@ -16,7 +16,7 @@
16
16
  "ng-native-desktop": "./bin/ng-native-desktop.mjs"
17
17
  },
18
18
  "dependencies": {
19
- "@ng-native/device": "0.23.0"
19
+ "@ng-native/device": "0.25.0"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "react-native": "~0.88.0"
package/prebuilt.json CHANGED
@@ -4,8 +4,8 @@
4
4
  {
5
5
  "reactNative": "0.88.0",
6
6
  "flavour": "debug",
7
- "url": "https://github.com/ng-native/ng-native/releases/download/vminor/ng-native-desktop-host-minor-rn-0.88.0-macos-universal-debug.tar.gz",
8
- "sha256": "f69b8e99c19f739f6a8f0039fe92a99a2e3dca7b2523f95541e6943c13678d46",
7
+ "url": "https://github.com/ng-native/ng-native/releases/download/v0.25.0/ng-native-desktop-host-0.25.0-rn-0.88.0-macos-universal-debug.tar.gz",
8
+ "sha256": "ed27065ecb02b16a533ae73ad894e1ef398ee88219ed72cc441e223de6a46022",
9
9
  "libraries": {
10
10
  "react-native-screens": "4.30.0",
11
11
  "react-native-safe-area-context": "5.10.1",
@@ -13,13 +13,13 @@
13
13
  "react-native-worklets": "0.13.0",
14
14
  "react-native-reanimated": "4.7.1"
15
15
  },
16
- "inputs": "af0e12481a719f97c4ba92eee9317c1207084d2cb6f4eb6affada352019e3f32"
16
+ "inputs": "f891f249fcb9d7dea347f359361aefac1ff8b381aa2c216274f40c0e00942749"
17
17
  },
18
18
  {
19
19
  "reactNative": "0.88.0",
20
20
  "flavour": "release",
21
- "url": "https://github.com/ng-native/ng-native/releases/download/vminor/ng-native-desktop-host-minor-rn-0.88.0-macos-universal.tar.gz",
22
- "sha256": "d4058d91c399452762deef93ea87586e3511c22d249ea9853819ae16ebca7f33",
21
+ "url": "https://github.com/ng-native/ng-native/releases/download/v0.25.0/ng-native-desktop-host-0.25.0-rn-0.88.0-macos-universal.tar.gz",
22
+ "sha256": "bc1fd2540661e89eaf8f346522d197909c35f55d237bde52c0ab76bceab6cae9",
23
23
  "libraries": {
24
24
  "react-native-screens": "4.30.0",
25
25
  "react-native-safe-area-context": "5.10.1",
@@ -27,7 +27,7 @@
27
27
  "react-native-worklets": "0.13.0",
28
28
  "react-native-reanimated": "4.7.1"
29
29
  },
30
- "inputs": "2521d55a05418e1d949972e0263e34ebd502ef69694a58bf8d45428b4c0d080b"
30
+ "inputs": "8176fcd27ee569b08a235f090a03d5de22625039cf48e904245b5248316abe4a"
31
31
  }
32
32
  ]
33
33
  }