Skip to content

Commit 3d11b18

Browse files
author
Brian Vaughn
committed
Adds new, fiber-based renderer for native dubbed ReactNativeFiber.
Existing native renderer has been renamed to ReactNativeStack and a new flags file ReactNativeFeatureFlags has been added to switch between the 2 renderers.
1 parent 0a3256a commit 3d11b18

14 files changed

+590
-80
lines changed

flow/react-native-host-hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ declare module 'deepFreezeAndThrowOnMutationInDev' {
1818
declare function exports<T>(obj : T) : T;
1919
}
2020
declare module 'flattenStyle' { }
21-
declare module 'InitializeJavaScriptAppEngine' { }
21+
declare module 'InitializeCore' { }
2222
declare module 'RCTEventEmitter' {
2323
declare function register() : void;
2424
}

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ var moduleMapReactNative = Object.assign(
145145
deepDiffer: 'react-native/lib/deepDiffer',
146146
deepFreezeAndThrowOnMutationInDev: 'react-native/lib/deepFreezeAndThrowOnMutationInDev',
147147
flattenStyle: 'react-native/lib/flattenStyle',
148-
InitializeJavaScriptAppEngine: 'react-native/lib/InitializeJavaScriptAppEngine',
148+
InitializeCore: 'react-native/lib/InitializeCore',
149149
RCTEventEmitter: 'react-native/lib/RCTEventEmitter',
150150
TextInputState: 'react-native/lib/TextInputState',
151151
UIManager: 'react-native/lib/UIManager',

src/renderers/native/ReactNative.js

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,8 @@
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');
14+
const ReactNativeFeatureFlags = require('ReactNativeFeatureFlags');
1915

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;
16+
module.exports = ReactNativeFeatureFlags.useFiber
17+
? require('ReactNativeFiber')
18+
: require('ReactNativeStack');

src/renderers/native/ReactNativeComponentTree.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,41 @@ 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) {
43-
var tag = inst._rootNodeID;
47+
// TODO (bvaughn) Clean up once Stack is deprecated
48+
var tag = inst._rootNodeID || inst.stateNode._nativeTag;
4449
if (tag) {
4550
delete instanceCache[tag];
4651
}
4752
}
4853

54+
function uncacheFiberNode(tag) {
55+
delete instanceCache[tag];
56+
}
57+
4958
function getInstanceFromTag(tag) {
5059
return instanceCache[tag] || null;
5160
}
5261

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

5869
var ReactNativeComponentTree = {
5970
getClosestInstanceFromNode: getInstanceFromTag,
6071
getInstanceFromNode: getInstanceFromTag,
6172
getNodeFromInstance: getTagFromInstance,
62-
precacheNode: precacheNode,
63-
uncacheNode: uncacheNode,
73+
precacheFiberNode,
74+
precacheNode,
75+
uncacheFiberNode,
76+
uncacheNode,
6477
};
6578

6679
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)