Skip to content

Commit 957a8db

Browse files
author
Edvin Erikson
committed
event system, element rendering and updating
1 parent 3b41d79 commit 957a8db

7 files changed

Lines changed: 299 additions & 70 deletions

src/renderers/native/ReactNative.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ var ReactNativeComponentTree = require('ReactNativeComponentTree');
1717
var ReactNativeInjection = require('ReactNativeInjection');
1818
var ReactNativeStackInjection = require('ReactNativeStackInjection');
1919

20-
const useFiber = true;
20+
var ReactNativeFeatureFlags = require('ReactNativeFeatureFlags');
2121

22-
var ReactNativeMount = useFiber ? require('ReactNativeFiber') : require('ReactNativeMount');
22+
var ReactNativeMount;
23+
if (ReactNativeFeatureFlags.useFiber) {
24+
ReactNativeMount = require('ReactNativeFiber');
25+
26+
} else {
27+
ReactNativeMount = require('ReactNativeMount');
28+
}
2329
var ReactUpdates = require('ReactUpdates');
2430

2531
var findNodeHandle = require('findNodeHandle');

src/renderers/native/ReactNativeComponentTree.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*
99
* @providesModule ReactNativeComponentTree
10+
* @flow
1011
*/
1112

1213
'use strict';
1314

15+
import type { Fiber } from 'ReactFiber';
16+
1417
var invariant = require('invariant');
18+
var { useFiber } = require('ReactNativeFeatureFlags');
1519

1620
var instanceCache = {};
1721

@@ -34,33 +38,43 @@ function getRenderedHostOrTextFromComponent(component) {
3438
* Populate `_hostNode` on the rendered host/text component with the given
3539
* DOM node. The passed `inst` can be a composite.
3640
*/
37-
function precacheNode(inst, tag) {
41+
function precacheNode(inst: Object, tag: number) {
3842
var nativeInst = getRenderedHostOrTextFromComponent(inst);
3943
instanceCache[tag] = nativeInst;
4044
}
4145

42-
function uncacheNode(inst) {
46+
function precacheFiberNode(inst: Object, tag: number) {
47+
instanceCache[tag] = inst;
48+
}
49+
50+
function uncacheNode(inst: Object) {
4351
var tag = inst._rootNodeID;
4452
if (tag) {
4553
delete instanceCache[tag];
4654
}
4755
}
4856

49-
function getInstanceFromTag(tag) {
57+
function getInstanceFromTag(tag: number) {
5058
return instanceCache[tag] || null;
5159
}
5260

53-
function getTagFromInstance(inst) {
61+
function getTagFromFiber(fiber: Fiber) {
62+
invariant(fiber.stateNode, 'All native instances should have a tag.');
63+
return fiber.stateNode._rootNodeID;
64+
}
65+
66+
function getTagFromInstance(inst: Object) {
5467
invariant(inst._rootNodeID, 'All native instances should have a tag.');
5568
return inst._rootNodeID;
5669
}
5770

5871
var ReactNativeComponentTree = {
5972
getClosestInstanceFromNode: getInstanceFromTag,
6073
getInstanceFromNode: getInstanceFromTag,
61-
getNodeFromInstance: getTagFromInstance,
74+
getNodeFromInstance: useFiber ? getTagFromFiber : getTagFromInstance,
6275
precacheNode: precacheNode,
6376
uncacheNode: uncacheNode,
77+
precacheFiberNode: precacheFiberNode,
6478
};
6579

6680
module.exports = ReactNativeComponentTree;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
* @flow
11+
*/
12+
13+
'use strict';
14+
15+
var ReactNativeFeatureFlags = {
16+
useFiber: true,
17+
};
18+
19+
module.exports = ReactNativeFeatureFlags;

src/renderers/native/createReactNativeComponentClass.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ type ReactNativeBaseComponentViewConfig = {
1919
propTypes?: Object,
2020
}
2121

22-
var configMap = new Map();
22+
var ReactNativeFeatureFlags = require('ReactNativeFeatureFlags');
23+
var ReactNativeFiberComponent = require('ReactNativeFiberComponent');
24+
var ReactNativeBaseComponent = require('ReactNativeBaseComponent');
2325

2426
/**
2527
* @param {string} config iOS View configuration.
@@ -28,21 +30,26 @@ var configMap = new Map();
2830
var createReactNativeComponentClass = function(
2931
viewConfig: ReactNativeBaseComponentViewConfig
3032
): ReactClass<*> {
31-
var name = viewConfig.uiViewClassName;
32-
if (configMap.has(name)) {
33-
throw new Error(name + ' was configured twice');
34-
} else {
35-
configMap.set(name, viewConfig);
33+
if (ReactNativeFeatureFlags.useFiber) {
34+
return ReactNativeFiberComponent.createComponent(viewConfig);
3635
}
3736

38-
var component = function(props) {
39-
return React.createElement(name, props);
37+
var Constructor = function(element) {
38+
this._currentElement = element;
39+
this._topLevelWrapper = null;
40+
this._hostParent = null;
41+
this._hostContainerInfo = null;
42+
this._rootNodeID = 0;
43+
this._renderedChildren = null;
4044
};
45+
Constructor.displayName = viewConfig.uiViewClassName;
46+
Constructor.viewConfig = viewConfig;
47+
Constructor.propTypes = viewConfig.propTypes;
48+
Constructor.prototype = new ReactNativeBaseComponent(viewConfig);
49+
Constructor.prototype.constructor = Constructor;
4150

42-
component.propTypes = viewConfig.propTypes;
43-
return component;
44-
};
51+
return ((Constructor: any): ReactClass<any>);
4552

46-
createReactNativeComponentClass.configMap = configMap;
53+
};
4754

4855
module.exports = createReactNativeComponentClass;

0 commit comments

Comments
 (0)