-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUIManager.js
206 lines (193 loc) · 5.56 KB
/
UIManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
import type {RootTag} from '../Types/RootTagTypes';
import type {Spec} from './NativeUIManager';
import {getFabricUIManager} from './FabricUIManager';
import nullthrows from 'nullthrows';
export interface UIManagerJSInterface extends Spec {
+getViewManagerConfig: (viewManagerName: string) => Object;
+hasViewManagerConfig: (viewManagerName: string) => boolean;
+createView: (
reactTag: ?number,
viewName: string,
rootTag: RootTag,
props: Object,
) => void;
+updateView: (reactTag: number, viewName: string, props: Object) => void;
+manageChildren: (
containerTag: ?number,
moveFromIndices: Array<number>,
moveToIndices: Array<number>,
addChildReactTags: Array<number>,
addAtIndices: Array<number>,
removeAtIndices: Array<number>,
) => void;
}
function isFabricReactTag(reactTag: number): boolean {
// React reserves even numbers for Fabric.
return reactTag % 2 === 0;
}
const UIManagerImpl: UIManagerJSInterface =
global.RN$Bridgeless === true
? require('./BridgelessUIManager')
: require('./PaperUIManager');
// $FlowFixMe[cannot-spread-interface]
const UIManager = {
...UIManagerImpl,
measure(
reactTag: number,
callback: (
left: number,
top: number,
width: number,
height: number,
pageX: number,
pageY: number,
) => void,
): void {
if (isFabricReactTag(reactTag)) {
const FabricUIManager = nullthrows(getFabricUIManager());
const shadowNode =
FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag);
if (shadowNode) {
FabricUIManager.measure(shadowNode, callback);
} else {
console.warn(`measure cannot find view with tag #${reactTag}`);
// $FlowFixMe[incompatible-call]
callback();
}
} else {
// Paper
UIManagerImpl.measure(reactTag, callback);
}
},
measureInWindow(
reactTag: number,
callback: (
left: number,
top: number,
width: number,
height: number,
) => void,
): void {
if (isFabricReactTag(reactTag)) {
const FabricUIManager = nullthrows(getFabricUIManager());
const shadowNode =
FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag);
if (shadowNode) {
FabricUIManager.measureInWindow(shadowNode, callback);
} else {
console.warn(`measure cannot find view with tag #${reactTag}`);
// $FlowFixMe[incompatible-call]
callback();
}
} else {
// Paper
UIManagerImpl.measureInWindow(reactTag, callback);
}
},
measureLayout(
reactTag: number,
ancestorReactTag: number,
errorCallback: (error: Object) => void,
callback: (
left: number,
top: number,
width: number,
height: number,
) => void,
): void {
if (isFabricReactTag(reactTag)) {
const FabricUIManager = nullthrows(getFabricUIManager());
const shadowNode =
FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag);
const ancestorShadowNode =
FabricUIManager.findShadowNodeByTag_DEPRECATED(ancestorReactTag);
if (!shadowNode || !ancestorShadowNode) {
return;
}
FabricUIManager.measureLayout(
shadowNode,
ancestorShadowNode,
errorCallback,
callback,
);
} else {
// Paper
UIManagerImpl.measureLayout(
reactTag,
ancestorReactTag,
errorCallback,
callback,
);
}
},
measureLayoutRelativeToParent(
reactTag: number,
errorCallback: (error: Object) => void,
callback: (
left: number,
top: number,
width: number,
height: number,
) => void,
): void {
if (isFabricReactTag(reactTag)) {
console.warn(
'RCTUIManager.measureLayoutRelativeToParent method is deprecated and it will not be implemented in newer versions of RN (Fabric) - T47686450',
);
const FabricUIManager = nullthrows(getFabricUIManager());
const shadowNode =
FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag);
if (shadowNode) {
FabricUIManager.measure(
shadowNode,
(left, top, width, height, pageX, pageY) => {
callback(left, top, width, height);
},
);
}
} else {
// Paper
UIManagerImpl.measureLayoutRelativeToParent(
reactTag,
errorCallback,
callback,
);
}
},
dispatchViewManagerCommand(
reactTag: number,
commandName: number | string,
commandArgs: any[],
) {
if (isFabricReactTag(reactTag)) {
const FabricUIManager = nullthrows(getFabricUIManager());
const shadowNode =
FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag);
if (shadowNode) {
// Transform the accidental CommandID into a CommandName which is the stringified number.
// The interop layer knows how to convert this number into the right method name.
// Stringify a string is a no-op, so it's safe.
commandName = `${commandName}`;
FabricUIManager.dispatchCommand(shadowNode, commandName, commandArgs);
}
} else {
UIManagerImpl.dispatchViewManagerCommand(
reactTag,
// We have some legacy components that are actually already using strings. ¯\_(ツ)_/¯
// $FlowFixMe[incompatible-call]
commandName,
commandArgs,
);
}
},
};
module.exports = UIManager;