Skip to content

Commit

Permalink
Merge pull request facebook#8560 from bvaughn/react-native-fiber
Browse files Browse the repository at this point in the history
ReactNative fiber renderer
  • Loading branch information
bvaughn authored Dec 15, 2016
2 parents ac24197 + 5266ca9 commit ab72f62
Show file tree
Hide file tree
Showing 13 changed files with 650 additions and 82 deletions.
27 changes: 23 additions & 4 deletions flow/react-native-host-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,35 @@ declare module 'TextInputState' {
declare module 'UIManager' {
declare var customBubblingEventTypes : Object;
declare var customDirectEventTypes : Object;
declare function createView() : void;
declare function manageChildren() : void;
declare function createView(
reactTag : number,
viewName : string,
rootTag : number,
props : ?Object,
) : void;
declare function manageChildren(
containerTag : number,
moveFromIndices : Array<number>,
moveToIndices : Array<number>,
addChildReactTags : Array<number>,
addAtIndices : Array<number>,
removeAtIndices : Array<number>
) : void;
declare function measure() : void;
declare function measureInWindow() : void;
declare function measureLayout() : void;
declare function removeRootView() : void;
declare function removeSubviewsFromContainerWithID() : void;
declare function replaceExistingNonRootView() : void;
declare function setChildren() : void;
declare function updateView() : void;
declare function setChildren(
containerTag : number,
reactTags : Array<number>,
) : void;
declare function updateView(
reactTag : number,
viewName : string,
props : ?Object,
) : void;
}
declare module 'View' {
declare var exports : typeof ReactComponent;
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/native/NativeMethodsMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ var NativeMethodsMixin = {
);

UIManager.updateView(
findNodeHandle(this),
(findNodeHandle(this) : any),
this.viewConfig.uiViewClassName,
updatePayload
);
Expand Down
66 changes: 2 additions & 64 deletions src/renderers/native/ReactNative.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,5 @@
*/
'use strict';

// Require ReactNativeDefaultInjection first for its side effects of setting up
// the JS environment
var ReactNativeComponentTree = require('ReactNativeComponentTree');
var ReactNativeInjection = require('ReactNativeInjection');
var ReactNativeStackInjection = require('ReactNativeStackInjection');

var ReactNativeMount = require('ReactNativeMount');
var ReactUpdates = require('ReactUpdates');

var findNodeHandle = require('findNodeHandle');

ReactNativeInjection.inject();
ReactNativeStackInjection.inject();

var render = function(
element: ReactElement<any>,
mountInto: number,
callback?: ?(() => void)
): ?ReactComponent<any, any, any> {
return ReactNativeMount.renderComponent(element, mountInto, callback);
};

var ReactNative = {
hasReactNativeInitialized: false,
findNodeHandle: findNodeHandle,
render: render,
unmountComponentAtNode: ReactNativeMount.unmountComponentAtNode,

/* eslint-disable camelcase */
unstable_batchedUpdates: ReactUpdates.batchedUpdates,
/* eslint-enable camelcase */

unmountComponentAtNodeAndRemoveContainer: ReactNativeMount.unmountComponentAtNodeAndRemoveContainer,
};

// Inject the runtime into a devtools global hook regardless of browser.
// Allows for debugging when the hook is injected on the page.
/* globals __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.inject === 'function') {
__REACT_DEVTOOLS_GLOBAL_HOOK__.inject({
ComponentTree: {
getClosestInstanceFromNode: function(node) {
return ReactNativeComponentTree.getClosestInstanceFromNode(node);
},
getNodeFromInstance: function(inst) {
// inst is an internal instance (but could be a composite)
while (inst._renderedComponent) {
inst = inst._renderedComponent;
}
if (inst) {
return ReactNativeComponentTree.getNodeFromInstance(inst);
} else {
return null;
}
},
},
Mount: ReactNativeMount,
Reconciler: require('ReactReconciler'),
});
}

module.exports = ReactNative;
// TODO (bvaughn) Enable Fiber experiement via ReactNativeFeatureFlags
module.exports = require('ReactNativeStack');
20 changes: 16 additions & 4 deletions src/renderers/native/ReactNativeComponentTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,40 @@ function precacheNode(inst, tag) {
instanceCache[tag] = nativeInst;
}

function precacheFiberNode(hostInst, tag) {
instanceCache[tag] = hostInst;
}

function uncacheNode(inst) {
var tag = inst._rootNodeID;
if (tag) {
delete instanceCache[tag];
}
}

function uncacheFiberNode(tag) {
delete instanceCache[tag];
}

function getInstanceFromTag(tag) {
return instanceCache[tag] || null;
}

function getTagFromInstance(inst) {
invariant(inst._rootNodeID, 'All native instances should have a tag.');
return inst._rootNodeID;
// TODO (bvaughn) Clean up once Stack is deprecated
var tag = inst._rootNodeID || inst.stateNode._nativeTag;
invariant(tag, 'All native instances should have a tag.');
return tag;
}

var ReactNativeComponentTree = {
getClosestInstanceFromNode: getInstanceFromTag,
getInstanceFromNode: getInstanceFromTag,
getNodeFromInstance: getTagFromInstance,
precacheNode: precacheNode,
uncacheNode: uncacheNode,
precacheFiberNode,
precacheNode,
uncacheFiberNode,
uncacheNode,
};

module.exports = ReactNativeComponentTree;
18 changes: 18 additions & 0 deletions src/renderers/native/ReactNativeFeatureFlags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ReactNativeFeatureFlags
*/

'use strict';

var ReactNativeFeatureFlags = {
useFiber: false,
};

module.exports = ReactNativeFeatureFlags;
Loading

0 comments on commit ab72f62

Please sign in to comment.