Skip to content

Commit ab72f62

Browse files
authored
Merge pull request #8560 from bvaughn/react-native-fiber
ReactNative fiber renderer
2 parents ac24197 + 5266ca9 commit ab72f62

13 files changed

+650
-82
lines changed

flow/react-native-host-hooks.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,35 @@ declare module 'TextInputState' {
2929
declare module 'UIManager' {
3030
declare var customBubblingEventTypes : Object;
3131
declare var customDirectEventTypes : Object;
32-
declare function createView() : void;
33-
declare function manageChildren() : void;
32+
declare function createView(
33+
reactTag : number,
34+
viewName : string,
35+
rootTag : number,
36+
props : ?Object,
37+
) : void;
38+
declare function manageChildren(
39+
containerTag : number,
40+
moveFromIndices : Array<number>,
41+
moveToIndices : Array<number>,
42+
addChildReactTags : Array<number>,
43+
addAtIndices : Array<number>,
44+
removeAtIndices : Array<number>
45+
) : void;
3446
declare function measure() : void;
3547
declare function measureInWindow() : void;
3648
declare function measureLayout() : void;
3749
declare function removeRootView() : void;
3850
declare function removeSubviewsFromContainerWithID() : void;
3951
declare function replaceExistingNonRootView() : void;
40-
declare function setChildren() : void;
41-
declare function updateView() : void;
52+
declare function setChildren(
53+
containerTag : number,
54+
reactTags : Array<number>,
55+
) : void;
56+
declare function updateView(
57+
reactTag : number,
58+
viewName : string,
59+
props : ?Object,
60+
) : void;
4261
}
4362
declare module 'View' {
4463
declare var exports : typeof ReactComponent;

src/renderers/native/NativeMethodsMixin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ var NativeMethodsMixin = {
150150
);
151151

152152
UIManager.updateView(
153-
findNodeHandle(this),
153+
(findNodeHandle(this) : any),
154154
this.viewConfig.uiViewClassName,
155155
updatePayload
156156
);

src/renderers/native/ReactNative.js

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,5 @@
1111
*/
1212
'use strict';
1313

14-
// Require ReactNativeDefaultInjection first for its side effects of setting up
15-
// the JS environment
16-
var ReactNativeComponentTree = require('ReactNativeComponentTree');
17-
var ReactNativeInjection = require('ReactNativeInjection');
18-
var ReactNativeStackInjection = require('ReactNativeStackInjection');
19-
20-
var ReactNativeMount = require('ReactNativeMount');
21-
var ReactUpdates = require('ReactUpdates');
22-
23-
var findNodeHandle = require('findNodeHandle');
24-
25-
ReactNativeInjection.inject();
26-
ReactNativeStackInjection.inject();
27-
28-
var render = function(
29-
element: ReactElement<any>,
30-
mountInto: number,
31-
callback?: ?(() => void)
32-
): ?ReactComponent<any, any, any> {
33-
return ReactNativeMount.renderComponent(element, mountInto, callback);
34-
};
35-
36-
var ReactNative = {
37-
hasReactNativeInitialized: false,
38-
findNodeHandle: findNodeHandle,
39-
render: render,
40-
unmountComponentAtNode: ReactNativeMount.unmountComponentAtNode,
41-
42-
/* eslint-disable camelcase */
43-
unstable_batchedUpdates: ReactUpdates.batchedUpdates,
44-
/* eslint-enable camelcase */
45-
46-
unmountComponentAtNodeAndRemoveContainer: ReactNativeMount.unmountComponentAtNodeAndRemoveContainer,
47-
};
48-
49-
// Inject the runtime into a devtools global hook regardless of browser.
50-
// Allows for debugging when the hook is injected on the page.
51-
/* globals __REACT_DEVTOOLS_GLOBAL_HOOK__ */
52-
if (
53-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
54-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.inject === 'function') {
55-
__REACT_DEVTOOLS_GLOBAL_HOOK__.inject({
56-
ComponentTree: {
57-
getClosestInstanceFromNode: function(node) {
58-
return ReactNativeComponentTree.getClosestInstanceFromNode(node);
59-
},
60-
getNodeFromInstance: function(inst) {
61-
// inst is an internal instance (but could be a composite)
62-
while (inst._renderedComponent) {
63-
inst = inst._renderedComponent;
64-
}
65-
if (inst) {
66-
return ReactNativeComponentTree.getNodeFromInstance(inst);
67-
} else {
68-
return null;
69-
}
70-
},
71-
},
72-
Mount: ReactNativeMount,
73-
Reconciler: require('ReactReconciler'),
74-
});
75-
}
76-
77-
module.exports = ReactNative;
14+
// TODO (bvaughn) Enable Fiber experiement via ReactNativeFeatureFlags
15+
module.exports = require('ReactNativeStack');

src/renderers/native/ReactNativeComponentTree.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,40 @@ function precacheNode(inst, tag) {
3939
instanceCache[tag] = nativeInst;
4040
}
4141

42+
function precacheFiberNode(hostInst, tag) {
43+
instanceCache[tag] = hostInst;
44+
}
45+
4246
function uncacheNode(inst) {
4347
var tag = inst._rootNodeID;
4448
if (tag) {
4549
delete instanceCache[tag];
4650
}
4751
}
4852

53+
function uncacheFiberNode(tag) {
54+
delete instanceCache[tag];
55+
}
56+
4957
function getInstanceFromTag(tag) {
5058
return instanceCache[tag] || null;
5159
}
5260

5361
function getTagFromInstance(inst) {
54-
invariant(inst._rootNodeID, 'All native instances should have a tag.');
55-
return inst._rootNodeID;
62+
// TODO (bvaughn) Clean up once Stack is deprecated
63+
var tag = inst._rootNodeID || inst.stateNode._nativeTag;
64+
invariant(tag, 'All native instances should have a tag.');
65+
return tag;
5666
}
5767

5868
var ReactNativeComponentTree = {
5969
getClosestInstanceFromNode: getInstanceFromTag,
6070
getInstanceFromNode: getInstanceFromTag,
6171
getNodeFromInstance: getTagFromInstance,
62-
precacheNode: precacheNode,
63-
uncacheNode: uncacheNode,
72+
precacheFiberNode,
73+
precacheNode,
74+
uncacheFiberNode,
75+
uncacheNode,
6476
};
6577

6678
module.exports = ReactNativeComponentTree;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright 2013-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @providesModule ReactNativeFeatureFlags
10+
*/
11+
12+
'use strict';
13+
14+
var ReactNativeFeatureFlags = {
15+
useFiber: false,
16+
};
17+
18+
module.exports = ReactNativeFeatureFlags;

0 commit comments

Comments
 (0)