@react-navigation/lynx 0.4.4 → 0.4.5

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.
package/README.md CHANGED
@@ -23,6 +23,11 @@ host app as well.
23
23
  `@lynx-js/react` has to be 0.126 or later, where `ref` reaches components as a
24
24
  prop the way it does in React 19; `NavigationContainer` depends on that.
25
25
 
26
+ Lynx's JS engine is missing builtins that `@react-navigation/core`,
27
+ `@react-navigation/routers` and `query-string` call, so importing this package
28
+ installs conditional polyfills for `Array.prototype.findLast`, `findLastIndex`
29
+ and `at`, `Object.hasOwn`, `String.prototype.replaceAll` and `queueMicrotask`.
30
+
26
31
  `@react-navigation/core` is written against React, so `react` has to resolve to
27
32
  ReactLynx's compat entry, which adds `use`, `useInsertionEffect` and
28
33
  `startTransition`:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-navigation/lynx",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "Lynx integration for React Navigation",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
package/src/index.tsx CHANGED
@@ -5,6 +5,8 @@
5
5
  // The platform layer, mirroring what `@react-navigation/native` does for
6
6
  // React Native: it owns everything Lynx-specific that every navigator needs,
7
7
  // and re-exports core so apps have a single import surface.
8
+ import './polyfills';
9
+
8
10
  export { createStaticNavigation } from './createStaticNavigation';
9
11
  export { LinkingContext } from './LinkingContext';
10
12
  export { LocaleDirContext } from './LocaleDirContext';
@@ -0,0 +1,91 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ type Predicate<T> = (value: T, index: number, array: T[]) => boolean;
6
+
7
+ function define(target: object, name: string, value: unknown) {
8
+ Object.defineProperty(target, name, {
9
+ value,
10
+ configurable: true,
11
+ writable: true,
12
+ });
13
+ }
14
+
15
+ if (typeof Array.prototype.findLast !== 'function') {
16
+ define(Array.prototype, 'findLast', function<T>(
17
+ this: T[],
18
+ predicate: Predicate<T>,
19
+ thisArg?: unknown
20
+ ) {
21
+ for (let i = this.length - 1; i >= 0; i--) {
22
+ if (predicate.call(thisArg, this[i] as T, i, this)) {
23
+ return this[i];
24
+ }
25
+ }
26
+
27
+ return undefined;
28
+ });
29
+ }
30
+
31
+ if (typeof Array.prototype.findLastIndex !== 'function') {
32
+ define(Array.prototype, 'findLastIndex', function<T>(
33
+ this: T[],
34
+ predicate: Predicate<T>,
35
+ thisArg?: unknown
36
+ ) {
37
+ for (let i = this.length - 1; i >= 0; i--) {
38
+ if (predicate.call(thisArg, this[i] as T, i, this)) {
39
+ return i;
40
+ }
41
+ }
42
+
43
+ return -1;
44
+ });
45
+ }
46
+
47
+ if (typeof Array.prototype.at !== 'function') {
48
+ define(Array.prototype, 'at', function<T>(this: T[], index: number) {
49
+ const i = Math.trunc(index) || 0;
50
+
51
+ return this[i < 0 ? this.length + i : i];
52
+ });
53
+ }
54
+
55
+ if (typeof Object.hasOwn !== 'function') {
56
+ define(Object, 'hasOwn', function(target: object, key: PropertyKey) {
57
+ return Object.prototype.hasOwnProperty.call(target, key);
58
+ });
59
+ }
60
+
61
+ if (typeof String.prototype.replaceAll !== 'function') {
62
+ define(String.prototype, 'replaceAll', function(
63
+ this: string,
64
+ pattern: string | RegExp,
65
+ replacement: string | ((...args: string[]) => string)
66
+ ) {
67
+ if (pattern instanceof RegExp) {
68
+ if (!pattern.global) {
69
+ throw new TypeError(
70
+ 'replaceAll must be called with a global RegExp'
71
+ );
72
+ }
73
+
74
+ return this.replace(pattern, replacement as string);
75
+ }
76
+
77
+ const escaped = String(pattern).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
78
+
79
+ return this.replace(new RegExp(escaped, 'g'), replacement as string);
80
+ });
81
+ }
82
+
83
+ const globals = globalThis as {
84
+ queueMicrotask?: (callback: () => void) => void;
85
+ };
86
+
87
+ if (typeof globals.queueMicrotask !== 'function') {
88
+ globals.queueMicrotask = (callback: () => void) => {
89
+ Promise.resolve().then(callback);
90
+ };
91
+ }
@@ -2,6 +2,8 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
 
5
+ import '../polyfills';
6
+
5
7
  /**
6
8
  * Navigators
7
9
  */