1 |
|
2 | 'use strict';
|
3 |
|
4 | import { processColorsInProps } from "./Colors.js";
|
5 | import { _updatePropsJS } from "./js-reanimated/index.js";
|
6 | import { isFabric, isJest, shouldBeUseWeb } from "./PlatformChecker.js";
|
7 | import { runOnUIImmediately } from "./threads.js";
|
8 | import { ReanimatedError } from "./errors.js";
|
9 | let updateProps;
|
10 | if (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 | }
|
27 | export 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 | };
|
37 | export default updateProps;
|
38 | const createUpdatePropsManager = isFabric() ? () => {
|
39 | 'worklet';
|
40 |
|
41 |
|
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 |
|
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 | };
|
84 | if (shouldBeUseWeb()) {
|
85 | const maybeThrowError = () => {
|
86 |
|
87 |
|
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 |
|
109 |
|
110 |
|
111 |
|
\ | No newline at end of file |