Skip to content

Commit

Permalink
Added new fiber-based renderer for native dubbed ReactNativeFiber
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Dec 15, 2016
1 parent ac24197 commit 5266ca9
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 Original file line Diff line number Diff line change
Expand Up @@ -29,16 +29,35 @@ declare module 'TextInputState' {
declare module 'UIManager' { declare module 'UIManager' {
declare var customBubblingEventTypes : Object; declare var customBubblingEventTypes : Object;
declare var customDirectEventTypes : Object; declare var customDirectEventTypes : Object;
declare function createView() : void; declare function createView(
declare function manageChildren() : void; 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 measure() : void;
declare function measureInWindow() : void; declare function measureInWindow() : void;
declare function measureLayout() : void; declare function measureLayout() : void;
declare function removeRootView() : void; declare function removeRootView() : void;
declare function removeSubviewsFromContainerWithID() : void; declare function removeSubviewsFromContainerWithID() : void;
declare function replaceExistingNonRootView() : void; declare function replaceExistingNonRootView() : void;
declare function setChildren() : void; declare function setChildren(
declare function updateView() : void; containerTag : number,
reactTags : Array<number>,
) : void;
declare function updateView(
reactTag : number,
viewName : string,
props : ?Object,
) : void;
} }
declare module 'View' { declare module 'View' {
declare var exports : typeof ReactComponent; declare var exports : typeof ReactComponent;
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/native/NativeMethodsMixin.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ var NativeMethodsMixin = {
); );


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


// Require ReactNativeDefaultInjection first for its side effects of setting up // TODO (bvaughn) Enable Fiber experiement via ReactNativeFeatureFlags
// the JS environment module.exports = require('ReactNativeStack');
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;
20 changes: 16 additions & 4 deletions src/renderers/native/ReactNativeComponentTree.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -39,28 +39,40 @@ function precacheNode(inst, tag) {
instanceCache[tag] = nativeInst; instanceCache[tag] = nativeInst;
} }


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

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


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

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


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


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


module.exports = ReactNativeComponentTree; module.exports = ReactNativeComponentTree;
18 changes: 18 additions & 0 deletions src/renderers/native/ReactNativeFeatureFlags.js
Original file line number Original file line 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 5266ca9

Please sign in to comment.