16
let createReactClass;
17
let createReactNativeComponentClass;
18
let UIManager;
19
-let FabricUIManager;
19
let StrictMode;
20
let NativeMethodsMixin;
21
30
beforeEach(() => {
31
jest.resetModules();
32
33
+ require('react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager');
34
+
35
React = require('react');
36
StrictMode = React.StrictMode;
37
ReactFeatureFlags = require('shared/ReactFeatureFlags');
38
ReactFeatureFlags.warnAboutDeprecatedSetNativeProps = true;
39
ReactFabric = require('react-native-renderer/fabric');
39
- FabricUIManager = require('FabricUIManager');
40
- UIManager = require('UIManager');
40
+ UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
41
+ .UIManager;
42
createReactClass = require('create-react-class/factory')(
43
React.Component,
44
React.isValidElement,
45
new React.Component().updater,
46
);
46
- createReactNativeComponentClass = require('ReactNativeViewConfigRegistry')
47
- .register;
47
+ createReactNativeComponentClass = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
48
+ .ReactNativeViewConfigRegistry.register;
49
NativeMethodsMixin =
50
ReactFabric.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
51
.NativeMethodsMixin;
51
-
52
- global.nativeFabricUIManager = {
53
- measure: FabricUIManager.measure,
54
- measureInWindow: FabricUIManager.measureInWindow,
55
- };
52
});
53
54
it('should be able to create and render a native component', () => {
58
}));
59
60
ReactFabric.render(<View foo="test" />, 1);
65
- expect(FabricUIManager.createNode).toBeCalled();
66
- expect(FabricUIManager.appendChild).not.toBeCalled();
67
- expect(FabricUIManager.completeRoot).toBeCalled();
61
+ expect(nativeFabricUIManager.createNode).toBeCalled();
62
+ expect(nativeFabricUIManager.appendChild).not.toBeCalled();
63
+ expect(nativeFabricUIManager.completeRoot).toBeCalled();
64
});
65
66
it('should be able to create and update a native component', () => {
71
72
const firstNode = {};
73
78
- FabricUIManager.createNode.mockReturnValue(firstNode);
74
+ nativeFabricUIManager.createNode.mockReturnValue(firstNode);
75
76
ReactFabric.render(<View foo="foo" />, 11);
77
82
- expect(FabricUIManager.createNode).toHaveBeenCalledTimes(1);
78
+ expect(nativeFabricUIManager.createNode).toHaveBeenCalledTimes(1);
79
80
ReactFabric.render(<View foo="bar" />, 11);
81
86
- expect(FabricUIManager.createNode).toHaveBeenCalledTimes(1);
87
- expect(FabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(1);
88
- expect(FabricUIManager.cloneNodeWithNewProps.mock.calls[0][0]).toBe(
82
+ expect(nativeFabricUIManager.createNode).toHaveBeenCalledTimes(1);
83
+ expect(nativeFabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(
84
+ 1,
85
+ );
86
+ expect(nativeFabricUIManager.cloneNodeWithNewProps.mock.calls[0][0]).toBe(
87
firstNode,
88
);
91
- expect(FabricUIManager.cloneNodeWithNewProps.mock.calls[0][1]).toEqual({
89
+ expect(
90
+ nativeFabricUIManager.cloneNodeWithNewProps.mock.calls[0][1],
91
+ ).toEqual({
92
foo: 'bar',
93
});
94
});
100
}));
101
102
ReactFabric.render(<Text foo="a">1</Text>, 11);
103
- expect(FabricUIManager.cloneNode).not.toBeCalled();
104
- expect(FabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
105
- expect(FabricUIManager.cloneNodeWithNewProps).not.toBeCalled();
106
- expect(FabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
103
+ expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
104
+ expect(nativeFabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
105
+ expect(nativeFabricUIManager.cloneNodeWithNewProps).not.toBeCalled();
106
+ expect(
107
+ nativeFabricUIManager.cloneNodeWithNewChildrenAndProps,
108
+ ).not.toBeCalled();
109
110
// If no properties have changed, we shouldn't call cloneNode.
111
ReactFabric.render(<Text foo="a">1</Text>, 11);
110
- expect(FabricUIManager.cloneNode).not.toBeCalled();
111
- expect(FabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
112
- expect(FabricUIManager.cloneNodeWithNewProps).not.toBeCalled();
113
- expect(FabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
112
+ expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
113
+ expect(nativeFabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
114
+ expect(nativeFabricUIManager.cloneNodeWithNewProps).not.toBeCalled();
115
+ expect(
116
+ nativeFabricUIManager.cloneNodeWithNewChildrenAndProps,
117
+ ).not.toBeCalled();
118
119
// Only call cloneNode for the changed property (and not for text).
120
ReactFabric.render(<Text foo="b">1</Text>, 11);
117
- expect(FabricUIManager.cloneNode).not.toBeCalled();
118
- expect(FabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
119
- expect(FabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(1);
120
- expect(FabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
121
+ expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
122
+ expect(nativeFabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
123
+ expect(nativeFabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(
124
+ 1,
125
+ );
126
+ expect(
127
+ nativeFabricUIManager.cloneNodeWithNewChildrenAndProps,
128
+ ).not.toBeCalled();
129
130
// Only call cloneNode for the changed text (and no other properties).
131
ReactFabric.render(<Text foo="b">2</Text>, 11);
124
- expect(FabricUIManager.cloneNode).not.toBeCalled();
125
- expect(FabricUIManager.cloneNodeWithNewChildren).toHaveBeenCalledTimes(1);
126
- expect(FabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(1);
127
- expect(FabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
132
+ expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
133
+ expect(
134
+ nativeFabricUIManager.cloneNodeWithNewChildren,
135
+ ).toHaveBeenCalledTimes(1);
136
+ expect(nativeFabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(
137
+ 1,
138
+ );
139
+ expect(
140
+ nativeFabricUIManager.cloneNodeWithNewChildrenAndProps,
141
+ ).not.toBeCalled();
142
143
// Call cloneNode for both changed text and properties.
144
ReactFabric.render(<Text foo="c">3</Text>, 11);
131
- expect(FabricUIManager.cloneNode).not.toBeCalled();
132
- expect(FabricUIManager.cloneNodeWithNewChildren).toHaveBeenCalledTimes(1);
133
- expect(FabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(1);
145
+ expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
146
expect(
135
- FabricUIManager.cloneNodeWithNewChildrenAndProps,
147
+ nativeFabricUIManager.cloneNodeWithNewChildren,
148
+ ).toHaveBeenCalledTimes(1);
149
+ expect(nativeFabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(
150
+ 1,
151
+ );
152
+ expect(
153
+ nativeFabricUIManager.cloneNodeWithNewChildrenAndProps,
154
).toHaveBeenCalledTimes(1);
155
});
156
166
</Text>,
167
11,
168
);
151
- expect(FabricUIManager.cloneNode).not.toBeCalled();
152
- expect(FabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
153
- expect(FabricUIManager.cloneNodeWithNewProps).not.toBeCalled();
154
- expect(FabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
169
+ expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
170
+ expect(nativeFabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
171
+ expect(nativeFabricUIManager.cloneNodeWithNewProps).not.toBeCalled();
172
+ expect(
173
+ nativeFabricUIManager.cloneNodeWithNewChildrenAndProps,
174
+ ).not.toBeCalled();
175
176
ReactFabric.render(
177
<Text foo="a" bar="b">
179
</Text>,
180
11,
181
);
162
- expect(FabricUIManager.cloneNodeWithNewProps.mock.calls[0][1]).toEqual({
182
+ expect(
183
+ nativeFabricUIManager.cloneNodeWithNewProps.mock.calls[0][1],
184
+ ).toEqual({
185
bar: 'b',
186
});
165
- expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
187
+ expect(
188
+ nativeFabricUIManager.__dumpHierarchyForJestTestsOnly(),
189
+ ).toMatchSnapshot();
190
191
ReactFabric.render(
192
<Text foo="b" bar="b">
195
11,
196
);
197
expect(
174
- FabricUIManager.cloneNodeWithNewChildrenAndProps.mock.calls[0][1],
198
+ nativeFabricUIManager.cloneNodeWithNewChildrenAndProps.mock.calls[0][1],
199
).toEqual({
200
foo: 'b',
201
});
178
- expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
202
+ expect(
203
+ nativeFabricUIManager.__dumpHierarchyForJestTestsOnly(),
204
+ ).toMatchSnapshot();
205
});
206
207
it('should not call UIManager.updateView from ref.setNativeProps', () => {
353
});
354
355
[View, Subclass, CreateClass].forEach(Component => {
330
- FabricUIManager.measure.mockClear();
356
+ nativeFabricUIManager.measure.mockClear();
357
358
let viewRef;
359
ReactFabric.render(
365
11,
366
);
367
342
- expect(FabricUIManager.measure).not.toBeCalled();
368
+ expect(nativeFabricUIManager.measure).not.toBeCalled();
369
const successCallback = jest.fn();
370
viewRef.measure(successCallback);
345
- expect(FabricUIManager.measure).toHaveBeenCalledTimes(1);
371
+ expect(nativeFabricUIManager.measure).toHaveBeenCalledTimes(1);
372
expect(successCallback).toHaveBeenCalledTimes(1);
373
expect(successCallback).toHaveBeenCalledWith(10, 10, 100, 100, 0, 0);
374
});
394
});
395
396
[View, Subclass, CreateClass].forEach(Component => {
371
- FabricUIManager.measureInWindow.mockClear();
397
+ nativeFabricUIManager.measureInWindow.mockClear();
398
399
let viewRef;
400
ReactFabric.render(
406
11,
407
);
408
383
- expect(FabricUIManager.measureInWindow).not.toBeCalled();
409
+ expect(nativeFabricUIManager.measureInWindow).not.toBeCalled();
410
const successCallback = jest.fn();
411
viewRef.measureInWindow(successCallback);
386
- expect(FabricUIManager.measureInWindow).toHaveBeenCalledTimes(1);
412
+ expect(nativeFabricUIManager.measureInWindow).toHaveBeenCalledTimes(1);
413
expect(successCallback).toHaveBeenCalledTimes(1);
414
expect(successCallback).toHaveBeenCalledWith(10, 10, 100, 100);
415
});
422
}));
423
424
[View].forEach(Component => {
399
- FabricUIManager.measureLayout.mockClear();
425
+ nativeFabricUIManager.measureLayout.mockClear();
426
427
let viewRef;
428
let otherRef;
443
11,
444
);
445
420
- expect(FabricUIManager.measureLayout).not.toBeCalled();
446
+ expect(nativeFabricUIManager.measureLayout).not.toBeCalled();
447
const successCallback = jest.fn();
448
const failureCallback = jest.fn();
449
viewRef.measureLayout(otherRef, successCallback, failureCallback);
424
- expect(FabricUIManager.measureLayout).toHaveBeenCalledTimes(1);
450
+ expect(nativeFabricUIManager.measureLayout).toHaveBeenCalledTimes(1);
451
expect(successCallback).toHaveBeenCalledTimes(1);
452
expect(successCallback).toHaveBeenCalledWith(1, 1, 100, 100);
453
});
473
});
474
475
[Subclass, CreateClass].forEach(Component => {
450
- FabricUIManager.measureLayout.mockReset();
476
+ nativeFabricUIManager.measureLayout.mockReset();
477
478
let viewRef;
479
let otherRef;
510
},
511
);
512
487
- expect(FabricUIManager.measureLayout).not.toBeCalled();
513
+ expect(nativeFabricUIManager.measureLayout).not.toBeCalled();
514
expect(UIManager.measureLayout).not.toBeCalled();
515
});
516
});
556
const after = 'mxhpgwfralkeoivcstzy';
557
558
ReactFabric.render(<Component chars={before} />, 11);
533
- expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
559
+ expect(
560
+ nativeFabricUIManager.__dumpHierarchyForJestTestsOnly(),
561
+ ).toMatchSnapshot();
562
563
ReactFabric.render(<Component chars={after} />, 11);
536
- expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
564
+ expect(
565
+ nativeFabricUIManager.__dumpHierarchyForJestTestsOnly(),
566
+ ).toMatchSnapshot();
567
});
568
569
it('recreates host parents even if only children changed', () => {
595
</View>,
596
11,
597
);
568
- expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
598
+ expect(
599
+ nativeFabricUIManager.__dumpHierarchyForJestTestsOnly(),
600
+ ).toMatchSnapshot();
601
602
// Call setState() so that we skip over the top-level host node.
603
// It should still get recreated despite a bailout.
604
ref.current.setState({
605
chars: after,
606
});
575
- expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
607
+ expect(
608
+ nativeFabricUIManager.__dumpHierarchyForJestTestsOnly(),
609
+ ).toMatchSnapshot();
610
});
611
612
it('calls setState with no arguments', () => {
631
}));
632
633
const snapshots = [];
600
- FabricUIManager.completeRoot.mockImplementation(function(
634
+ nativeFabricUIManager.completeRoot.mockImplementation(function(
635
rootTag,
636
newChildSet,
637
) {
638
snapshots.push(
605
- FabricUIManager.__dumpChildSetForJestTestsOnly(newChildSet),
639
+ nativeFabricUIManager.__dumpChildSetForJestTestsOnly(newChildSet),
640
);
641
});
642
738
739
ReactFabric.render(<View onTouchStart={touchStart} />, 11);
740
707
- expect(FabricUIManager.createNode.mock.calls.length).toBe(1);
708
- expect(FabricUIManager.registerEventHandler.mock.calls.length).toBe(1);
741
+ expect(nativeFabricUIManager.createNode.mock.calls.length).toBe(1);
742
+ expect(nativeFabricUIManager.registerEventHandler.mock.calls.length).toBe(
743
+ 1,
744
+ );
745
710
- let [, , , , instanceHandle] = FabricUIManager.createNode.mock.calls[0];
711
- let [dispatchEvent] = FabricUIManager.registerEventHandler.mock.calls[0];
746
+ let [
747
+ ,
748
+ ,
749
+ ,
750
+ ,
751
+ instanceHandle,
752
+ ] = nativeFabricUIManager.createNode.mock.calls[0];
753
+ let [
754
+ dispatchEvent,
755
+ ] = nativeFabricUIManager.registerEventHandler.mock.calls[0];
756
757
let touchEvent = {
758
touches: [],