@ng-native/desktop 0.24.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.
@@ -8,6 +8,7 @@
8
8
  #include <react/renderer/attributedstring/AttributedString.h>
9
9
  #include <react/renderer/attributedstring/ParagraphAttributes.h>
10
10
  #include <react/renderer/graphics/Size.h>
11
+ #include <react/renderer/textlayoutmanager/TextMeasureCache.h>
11
12
  #include <react/utils/ContextContainer.h>
12
13
 
13
14
  #include <memory>
@@ -24,6 +25,16 @@ class TextMeasurer {
24
25
  const facebook::react::AttributedString &text,
25
26
  const facebook::react::ParagraphAttributes &paragraph,
26
27
  facebook::react::Float maxWidth) const = 0;
28
+
29
+ // The lines the text lays out in at `width`, each with its frame and its first font's metrics,
30
+ // y measured from the top of the text: what a baseline and onTextLayout read. None by default,
31
+ // which reads as a baseline at the top.
32
+ virtual facebook::react::LinesMeasurements lines(
33
+ const facebook::react::AttributedString &text,
34
+ const facebook::react::ParagraphAttributes &paragraph,
35
+ facebook::react::Float width) const {
36
+ return {};
37
+ }
27
38
  };
28
39
 
29
40
  // The ContextContainer key the core's TextLayoutManager reads the measurer from.
@@ -377,8 +377,10 @@ std::shared_ptr<NativeModule> makeGestureHandlerModule(const CoreModuleServices
377
377
  // Each call is already queued for the UI thread as it is made.
378
378
  sync("flushOperations", [](const folly::dynamic &) { return folly::dynamic(nullptr); });
379
379
  // The worklet runtime's `_setGestureStateSync` is not installed: a worklet's state manager
380
- // reaches the handlers through Reanimated's setGestureState instead (worklet-host.h).
381
- sync("installUIRuntimeBindings", [](const folly::dynamic &) { return folly::dynamic(false); });
380
+ // reaches the handlers through Reanimated's setGestureState instead (worklet-host.h). The
381
+ // answer only decides whether the gesture handler warns, telling the app to report a bug,
382
+ // so it says the runtime is ready, as the gesture handler's own web module does.
383
+ sync("installUIRuntimeBindings", [](const folly::dynamic &) { return folly::dynamic(true); });
382
384
  }
383
385
 
384
386
  void send(const std::string &event, folly::dynamic body) const {
@@ -1,5 +1,8 @@
1
1
  #include "ngn/scrollers.h"
2
2
 
3
+ #include <algorithm>
4
+ #include <cmath>
5
+
3
6
  using namespace facebook::react;
4
7
  namespace yoga = facebook::yoga;
5
8
 
@@ -20,6 +23,14 @@ ScrollerVisibility scrollerVisibility(
20
23
  };
21
24
  }
22
25
 
26
+ float pagedOffset(float offset, float velocity, float page, float max) {
27
+ // ponytail: a flick is a fixed speed, as UIKit's paging roughly is; tune here if it feels off.
28
+ constexpr float flick = 0.3f;
29
+ float at = page > 0 ? offset / page : 0;
30
+ float index = velocity > flick ? std::floor(at) + 1 : velocity < -flick ? std::ceil(at) - 1 : std::round(at);
31
+ return std::clamp(index * page, 0.0f, std::max(0.0f, max));
32
+ }
33
+
23
34
  ScrollerGutter scrollerGutter(ScrollerStyle style, float legacyWidth, const ScrollerVisibility &visibility) {
24
35
  if (style == ScrollerStyle::Overlay) {
25
36
  return {};
@@ -60,4 +60,17 @@ TextMeasurement TextLayoutManager::measure(
60
60
  compute);
61
61
  }
62
62
 
63
+ LinesMeasurements TextLayoutManager::measureLines(
64
+ const AttributedStringBox &attributedStringBox,
65
+ const ParagraphAttributes &paragraphAttributes,
66
+ const Size &size) const {
67
+ auto measurer = contextContainer_
68
+ ? contextContainer_->find<std::shared_ptr<const ngn::TextMeasurer>>(ngn::kTextMeasurerKey)
69
+ : std::nullopt;
70
+ if (!measurer || !*measurer) {
71
+ return {};
72
+ }
73
+ return (*measurer)->lines(attributedStringBox.getValue(), paragraphAttributes, size.width);
74
+ }
75
+
63
76
  } // namespace facebook::react
@@ -142,7 +142,13 @@ fi
142
142
 
143
143
  arch_key="${archs//;/-}"
144
144
  hermes_args=()
145
- if [ "$backend" != "none" ]; then
145
+ if [ "$backend" = "appkit" ]; then
146
+ # React Native's own prebuilt Hermes, universal: with the debugger for a dev build, as React
147
+ # Native's Debug builds have it, and without for Release.
148
+ hermes_flavour=debug
149
+ [ "$config" = Release ] && hermes_flavour=release
150
+ hermes_args=(-DNGN_HERMES_PREBUILT="$("$here/fetch-hermes.sh" "$RN_PKG" "$hermes_flavour")")
151
+ elif [ "$backend" != "none" ]; then
146
152
  hermes="$CACHE/hermes-$arch_key"
147
153
  # Built again when missing, or built for another macOS than the host's.
148
154
  if ! "$here/hermes-built.sh" "$hermes"; then
@@ -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"
@@ -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.24.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.24.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/v0.24.0/ng-native-desktop-host-0.24.0-rn-0.88.0-macos-universal-debug.tar.gz",
8
- "sha256": "511cf3168dd8a613655934d68f9ad574834d510b1d55ef743b39031bf41526c4",
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": "7fa2f4fd506382258e6a1717b3bd20bacf13e0c0c7753e14326a6396c50722de"
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/v0.24.0/ng-native-desktop-host-0.24.0-rn-0.88.0-macos-universal.tar.gz",
22
- "sha256": "0f0c417ebb24b25062696db92a6797585fed117def31ff87e7a4e09e127aeae6",
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": "62458462c0c914c24a88a151a4af50ad70fbb332a967b81f9d78774da29fef4c"
30
+ "inputs": "8176fcd27ee569b08a235f090a03d5de22625039cf48e904245b5248316abe4a"
31
31
  }
32
32
  ]
33
33
  }