UNPKG

2.96 kBJavaScriptView Raw
1/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
2'use strict';
3
4import { processColorsInProps } from "./Colors.js";
5import { _updatePropsJS } from "./js-reanimated/index.js";
6import { isFabric, isJest, shouldBeUseWeb } from "./PlatformChecker.js";
7import { runOnUIImmediately } from "./threads.js";
8import { ReanimatedError } from "./errors.js";
9let updateProps;
10if (shouldBeUseWeb()) {
11 updateProps = (viewDescriptors, updates, isAnimatedProps) => {
12 'worklet';
13
14 viewDescriptors.value?.forEach(viewDescriptor => {
15 const component = viewDescriptor.tag;
16 _updatePropsJS(updates, component, isAnimatedProps);
17 });
18 };
19} else {
20 updateProps = (viewDescriptors, updates) => {
21 'worklet';
22
23 processColorsInProps(updates);
24 global.UpdatePropsManager.update(viewDescriptors, updates);
25 };
26}
27export const updatePropsJestWrapper = (viewDescriptors, updates, animatedStyle, adapters) => {
28 adapters.forEach(adapter => {
29 adapter(updates);
30 });
31 animatedStyle.current.value = {
32 ...animatedStyle.current.value,
33 ...updates
34 };
35 updateProps(viewDescriptors, updates);
36};
37export default updateProps;
38const createUpdatePropsManager = isFabric() ? () => {
39 'worklet';
40
41 // Fabric
42 const operations = [];
43 return {
44 update(viewDescriptors, updates) {
45 viewDescriptors.value.forEach(viewDescriptor => {
46 operations.push({
47 shadowNodeWrapper: viewDescriptor.shadowNodeWrapper,
48 updates
49 });
50 if (operations.length === 1) {
51 queueMicrotask(this.flush);
52 }
53 });
54 },
55 flush() {
56 global._updatePropsFabric(operations);
57 operations.length = 0;
58 }
59 };
60} : () => {
61 'worklet';
62
63 // Paper
64 const operations = [];
65 return {
66 update(viewDescriptors, updates) {
67 viewDescriptors.value.forEach(viewDescriptor => {
68 operations.push({
69 tag: viewDescriptor.tag,
70 name: viewDescriptor.name || 'RCTView',
71 updates
72 });
73 if (operations.length === 1) {
74 queueMicrotask(this.flush);
75 }
76 });
77 },
78 flush() {
79 global._updatePropsPaper(operations);
80 operations.length = 0;
81 }
82 };
83};
84if (shouldBeUseWeb()) {
85 const maybeThrowError = () => {
86 // Jest attempts to access a property of this object to check if it is a Jest mock
87 // so we can't throw an error in the getter.
88 if (!isJest()) {
89 throw new ReanimatedError('`UpdatePropsManager` is not available on non-native platform.');
90 }
91 };
92 global.UpdatePropsManager = new Proxy({}, {
93 get: maybeThrowError,
94 set: () => {
95 maybeThrowError();
96 return false;
97 }
98 });
99} else {
100 runOnUIImmediately(() => {
101 'worklet';
102
103 global.UpdatePropsManager = createUpdatePropsManager();
104 })();
105}
106
107/**
108 * This used to be `SharedValue<Descriptors[]>` but objects holding just a
109 * single `value` prop are fine too.
110 */
111//# sourceMappingURL=UpdateProps.js.map
\No newline at end of file