@tamagui/native-registry 3.0.9 → 3.0.11
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/android/build.gradle +1 -1
- package/cpp/HybridTamaguiRegistry.cpp +92 -14
- package/cpp/HybridTamaguiRegistry.hpp +1 -0
- package/dist/cjs/index.native.cjs +5 -4
- package/dist/cjs/index.native.js +5 -4
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/index.native.js +5 -4
- package/dist/esm/index.native.js.map +1 -1
- package/package.json +3 -3
- package/src/index.native.ts +9 -4
- package/types/index.native.d.ts.map +2 -2
package/android/build.gradle
CHANGED
|
@@ -35,7 +35,7 @@ android {
|
|
|
35
35
|
externalNativeBuild {
|
|
36
36
|
cmake {
|
|
37
37
|
cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
|
|
38
|
-
arguments "-DANDROID_STL=c++_shared"
|
|
38
|
+
arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
|
|
39
39
|
abiFilters(*(rootProject.getProperties().get("reactNativeArchitectures")?.split(",")
|
|
40
40
|
?: ["x86", "x86_64", "armeabi-v7a", "arm64-v8a"]))
|
|
41
41
|
}
|
|
@@ -16,10 +16,15 @@
|
|
|
16
16
|
|
|
17
17
|
#include <algorithm>
|
|
18
18
|
#include <cstring>
|
|
19
|
+
#include <exception>
|
|
19
20
|
#include <optional>
|
|
20
21
|
#include <unordered_set>
|
|
21
22
|
#include <vector>
|
|
22
23
|
|
|
24
|
+
#ifdef __APPLE__
|
|
25
|
+
#include <dispatch/dispatch.h>
|
|
26
|
+
#endif
|
|
27
|
+
|
|
23
28
|
#ifdef __ANDROID__
|
|
24
29
|
#include <fbjni/fbjni.h>
|
|
25
30
|
|
|
@@ -293,6 +298,91 @@ std::optional<AffectedNodes> findAffectedNodes(const RootShadowNode& root,
|
|
|
293
298
|
return affected;
|
|
294
299
|
}
|
|
295
300
|
|
|
301
|
+
struct PropsJob {
|
|
302
|
+
const ShadowNode* node;
|
|
303
|
+
HybridTamaguiRegistry::LeafUpdate* update;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
void parsePropsJob(PropsJob& job) {
|
|
307
|
+
const auto& node = *job.node;
|
|
308
|
+
PropsParserContext ctx{node.getSurfaceId(), *node.getContextContainer()};
|
|
309
|
+
job.update->prepared = node.getComponentDescriptor().cloneProps(
|
|
310
|
+
ctx, node.getProps(), RawProps(job.update->props()));
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
#ifdef __APPLE__
|
|
314
|
+
struct PropsWorkers {
|
|
315
|
+
std::vector<PropsJob>& jobs;
|
|
316
|
+
size_t count;
|
|
317
|
+
std::vector<std::exception_ptr> errors;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
void parsePropsWorker(void* context, size_t worker) {
|
|
321
|
+
auto& work = *static_cast<PropsWorkers*>(context);
|
|
322
|
+
try {
|
|
323
|
+
for (size_t i = worker; i < work.jobs.size(); i += work.count) {
|
|
324
|
+
parsePropsJob(work.jobs[i]);
|
|
325
|
+
}
|
|
326
|
+
} catch (...) {
|
|
327
|
+
work.errors[worker] = std::current_exception();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
#endif
|
|
331
|
+
|
|
332
|
+
// only props parsing runs concurrently: it reads immutable nodes and tables,
|
|
333
|
+
// with a separate RawProps cursor per view. state, warm caches, tree cloning,
|
|
334
|
+
// and React's runtime shadow-node handles remain on the committing thread.
|
|
335
|
+
void prepareProps(const RootShadowNode& root, LeafUpdates& updates,
|
|
336
|
+
const AffectedNodes* affected) {
|
|
337
|
+
std::vector<PropsJob> jobs;
|
|
338
|
+
jobs.reserve(updates.size());
|
|
339
|
+
std::vector<const ShadowNode*> stack{&root};
|
|
340
|
+
while (!stack.empty()) {
|
|
341
|
+
const auto* node = stack.back();
|
|
342
|
+
stack.pop_back();
|
|
343
|
+
const auto& children = node->getChildren();
|
|
344
|
+
if (!affected) {
|
|
345
|
+
for (const auto& child : children) stack.push_back(child.get());
|
|
346
|
+
} else if (auto it = affected->find(&node->getFamily());
|
|
347
|
+
it != affected->end()) {
|
|
348
|
+
for (auto index : it->second) stack.push_back(children[index].get());
|
|
349
|
+
}
|
|
350
|
+
const auto it = updates.find(&node->getFamily());
|
|
351
|
+
if (it == updates.end()) continue;
|
|
352
|
+
auto& update = it->second;
|
|
353
|
+
update.prepared = nullptr;
|
|
354
|
+
if (auto* warm = update.warm) {
|
|
355
|
+
if (warm->last != node->getProps()) warm->byState.clear();
|
|
356
|
+
const auto cached = warm->byState.find(*update.state);
|
|
357
|
+
if (cached != warm->byState.end()) update.prepared = cached->second;
|
|
358
|
+
}
|
|
359
|
+
if (!update.prepared) jobs.push_back({node, &update});
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
#ifdef __APPLE__
|
|
363
|
+
if (jobs.size() >= 256) {
|
|
364
|
+
constexpr size_t workers = 4;
|
|
365
|
+
PropsWorkers work{jobs, workers, std::vector<std::exception_ptr>(workers)};
|
|
366
|
+
dispatch_apply_f(workers,
|
|
367
|
+
dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0),
|
|
368
|
+
&work, parsePropsWorker);
|
|
369
|
+
for (const auto& error : work.errors) {
|
|
370
|
+
if (error) std::rethrow_exception(error);
|
|
371
|
+
}
|
|
372
|
+
} else
|
|
373
|
+
#endif
|
|
374
|
+
{
|
|
375
|
+
for (auto& job : jobs) parsePropsJob(job);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
for (auto& [family, update] : updates) {
|
|
379
|
+
if (update.warm && update.prepared) {
|
|
380
|
+
update.warm->byState[*update.state] = update.prepared;
|
|
381
|
+
update.warm->last = update.prepared;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
296
386
|
// RN dirties the measurement of every paragraph cloned with props, and the
|
|
297
387
|
// dirty flag relays out each ancestor: one text color in each row of a long
|
|
298
388
|
// list relays out the whole list. for a paragraph of plain strings, whose
|
|
@@ -377,20 +467,7 @@ std::shared_ptr<ShadowNode> cloneSubtree(const ShadowNode& node,
|
|
|
377
467
|
Props::Shared newProps = ShadowNodeFragment::propsPlaceholder();
|
|
378
468
|
if (auto it = updates.find(family); it != updates.end()) {
|
|
379
469
|
const auto& update = it->second;
|
|
380
|
-
|
|
381
|
-
PropsParserContext ctx{node.getSurfaceId(), *node.getContextContainer()};
|
|
382
|
-
return node.getComponentDescriptor().cloneProps(ctx, node.getProps(),
|
|
383
|
-
RawProps(update.props()));
|
|
384
|
-
};
|
|
385
|
-
if (auto* warm = update.warm) {
|
|
386
|
-
if (warm->last != node.getProps()) warm->byState.clear();
|
|
387
|
-
auto& props = warm->byState[*update.state];
|
|
388
|
-
if (!props) props = parse();
|
|
389
|
-
warm->last = props;
|
|
390
|
-
newProps = props;
|
|
391
|
-
} else {
|
|
392
|
-
newProps = parse();
|
|
393
|
-
}
|
|
470
|
+
newProps = update.prepared;
|
|
394
471
|
if (auto restyled = restyleParagraph(node, newProps)) {
|
|
395
472
|
return restyled;
|
|
396
473
|
}
|
|
@@ -555,6 +632,7 @@ void HybridTamaguiRegistry::commitUpdates(jsi::Runtime& rt,
|
|
|
555
632
|
[&updates](const RootShadowNode& oldRoot)
|
|
556
633
|
-> RootShadowNode::Unshared {
|
|
557
634
|
auto affected = findAffectedNodes(oldRoot, updates);
|
|
635
|
+
prepareProps(oldRoot, updates, affected ? &*affected : nullptr);
|
|
558
636
|
return std::static_pointer_cast<RootShadowNode>(cloneSubtree(
|
|
559
637
|
oldRoot, updates, affected ? &*affected : nullptr));
|
|
560
638
|
},
|
|
@@ -56,6 +56,7 @@ class HybridTamaguiRegistry : public HybridTamaguiRegistrySpec {
|
|
|
56
56
|
struct LeafUpdate {
|
|
57
57
|
const folly::dynamic* shared = nullptr;
|
|
58
58
|
folly::dynamic owned;
|
|
59
|
+
facebook::react::Props::Shared prepared;
|
|
59
60
|
// table views only
|
|
60
61
|
WarmProps* warm = nullptr;
|
|
61
62
|
const std::string* state = nullptr;
|
|
@@ -58,10 +58,11 @@ function getEngine() {
|
|
|
58
58
|
throw new Error(`[@tamagui/native-registry] TamaguiRegistry failed to initialize; is react-native-nitro-modules installed and the app rebuilt?${detail}`);
|
|
59
59
|
}
|
|
60
60
|
function getShadowNode(ref) {
|
|
61
|
-
var _ref;
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
var _ref, _ref1;
|
|
62
|
+
var _record___internalInstanceHandle_stateNode, _record___internalInstanceHandle, _record_stateNode;
|
|
63
|
+
if (!ref || typeof ref !== "object") return null;
|
|
64
|
+
var record = ref;
|
|
65
|
+
return (_ref = (_ref1 = (_record___internalInstanceHandle = record.__internalInstanceHandle) === null || _record___internalInstanceHandle === void 0 ? void 0 : (_record___internalInstanceHandle_stateNode = _record___internalInstanceHandle.stateNode) === null || _record___internalInstanceHandle_stateNode === void 0 ? void 0 : _record___internalInstanceHandle_stateNode.node) !== null && _ref1 !== void 0 ? _ref1 : (_record_stateNode = record.stateNode) === null || _record_stateNode === void 0 ? void 0 : _record_stateNode.node) !== null && _ref !== void 0 ? _ref : null;
|
|
65
66
|
}
|
|
66
67
|
function isNitroHybridView(ref) {
|
|
67
68
|
var config = ref === null || ref === void 0 ? void 0 : ref.__viewConfig;
|
package/dist/cjs/index.native.js
CHANGED
|
@@ -58,10 +58,11 @@ function getEngine() {
|
|
|
58
58
|
throw new Error(`[@tamagui/native-registry] TamaguiRegistry failed to initialize; is react-native-nitro-modules installed and the app rebuilt?${detail}`);
|
|
59
59
|
}
|
|
60
60
|
function getShadowNode(ref) {
|
|
61
|
-
var _ref;
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
var _ref, _ref1;
|
|
62
|
+
var _record___internalInstanceHandle_stateNode, _record___internalInstanceHandle, _record_stateNode;
|
|
63
|
+
if (!ref || typeof ref !== "object") return null;
|
|
64
|
+
var record = ref;
|
|
65
|
+
return (_ref = (_ref1 = (_record___internalInstanceHandle = record.__internalInstanceHandle) === null || _record___internalInstanceHandle === void 0 ? void 0 : (_record___internalInstanceHandle_stateNode = _record___internalInstanceHandle.stateNode) === null || _record___internalInstanceHandle_stateNode === void 0 ? void 0 : _record___internalInstanceHandle_stateNode.node) !== null && _ref1 !== void 0 ? _ref1 : (_record_stateNode = record.stateNode) === null || _record_stateNode === void 0 ? void 0 : _record_stateNode.node) !== null && _ref !== void 0 ? _ref : null;
|
|
65
66
|
}
|
|
66
67
|
function isNitroHybridView(ref) {
|
|
67
68
|
var config = ref === null || ref === void 0 ? void 0 : ref.__viewConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.native.js","names":[],"sources":["cjs/index.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar index_native_exports = {};\n__export(index_native_exports, {\n ROOT_SCOPE: () => import_mirror2.ROOT_SCOPE,\n applyViewStates: () => applyViewStates,\n getMirroredStateName: () => import_mirror2.getMirroredStateName,\n getStats: () => getStats,\n getViewState: () => getViewState,\n isAvailable: () => isAvailable,\n link: () => link,\n linkTables: () => linkTables,\n processStyleColors: () => import_processStyleColors.processStyleColors,\n removeScope: () => removeScope,\n resolveSlots: () => resolveSlots,\n setStateName: () => setStateName,\n setTableState: () => setTableState,\n unlink: () => unlink\n});\nmodule.exports = __toCommonJS(index_native_exports);\nvar import_react_native_nitro_modules = require(\"react-native-nitro-modules\");\nvar import_mirror = require(\"./mirror\");\nvar import_mirror2 = require(\"./mirror\");\nvar import_processStyleColors = require(\"./processStyleColors.native\");\nvar engine = null;\nvar initError = null;\ntry {\n engine = import_react_native_nitro_modules.NitroModules.createHybridObject(\"TamaguiRegistry\");\n} catch (error) {\n initError = error;\n}\nfunction isAvailable() {\n return engine !== null;\n}\nfunction getEngine() {\n if (engine) return engine;\n var detail = initError instanceof Error ? ` ${initError.message}` : \"\";\n throw new Error(`[@tamagui/native-registry] TamaguiRegistry failed to initialize; is react-native-nitro-modules installed and the app rebuilt?${detail}`);\n}\nfunction getShadowNode(ref) {\n var _ref;\n var
|
|
1
|
+
{"version":3,"file":"index.native.js","names":[],"sources":["cjs/index.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar index_native_exports = {};\n__export(index_native_exports, {\n ROOT_SCOPE: () => import_mirror2.ROOT_SCOPE,\n applyViewStates: () => applyViewStates,\n getMirroredStateName: () => import_mirror2.getMirroredStateName,\n getStats: () => getStats,\n getViewState: () => getViewState,\n isAvailable: () => isAvailable,\n link: () => link,\n linkTables: () => linkTables,\n processStyleColors: () => import_processStyleColors.processStyleColors,\n removeScope: () => removeScope,\n resolveSlots: () => resolveSlots,\n setStateName: () => setStateName,\n setTableState: () => setTableState,\n unlink: () => unlink\n});\nmodule.exports = __toCommonJS(index_native_exports);\nvar import_react_native_nitro_modules = require(\"react-native-nitro-modules\");\nvar import_mirror = require(\"./mirror\");\nvar import_mirror2 = require(\"./mirror\");\nvar import_processStyleColors = require(\"./processStyleColors.native\");\nvar engine = null;\nvar initError = null;\ntry {\n engine = import_react_native_nitro_modules.NitroModules.createHybridObject(\"TamaguiRegistry\");\n} catch (error) {\n initError = error;\n}\nfunction isAvailable() {\n return engine !== null;\n}\nfunction getEngine() {\n if (engine) return engine;\n var detail = initError instanceof Error ? ` ${initError.message}` : \"\";\n throw new Error(`[@tamagui/native-registry] TamaguiRegistry failed to initialize; is react-native-nitro-modules installed and the app rebuilt?${detail}`);\n}\nfunction getShadowNode(ref) {\n var _ref, _ref1;\n var _record___internalInstanceHandle_stateNode, _record___internalInstanceHandle, _record_stateNode;\n if (!ref || typeof ref !== \"object\") return null;\n var record = ref;\n return (_ref = (_ref1 = (_record___internalInstanceHandle = record.__internalInstanceHandle) === null || _record___internalInstanceHandle === void 0 ? void 0 : (_record___internalInstanceHandle_stateNode = _record___internalInstanceHandle.stateNode) === null || _record___internalInstanceHandle_stateNode === void 0 ? void 0 : _record___internalInstanceHandle_stateNode.node) !== null && _ref1 !== void 0 ? _ref1 : (_record_stateNode = record.stateNode) === null || _record_stateNode === void 0 ? void 0 : _record_stateNode.node) !== null && _ref !== void 0 ? _ref : null;\n}\nfunction isNitroHybridView(ref) {\n var config = ref === null || ref === void 0 ? void 0 : ref.__viewConfig;\n return !!(config === null || config === void 0 ? void 0 : config.validAttributes) && \"hybridRef\" in config.validAttributes;\n}\nfunction link(ref, table) {\n var scopeId = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : import_mirror.ROOT_SCOPE, commitNow = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;\n if (isNitroHybridView(ref)) return null;\n var node = getShadowNode(ref);\n if (!node) return null;\n var e = getEngine();\n var id = e.link(node, table, scopeId, commitNow);\n var unlinked = false;\n return {\n id,\n unlink: function unlink2() {\n if (unlinked) return;\n unlinked = true;\n e.unlink(id);\n }\n };\n}\nfunction linkTables(refs, tableIds, scopeIndexes, scopes) {\n var nodes = new Array(refs.length);\n for (var i = 0; i < refs.length; i++) {\n nodes[i] = getShadowNode(refs[i]);\n }\n getEngine().linkTables(nodes, tableIds, scopeIndexes, scopes);\n}\nfunction unlink(id) {\n getEngine().unlink(id);\n}\nfunction applyViewStates(entries) {\n if (entries.length === 0) return;\n getEngine().applyViewStates(entries);\n}\nfunction setTableState(tableId, state, props) {\n getEngine().setTableState(tableId, state, props);\n}\nfunction setStateName(stateName) {\n var scopeId = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : import_mirror.ROOT_SCOPE;\n (0, import_mirror.setMirroredStateName)(scopeId, stateName);\n getEngine().setStateName(scopeId, stateName);\n}\nfunction removeScope(scopeId) {\n (0, import_mirror.removeMirroredScope)(scopeId);\n getEngine().removeScope(scopeId);\n}\nfunction resolveSlots(slots) {\n var scopeId = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : import_mirror.ROOT_SCOPE;\n var _slots_state;\n var name = (0, import_mirror.getMirroredStateName)(scopeId);\n return {\n ...slots.base,\n ...name ? (_slots_state = slots.state) === null || _slots_state === void 0 ? void 0 : _slots_state[name] : void 0\n };\n}\nfunction getViewState(id) {\n if (!engine) return null;\n return engine.getViewState(id);\n}\nfunction getStats() {\n if (!engine) return {\n viewCount: 0,\n commitCount: 0,\n missCount: 0\n };\n return {\n viewCount: engine.getViewCount(),\n commitCount: engine.getCommitCount(),\n missCount: engine.getMissCount()\n };\n}\n//# sourceMappingURL=index.native.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YA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Aa;EACb,WAAW;CACb;CACA,OAAO;EACL,WAAW,OAAO,aAAa;EAC/B,aAAa,OAAO,eAAe;EACnC,WAAW,OAAO,aAAa;CACjC;AACF"}
|
package/dist/esm/index.native.js
CHANGED
|
@@ -18,10 +18,11 @@ function getEngine() {
|
|
|
18
18
|
throw new Error(`[@tamagui/native-registry] TamaguiRegistry failed to initialize; is react-native-nitro-modules installed and the app rebuilt?${detail}`);
|
|
19
19
|
}
|
|
20
20
|
function getShadowNode(ref) {
|
|
21
|
-
var _ref;
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
var _ref, _ref1;
|
|
22
|
+
var _record___internalInstanceHandle_stateNode, _record___internalInstanceHandle, _record_stateNode;
|
|
23
|
+
if (!ref || typeof ref !== "object") return null;
|
|
24
|
+
var record = ref;
|
|
25
|
+
return (_ref = (_ref1 = (_record___internalInstanceHandle = record.__internalInstanceHandle) === null || _record___internalInstanceHandle === void 0 ? void 0 : (_record___internalInstanceHandle_stateNode = _record___internalInstanceHandle.stateNode) === null || _record___internalInstanceHandle_stateNode === void 0 ? void 0 : _record___internalInstanceHandle_stateNode.node) !== null && _ref1 !== void 0 ? _ref1 : (_record_stateNode = record.stateNode) === null || _record_stateNode === void 0 ? void 0 : _record_stateNode.node) !== null && _ref !== void 0 ? _ref : null;
|
|
25
26
|
}
|
|
26
27
|
function isNitroHybridView(ref) {
|
|
27
28
|
var config = ref === null || ref === void 0 ? void 0 : ref.__viewConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.native.js","names":[],"sources":["esm/index.native.js"],"sourcesContent":["import { NitroModules } from \"react-native-nitro-modules\";\nimport { ROOT_SCOPE, getMirroredStateName, removeMirroredScope, setMirroredStateName } from \"./mirror\";\nimport { ROOT_SCOPE as ROOT_SCOPE2, getMirroredStateName as getMirroredStateName2 } from \"./mirror\";\nimport { processStyleColors } from \"./processStyleColors.native\";\nvar engine = null;\nvar initError = null;\ntry {\n engine = NitroModules.createHybridObject(\"TamaguiRegistry\");\n} catch (error) {\n initError = error;\n}\nfunction isAvailable() {\n return engine !== null;\n}\nfunction getEngine() {\n if (engine) return engine;\n var detail = initError instanceof Error ? ` ${initError.message}` : \"\";\n throw new Error(`[@tamagui/native-registry] TamaguiRegistry failed to initialize; is react-native-nitro-modules installed and the app rebuilt?${detail}`);\n}\nfunction getShadowNode(ref) {\n var _ref;\n var
|
|
1
|
+
{"version":3,"file":"index.native.js","names":[],"sources":["esm/index.native.js"],"sourcesContent":["import { NitroModules } from \"react-native-nitro-modules\";\nimport { ROOT_SCOPE, getMirroredStateName, removeMirroredScope, setMirroredStateName } from \"./mirror\";\nimport { ROOT_SCOPE as ROOT_SCOPE2, getMirroredStateName as getMirroredStateName2 } from \"./mirror\";\nimport { processStyleColors } from \"./processStyleColors.native\";\nvar engine = null;\nvar initError = null;\ntry {\n engine = NitroModules.createHybridObject(\"TamaguiRegistry\");\n} catch (error) {\n initError = error;\n}\nfunction isAvailable() {\n return engine !== null;\n}\nfunction getEngine() {\n if (engine) return engine;\n var detail = initError instanceof Error ? ` ${initError.message}` : \"\";\n throw new Error(`[@tamagui/native-registry] TamaguiRegistry failed to initialize; is react-native-nitro-modules installed and the app rebuilt?${detail}`);\n}\nfunction getShadowNode(ref) {\n var _ref, _ref1;\n var _record___internalInstanceHandle_stateNode, _record___internalInstanceHandle, _record_stateNode;\n if (!ref || typeof ref !== \"object\") return null;\n var record = ref;\n return (_ref = (_ref1 = (_record___internalInstanceHandle = record.__internalInstanceHandle) === null || _record___internalInstanceHandle === void 0 ? void 0 : (_record___internalInstanceHandle_stateNode = _record___internalInstanceHandle.stateNode) === null || _record___internalInstanceHandle_stateNode === void 0 ? void 0 : _record___internalInstanceHandle_stateNode.node) !== null && _ref1 !== void 0 ? _ref1 : (_record_stateNode = record.stateNode) === null || _record_stateNode === void 0 ? void 0 : _record_stateNode.node) !== null && _ref !== void 0 ? _ref : null;\n}\nfunction isNitroHybridView(ref) {\n var config = ref === null || ref === void 0 ? void 0 : ref.__viewConfig;\n return !!(config === null || config === void 0 ? void 0 : config.validAttributes) && \"hybridRef\" in config.validAttributes;\n}\nfunction link(ref, table) {\n var scopeId = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : ROOT_SCOPE, commitNow = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;\n if (isNitroHybridView(ref)) return null;\n var node = getShadowNode(ref);\n if (!node) return null;\n var e = getEngine();\n var id = e.link(node, table, scopeId, commitNow);\n var unlinked = false;\n return {\n id,\n unlink: function unlink2() {\n if (unlinked) return;\n unlinked = true;\n e.unlink(id);\n }\n };\n}\nfunction linkTables(refs, tableIds, scopeIndexes, scopes) {\n var nodes = new Array(refs.length);\n for (var i = 0; i < refs.length; i++) {\n nodes[i] = getShadowNode(refs[i]);\n }\n getEngine().linkTables(nodes, tableIds, scopeIndexes, scopes);\n}\nfunction unlink(id) {\n getEngine().unlink(id);\n}\nfunction applyViewStates(entries) {\n if (entries.length === 0) return;\n getEngine().applyViewStates(entries);\n}\nfunction setTableState(tableId, state, props) {\n getEngine().setTableState(tableId, state, props);\n}\nfunction setStateName(stateName) {\n var scopeId = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ROOT_SCOPE;\n setMirroredStateName(scopeId, stateName);\n getEngine().setStateName(scopeId, stateName);\n}\nfunction removeScope(scopeId) {\n removeMirroredScope(scopeId);\n getEngine().removeScope(scopeId);\n}\nfunction resolveSlots(slots) {\n var scopeId = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ROOT_SCOPE;\n var _slots_state;\n var name = getMirroredStateName(scopeId);\n return {\n ...slots.base,\n ...name ? (_slots_state = slots.state) === null || _slots_state === void 0 ? void 0 : _slots_state[name] : void 0\n };\n}\nfunction getViewState(id) {\n if (!engine) return null;\n return engine.getViewState(id);\n}\nfunction getStats() {\n if (!engine) return {\n viewCount: 0,\n commitCount: 0,\n missCount: 0\n };\n return {\n viewCount: engine.getViewCount(),\n commitCount: engine.getCommitCount(),\n missCount: engine.getMissCount()\n };\n}\nexport {\n ROOT_SCOPE2 as ROOT_SCOPE,\n applyViewStates,\n getMirroredStateName2 as getMirroredStateName,\n getStats,\n getViewState,\n isAvailable,\n link,\n linkTables,\n processStyleColors,\n removeScope,\n resolveSlots,\n setStateName,\n setTableState,\n unlink\n};\n//# sourceMappingURL=index.native.js.map\n"],"mappings":";;;;;AAIA,IAAI,SAAS;AACb,IAAI,YAAY;AAChB,IAAI;CACF,SAAS,aAAa,mBAAmB,iBAAiB;AAC5D,SAAS,OAAO;CACd,YAAY;AACd;AACA,SAAS,cAAc;CACrB,OAAO,WAAW;AACpB;AACA,SAAS,YAAY;CACnB,IAAI,QAAQ,OAAO;CACnB,IAAI,SAAS,qBAAqB,QAAQ,IAAI,UAAU,YAAY;CACpE,MAAM,IAAI,MAAM,gIAAgI,QAAQ;AAC1J;AACA,SAAS,cAAc,KAAK;CAC1B,IAAI,MAAM;CACV,IAAI,4CAA4C,kCAAkC;CAClF,IAAI,CAAC,OAAO,OAAO,QAAQ,UAAU,OAAO;CAC5C,IAAI,SAAS;CACb,QAAQ,QAAQ,SAAS,mCAAmC,OAAO,8BAA8B,QAAQ,qCAAqC,KAAK,IAAI,KAAK,KAAK,6CAA6C,iCAAiC,eAAe,QAAQ,+CAA+C,KAAK,IAAI,KAAK,IAAI,2CAA2C,UAAU,QAAQ,UAAU,KAAK,IAAI,SAAS,oBAAoB,OAAO,eAAe,QAAQ,sBAAsB,KAAK,IAAI,KAAK,IAAI,kBAAkB,UAAU,QAAQ,SAAS,KAAK,IAAI,OAAO;AACzjB;AACA,SAAS,kBAAkB,KAAK;CAC9B,IAAI,SAAS,QAAQ,QAAQ,QAAQ,KAAK,IAAI,KAAK,IAAI,IAAI;CAC3D,OAAO,CAAC,EAAE,WAAW,QAAQ,WAAW,KAAK,IAAI,KAAK,IAAI,OAAO,oBAAoB,eAAe,OAAO;AAC7G;AACA,SAAS,KAAK,KAAK,OAAO;CACxB,IAAI,UAAU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U,SAAS,KAAK,UAAU,OAAO,KAAK,IAAI,UAAU,KAAK;CAC/E,IAAI;CACJ,IAAI,OAAO,qBAAqB,OAAO;CACvC,OAAO;EACL,GAAG,MAAM;EACT,GAAG,QAAQ,eAAe,MAAM,WAAW,QAAQ,iBAAiB,KAAK,IAAI,KAAK,IAAI,aAAa,QAAQ,KAAK;CAClH;AACF;AACA,SAAS,aAAa,IAAI;CACxB,IAAI,CAAC,QAAQ,OAAO;CACpB,OAAO,OAAO,aAAa,EAAE;AAC/B;AACA,SAAS,WAAW;CAClB,IAAI,CAAC,QAAQ,OAAO;EAClB,WAAW;EACX,aAAa;EACb,WAAW;CACb;CACA,OAAO;EACL,WAAW,OAAO,aAAa;EAC/B,aAAa,OAAO,eAAe;EACnC,WAAW,OAAO,aAAa;CACjC;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/native-registry",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.11",
|
|
4
4
|
"description": "Generic native style registry: zero-re-render style updates via Fabric ShadowTree commits",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@tamagui/build": "3.0.
|
|
49
|
+
"@tamagui/build": "3.0.11",
|
|
50
50
|
"react": "19.2.3",
|
|
51
51
|
"react-native": "0.87.1",
|
|
52
52
|
"react-native-nitro-modules": "0.37.1",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"publishConfig": {
|
|
78
78
|
"access": "public"
|
|
79
79
|
},
|
|
80
|
-
"releaseSourceCommit": "
|
|
80
|
+
"releaseSourceCommit": "2126db6e1f5389c724e21f06ce7d7e7d9f49f4aa"
|
|
81
81
|
}
|
package/src/index.native.ts
CHANGED
|
@@ -75,10 +75,15 @@ function getEngine(): Engine {
|
|
|
75
75
|
* Same internals access as Unistyles; verified against RN 0.86.
|
|
76
76
|
*/
|
|
77
77
|
function getShadowNode(ref: unknown): unknown | null {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
if (!ref || typeof ref !== 'object') return null
|
|
79
|
+
const record = ref as {
|
|
80
|
+
__internalInstanceHandle?: { stateNode?: { node?: unknown } }
|
|
81
|
+
stateNode?: { node?: unknown }
|
|
82
|
+
}
|
|
83
|
+
// a host ref, or the fiber a discovery walk passes straight through
|
|
84
|
+
return (
|
|
85
|
+
record.__internalInstanceHandle?.stateNode?.node ?? record.stateNode?.node ?? null
|
|
86
|
+
)
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"mappings": "AAOA,cACE,YACA,eAEA,WACA,mBACA,uBACK;AAQP,cACE,YACA,eACA,QACA,WACA,mBACA,uBACK;AACP,SAAS,YAAY,4BAA4B;AACjD,SAAS,0BAA0B;AA6BnC,OAAO,iBAAS;;;;;;;;;;;;
|
|
2
|
+
"mappings": "AAOA,cACE,YACA,eAEA,WACA,mBACA,uBACK;AAQP,cACE,YACA,eACA,QACA,WACA,mBACA,uBACK;AACP,SAAS,YAAY,4BAA4B;AACjD,SAAS,0BAA0B;AA6BnC,OAAO,iBAAS;;;;;;;;;;;;AAmDhB,OAAO,iBAAS,KACd,cACA,OAAO,oBACP,kBACA,sBACC;;;;;;;;AAyBH,OAAO,iBAAS,WACd,iBACA,oBACA,wBACA;;AAUF,OAAO,iBAAS,OAAO;;;;;;AASvB,OAAO,iBAAS,gBAAgB,SAAS;;;;;;AAUzC,OAAO,iBAAS,cACd,iBACA,eACA,OAAO;;;;;;AAUT,OAAO,iBAAS,aAAa,mBAAmB;AAKhD,OAAO,iBAAS,YAAY;;AAM5B,OAAO,iBAAS,aACd,OAAO,WACP,mBACC;;AASH,OAAO,iBAAS,aAAa,aAAa;AAK1C,OAAO,iBAAS,YAAY",
|
|
3
3
|
"names": [],
|
|
4
4
|
"sources": [
|
|
5
5
|
"src/index.native.ts"
|
|
6
6
|
],
|
|
7
7
|
"version": 3,
|
|
8
8
|
"sourcesContent": [
|
|
9
|
-
"/**\n * Native implementation backed by the TamaguiRegistry Nitro HybridObject.\n * The C++ engine commits style updates directly to Fabric's ShadowTree via\n * UIManager::updateShadowTree (RN >= 0.81), with zero React re-renders.\n */\nimport { NitroModules } from 'react-native-nitro-modules'\nimport type { TamaguiRegistry } from './specs/TamaguiRegistry.nitro'\nimport type {\n LinkHandle,\n RegistryStats,\n Unlink,\n ViewSlots,\n ViewStateSnapshot,\n ViewStateUpdate,\n} from './types'\nimport {\n ROOT_SCOPE,\n getMirroredStateName,\n removeMirroredScope,\n setMirroredStateName,\n} from './mirror'\n\nexport type {\n LinkHandle,\n RegistryStats,\n Unlink,\n ViewSlots,\n ViewStateSnapshot,\n ViewStateUpdate,\n} from './types'\nexport { ROOT_SCOPE, getMirroredStateName } from './mirror'\nexport { processStyleColors } from './processStyleColors.native'\n\n/** Full engine surface: typed Nitro methods plus the raw-JSI methods. */\ninterface Engine extends TamaguiRegistry {\n link(\n shadowNode: unknown,\n table: ViewSlots | number,\n scopeId: string,\n commitNow: boolean\n ): number\n linkTables(\n shadowNodes: unknown[],\n tableIds: number[],\n scopeIndexes: number[],\n scopes: string[]\n ): void\n applyViewStates(entries: ViewStateUpdate[]): void\n setTableState(tableId: number, state: string, props: Record<string, unknown>): void\n getViewState(id: number): ViewStateSnapshot | null\n}\n\nlet engine: Engine | null = null\nlet initError: unknown = null\ntry {\n engine = NitroModules.createHybridObject<TamaguiRegistry>('TamaguiRegistry') as Engine\n} catch (error) {\n initError = error\n}\n\nexport function isAvailable(): boolean {\n return engine !== null\n}\n\nfunction getEngine(): Engine {\n if (engine) return engine\n const detail = initError instanceof Error ? ` ${initError.message}` : ''\n throw new Error(\n `[@tamagui/native-registry] TamaguiRegistry failed to initialize; is react-native-nitro-modules installed and the app rebuilt?${detail}`\n )\n}\n\n/**\n * Extract the opaque ShadowNode JSI wrapper from a Fabric host component ref.\n * Same internals access as Unistyles; verified against RN 0.86.\n */\nfunction getShadowNode(ref: unknown): unknown | null {\n const
|
|
9
|
+
"/**\n * Native implementation backed by the TamaguiRegistry Nitro HybridObject.\n * The C++ engine commits style updates directly to Fabric's ShadowTree via\n * UIManager::updateShadowTree (RN >= 0.81), with zero React re-renders.\n */\nimport { NitroModules } from 'react-native-nitro-modules'\nimport type { TamaguiRegistry } from './specs/TamaguiRegistry.nitro'\nimport type {\n LinkHandle,\n RegistryStats,\n Unlink,\n ViewSlots,\n ViewStateSnapshot,\n ViewStateUpdate,\n} from './types'\nimport {\n ROOT_SCOPE,\n getMirroredStateName,\n removeMirroredScope,\n setMirroredStateName,\n} from './mirror'\n\nexport type {\n LinkHandle,\n RegistryStats,\n Unlink,\n ViewSlots,\n ViewStateSnapshot,\n ViewStateUpdate,\n} from './types'\nexport { ROOT_SCOPE, getMirroredStateName } from './mirror'\nexport { processStyleColors } from './processStyleColors.native'\n\n/** Full engine surface: typed Nitro methods plus the raw-JSI methods. */\ninterface Engine extends TamaguiRegistry {\n link(\n shadowNode: unknown,\n table: ViewSlots | number,\n scopeId: string,\n commitNow: boolean\n ): number\n linkTables(\n shadowNodes: unknown[],\n tableIds: number[],\n scopeIndexes: number[],\n scopes: string[]\n ): void\n applyViewStates(entries: ViewStateUpdate[]): void\n setTableState(tableId: number, state: string, props: Record<string, unknown>): void\n getViewState(id: number): ViewStateSnapshot | null\n}\n\nlet engine: Engine | null = null\nlet initError: unknown = null\ntry {\n engine = NitroModules.createHybridObject<TamaguiRegistry>('TamaguiRegistry') as Engine\n} catch (error) {\n initError = error\n}\n\nexport function isAvailable(): boolean {\n return engine !== null\n}\n\nfunction getEngine(): Engine {\n if (engine) return engine\n const detail = initError instanceof Error ? ` ${initError.message}` : ''\n throw new Error(\n `[@tamagui/native-registry] TamaguiRegistry failed to initialize; is react-native-nitro-modules installed and the app rebuilt?${detail}`\n )\n}\n\n/**\n * Extract the opaque ShadowNode JSI wrapper from a Fabric host component ref.\n * Same internals access as Unistyles; verified against RN 0.86.\n */\nfunction getShadowNode(ref: unknown): unknown | null {\n if (!ref || typeof ref !== 'object') return null\n const record = ref as {\n __internalInstanceHandle?: { stateNode?: { node?: unknown } }\n stateNode?: { node?: unknown }\n }\n // a host ref, or the fiber a discovery walk passes straight through\n return (\n record.__internalInstanceHandle?.stateNode?.node ?? record.stateNode?.node ?? null\n )\n}\n\n/**\n * Nitro hybrid views parse props only from JSI values (their component\n * descriptor uses the JSI RawPropsParser), so the folly props this engine\n * commits, like React Native's own setNativeProps, abort in them. Every\n * Nitro view declares its `hybridRef` prop; those hosts stay unlinked and\n * re-theme through React renders.\n */\nfunction isNitroHybridView(ref: unknown): boolean {\n const config = (ref as { __viewConfig?: { validAttributes?: object } })?.__viewConfig\n return !!config?.validAttributes && 'hybridRef' in config.validAttributes\n}\n\n/**\n * Link a mounted view to the engine. Captures the ShadowNode once, returns\n * a handle keyed by the engine-issued id: unlink never re-derives anything\n * from the ref, so a torn-down ref cannot leave a stale entry behind.\n *\n * `table` is either the view's own slots or the id of a shared table filled\n * by setTableState; every view of one compiler mapping links the same table,\n * so linking sends no props at all. `commitNow` commits the view's active\n * state once, for a host whose render raced a scope change. Props arrive in\n * engine form, already through processStyleColors.\n */\nexport function link(\n ref: unknown,\n table: ViewSlots | number,\n scopeId: string = ROOT_SCOPE,\n commitNow = false\n): LinkHandle | null {\n if (isNitroHybridView(ref)) return null\n const node = getShadowNode(ref)\n if (!node) return null\n\n const e = getEngine()\n const id = e.link(node, table, scopeId, commitNow)\n let unlinked = false\n return {\n id,\n unlink: () => {\n if (unlinked) return\n unlinked = true\n e.unlink(id)\n },\n }\n}\n\n/**\n * Link many host views to shared tables in one native call. Entry i links\n * refs[i] to table tableIds[i] under scope scopes[scopeIndexes[i]]. A host\n * already linked to a table moves to its new entry, and the engine drops\n * linked views that left the tree, so table links need no unlink. The refs\n * are React Native host components (never Nitro views, see link).\n */\nexport function linkTables(\n refs: unknown[],\n tableIds: number[],\n scopeIndexes: number[],\n scopes: string[]\n): void {\n const nodes = new Array(refs.length)\n for (let i = 0; i < refs.length; i++) {\n nodes[i] = getShadowNode(refs[i])\n }\n getEngine().linkTables(nodes, tableIds, scopeIndexes, scopes)\n}\n\n/** Unlink by an id from link. Safe to call twice. */\nexport function unlink(id: number): void {\n getEngine().unlink(id)\n}\n\n/**\n * Batched per-view state selection: cold entries carry `props` (computed by\n * the caller, colors already processed via processStyleColors), warm entries\n * just name the state. One native commit for the whole batch.\n */\nexport function applyViewStates(entries: ViewStateUpdate[]): void {\n if (entries.length === 0) return\n getEngine().applyViewStates(entries)\n}\n\n/**\n * Fill one state of a shared table. Every view linked to the table reads it;\n * views already showing that state commit the new props. Props arrive in\n * engine form, already through processStyleColors.\n */\nexport function setTableState(\n tableId: number,\n state: string,\n props: Record<string, unknown>\n): void {\n getEngine().setTableState(tableId, state, props)\n}\n\n/**\n * Set the active state name (e.g. theme name) for a scope and commit the\n * update natively. The JS mirror updates first so any concurrent React\n * render paints the same styles the engine commits.\n */\nexport function setStateName(stateName: string, scopeId: string = ROOT_SCOPE): void {\n setMirroredStateName(scopeId, stateName)\n getEngine().setStateName(scopeId, stateName)\n}\n\nexport function removeScope(scopeId: string): void {\n removeMirroredScope(scopeId)\n getEngine().removeScope(scopeId)\n}\n\n/** Resolve the props a view should render right now, mirror-consistent. */\nexport function resolveSlots(\n slots: ViewSlots,\n scopeId: string = ROOT_SCOPE\n): Record<string, unknown> {\n const name = getMirroredStateName(scopeId)\n return {\n ...slots.base,\n ...(name ? slots.state?.[name] : undefined),\n }\n}\n\n/** Debug/test introspection of a linked view's engine tables. Not a hot path. */\nexport function getViewState(id: number): ViewStateSnapshot | null {\n if (!engine) return null\n return engine.getViewState(id)\n}\n\nexport function getStats(): RegistryStats {\n if (!engine) return { viewCount: 0, commitCount: 0, missCount: 0 }\n return {\n viewCount: engine.getViewCount(),\n commitCount: engine.getCommitCount(),\n missCount: engine.getMissCount(),\n }\n}\n"
|
|
10
10
|
]
|
|
11
11
|
}
|