Remove experimental RT/CS renderers (#12032)
Will follow up with adding a new one.
Sebastian Markbåge committed
Jan 17, 2018 at 18:07 UTC
d3647583b3c2c1e68069f8188370b70a3f749b68
23 files changed
+1
-1207
packages/react-cs-renderer/index.js
deleted
-16
@@ -1,16 +0,0 @@
1
-/**
2
- * Copyright (c) 2013-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow
8
- */
9
-
10
-'use strict';
11
-
12
-const ReactNativeCS = require('./src/ReactNativeCS');
13
-
14
-// TODO: decide on the top-level export form.
15
-// This is hacky but makes it work with both Rollup and Jest.
16
-module.exports = ReactNativeCS.default ? ReactNativeCS.default : ReactNativeCS;
packages/react-cs-renderer/package.json
deleted
-14
@@ -1,14 +0,0 @@
1
-{
2
- "name": "react-cs-renderer",
3
- "version": "16.0.0",
4
- "private": true,
5
- "repository": "facebook/react",
6
- "dependencies": {
7
- "fbjs": "^0.8.16",
8
- "object-assign": "^4.1.1",
9
- "prop-types": "^15.6.0"
10
- },
11
- "peerDependencies": {
12
- "react": "^16.0.0"
13
- }
14
-}
packages/react-cs-renderer/src/ReactNativeCS.js
deleted
-306
@@ -1,306 +0,0 @@
1
-/**
2
- * Copyright (c) 2013-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow
8
- */
9
-
10
-import type {ReactNodeList} from 'shared/ReactTypes';
11
-import type {ReactNativeCSType} from './ReactNativeCSTypes';
12
-
13
-// Provided by CS:
14
-import {CSStatefulComponent} from 'CSStatefulComponent';
15
-
16
-import ReactFiberReconciler from 'react-reconciler';
17
-import ReactVersion from 'shared/ReactVersion';
18
-
19
-const emptyObject = {};
20
-
21
-type Container = {
22
- pendingChild: null | Instance | TextInstance,
23
-};
24
-type InstanceProps = Props & {children: Array<Instance>};
25
-type Instance = {
26
- props: InstanceProps,
27
- options: {key: string, ref: null},
28
- data: {type: 'NATIVE', name: string},
29
-};
30
-type Props = Object;
31
-type TextInstance = Instance;
32
-
33
-// We currently don't actually return a new state. We only use state updaters to trigger a
34
-// rerender. Therefore our state updater is the identity functions. When we later deal
35
-// with sync scheduling and aborted renders, we will need to update the state in render.
36
-const identityUpdater = state => state;
37
-// We currently don't have a hook for aborting render. Will add one once it is in place
38
-// in React Native proper.
39
-const infiniteDeadline = {
40
- timeRemaining: function() {
41
- return Infinity;
42
- },
43
-};
44
-
45
-const arePropsEqual = (oldProps: Props, newProps: Props): boolean => {
46
- let key;
47
- for (key in newProps) {
48
- if (key === 'children') {
49
- // Skip special case.
50
- continue;
51
- }
52
- if (newProps[key] !== oldProps[key]) {
53
- return false;
54
- }
55
- }
56
- for (key in oldProps) {
57
- if (key === 'children') {
58
- // Skip special case.
59
- continue;
60
- }
61
- if (!(key in newProps)) {
62
- return false;
63
- }
64
- }
65
- return true;
66
-};
67
-
68
-// React doesn't expose its full keypath. To manage lifetime of instances, we instead use IDs.
69
-let nextComponentKey = 0;
70
-
71
-// Callback. Currently this is global. TODO: This should be per root.
72
-let scheduledCallback = null;
73
-// Updater. This is the CS updater we use to trigger the update. TODO: This should be per root.
74
-let scheduleUpdate = null;
75
-
76
-const ReactNativeCSFiberRenderer = ReactFiberReconciler({
77
- appendInitialChild(
78
- parentInstance: Instance,
79
- child: Instance | TextInstance,
80
- ): void {
81
- if (parentInstance.props) {
82
- parentInstance.props.children.push(child);
83
- } else {
84
- // CSCustom
85
- (parentInstance: any).children.push(child);
86
- }
87
- },
88
-
89
- createInstance(
90
- type: string,
91
- props: Props,
92
- rootContainerInstance: Container,
93
- hostContext: {},
94
- internalInstanceHandle: Object,
95
- ): Instance {
96
- let key = '' + nextComponentKey++;
97
- let ref = null; // TODO: Always create Ref object so that getPublicInstance can use it.
98
- // We need a new props object so that we can represent flattened children.
99
- let newProps = Object.assign({}, props);
100
- newProps.children = [];
101
- if (type === 'CSCustom') {
102
- // Special cased type that treats the props as the object.
103
- // Useful for custom children types like FlexItem.
104
- return newProps;
105
- }
106
- return {
107
- props: newProps,
108
- options: {key, ref},
109
- data: {type: 'NATIVE', name: type},
110
- };
111
- },
112
-
113
- createTextInstance(
114
- text: string,
115
- rootContainerInstance: Container,
116
- hostContext: {},
117
- internalInstanceHandle: Object,
118
- ): TextInstance {
119
- // Could auto-translate to CSText with some host context defined attributes.
120
- throw new Error('Not yet implemented.');
121
- },
122
-
123
- finalizeInitialChildren(
124
- parentInstance: Instance,
125
- type: string,
126
- props: Props,
127
- rootContainerInstance: Container,
128
- ): boolean {
129
- return false;
130
- },
131
-
132
- getRootHostContext(): {} {
133
- return emptyObject;
134
- },
135
-
136
- getChildHostContext(): {} {
137
- return emptyObject;
138
- },
139
-
140
- getPublicInstance(instance: Instance) {
141
- return instance.options.ref;
142
- },
143
-
144
- prepareForCommit(): void {},
145
-
146
- prepareUpdate(
147
- instance: Instance,
148
- type: string,
149
- oldProps: Props,
150
- newProps: Props,
151
- rootContainerInstance: Container,
152
- hostContext: {},
153
- ): null | InstanceProps {
154
- if (arePropsEqual(oldProps, newProps)) {
155
- return null;
156
- }
157
- return Object.assign({}, newProps);
158
- },
159
-
160
- resetAfterCommit(): void {},
161
-
162
- shouldDeprioritizeSubtree(type: string, props: Props): boolean {
163
- return false;
164
- },
165
-
166
- scheduleDeferredCallback(callback) {
167
- scheduledCallback = callback;
168
- if (scheduleUpdate !== null) {
169
- scheduleUpdate(identityUpdater);
170
- }
171
- return 0;
172
- },
173
-
174
- cancelDeferredCallback() {
175
- // Noop. This is always called right before scheduling a new update, so
176
- // should be fine. This renderer won't use requestIdleCallback, anyway.
177
- // Will switch to use shouldYield() API instead.
178
- },
179
-
180
- shouldSetTextContent(type: string, props: Props): boolean {
181
- // TODO: Figure out when we should allow text content.
182
- return false;
183
- },
184
-
185
- now(): number {
186
- // TODO: Enable expiration by implementing this method.
187
- return 0;
188
- },
189
-
190
- persistence: {
191
- cloneInstance(
192
- instance: Instance,
193
- updatePayload: null | InstanceProps,
194
- type: string,
195
- oldProps: Props,
196
- newProps: Props,
197
- internalInstanceHandle: Object,
198
- keepChildren: boolean,
199
- recyclableInstance: null | Instance,
200
- ): Instance {
201
- let newInstanceProps = updatePayload;
202
- if (newInstanceProps === null) {
203
- newInstanceProps = Object.assign({}, newProps);
204
- }
205
- // We need a new props object so that we can represent flattened children.
206
- newInstanceProps.children = keepChildren ? instance.props.children : [];
207
- if (type === 'CSCustom') {
208
- return newInstanceProps;
209
- }
210
- return {
211
- props: newInstanceProps,
212
- options: instance.options,
213
- data: instance.data,
214
- };
215
- },
216
-
217
- createContainerChildSet(container: Container): Container {
218
- // We'll only ever have one instance in the container.
219
- container.pendingChild = null;
220
- return container;
221
- },
222
-
223
- appendChildToContainerChildSet(
224
- childSet: Container,
225
- child: Instance | TextInstance,
226
- ): void {
227
- if (childSet.pendingChild !== null) {
228
- throw new Error(
229
- 'CSReact does not support top level fragments. Wrap it in a primitve.',
230
- );
231
- }
232
- childSet.pendingChild = child;
233
- },
234
-
235
- finalizeContainerChildren(
236
- container: Container,
237
- newChildren: Container,
238
- ): void {},
239
-
240
- replaceContainerChildren(
241
- container: Container,
242
- newChildren: Container,
243
- ): void {},
244
- },
245
-});
246
-
247
-ReactNativeCSFiberRenderer.injectIntoDevTools({
248
- bundleType: __DEV__ ? 1 : 0,
249
- version: ReactVersion,
250
- rendererPackageName: 'react-cs-renderer',
251
-});
252
-
253
-type ReactCSProps = {children: ReactNodeList};
254
-type ReactCSState = {
255
- root: Object,
256
- container: {
257
- pendingChild: null | Instance | TextInstance,
258
- },
259
-};
260
-
261
-const ReactCS = CSStatefulComponent({
262
- getInitialState({props}: {props: ReactCSProps}): ReactCSState {
263
- let container = {
264
- pendingChild: null,
265
- };
266
- let root = ReactNativeCSFiberRenderer.createContainer(
267
- container,
268
- false,
269
- false,
270
- );
271
- return {root, container};
272
- },
273
- render({
274
- props,
275
- state,
276
- stateUpdater,
277
- }: {
278
- props: ReactCSProps,
279
- state: ReactCSState,
280
- stateUpdater: (update: (oldState: ReactCSState) => ReactCSState) => void,
281
- }) {
282
- scheduleUpdate = stateUpdater;
283
- // TODO: For a props rerender updateContainer will schedule an additional state
284
- // update even though it is not necessary since we're already rendering.
285
- // We should only call scheduleUpdate for a React setState, not a top level
286
- // props update.
287
- ReactNativeCSFiberRenderer.updateContainer(
288
- props.children,
289
- state.root,
290
- null,
291
- null,
292
- );
293
- if (scheduledCallback) {
294
- const callback = scheduledCallback;
295
- scheduledCallback = null;
296
- callback(infiniteDeadline);
297
- }
298
- return state.container.pendingChild;
299
- },
300
- getInstance({state}: {state: ReactCSState}) {
301
- return ReactNativeCSFiberRenderer.getPublicRootInstance(state.root);
302
- },
303
- // TODO: Unmount hook. E.g. finalizer.
304
-});
305
-
306
-export default (ReactCS: ReactNativeCSType);
packages/react-cs-renderer/src/ReactNativeCSTypes.js
deleted
-29
@@ -1,29 +0,0 @@
1
-/**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow
8
- * @providesModule ReactNativeCSTypes
9
- */
10
-
11
-/**
12
- * Flat CS renderer bundles are too big for Flow to parse efficiently.
13
- * Provide minimal Flow typing for the high-level API and call it a day.
14
- */
15
-
16
-import type {Options, Element} from 'CSComponent';
17
-
18
-export type Children<ChildType> = {|
19
- +children: $ReadOnlyArray<React$Element<ChildType>>,
20
-|};
21
-
22
-type StatelessComponent<Props> = React$StatelessFunctionalComponent<Props>;
23
-
24
-type ClassComponent<Props, Instance> = Class<React$Component<Props> & Instance>;
25
-
26
-export type ReactNativeCSType = <Props, Instance>(
27
- props: Children<ClassComponent<Props, Instance> | StatelessComponent<Props>>,
28
- options: Options<Instance> | void,
29
-) => Element;
packages/react-cs-renderer/src/__mocks__/CSStatefulComponent.js
deleted
-14
@@ -1,14 +0,0 @@
1
-/**
2
- * Copyright (c) 2013-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
-'use strict';
9
-
10
-// Mock of the CS Hooks
11
-
12
-export const CSStatefulComponent = function(spec) {
13
- return spec;
14
-};
packages/react-cs-renderer/src/__tests__/ReactNativeCS-test.internal.js
deleted
-35
@@ -1,35 +0,0 @@
1
-/**
2
- * Copyright (c) 2013-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails react-core
8
- * @jest-environment node
9
- */
10
-
11
-'use strict';
12
-
13
-let React;
14
-let ReactNativeCS;
15
-
16
-jest.mock('shared/ReactFeatureFlags', () =>
17
- require('shared/forks/ReactFeatureFlags.native-cs'),
18
-);
19
-
20
-describe('ReactNativeCS', () => {
21
- beforeEach(() => {
22
- jest.resetModules();
23
-
24
- React = require('react');
25
- ReactNativeCS = require('react-cs-renderer');
26
- });
27
-
28
- it('should be able to create and render a native component', () => {
29
- const CSView = 'View';
30
- const props = <CSView foo="test" />;
31
- const state = ReactNativeCS.getInitialState({});
32
- const stateUpdater = function() {};
33
- ReactNativeCS.render({props, state, stateUpdater});
34
- });
35
-});
packages/react-native-renderer/src/__mocks__/RTManager.js
deleted
-26
@@ -1,26 +0,0 @@
1
-/**
2
- * Copyright (c) 2013-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
-'use strict';
9
-
10
-// Mock of the Native Hooks
11
-
12
-const RCTRTManager = {
13
- createNode: jest.fn(function createView(tag, classType, props) {}),
14
- beginUpdates: jest.fn(function beginUpdates() {}),
15
- appendChildToContext: jest.fn(function appendChildToContext(
16
- contextTag,
17
- childTag,
18
- ) {}),
19
- appendChild: jest.fn(function appendChild(parentTag, childTag) {}),
20
- prependChild: jest.fn(function prependChild(childTag, beforeTag) {}),
21
- deleteChild: jest.fn(function deleteChild(childTag) {}),
22
- updateNode: jest.fn(function updateNode(tag, props) {}),
23
- completeUpdates: jest.fn(function completeUpdates() {}),
24
-};
25
-
26
-module.exports = RCTRTManager;
packages/react-rt-renderer/index.js
deleted
-14
@@ -1,14 +0,0 @@
1
-/**
2
- * Copyright (c) 2013-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow
8
- */
9
-
10
-const ReactNativeRT = require('./src/ReactNativeRT');
11
-
12
-// TODO: decide on the top-level export form.
13
-// This is hacky but makes it work with both Rollup and Jest.
14
-module.exports = ReactNativeRT.default ? ReactNativeRT.default : ReactNativeRT;
packages/react-rt-renderer/package.json
deleted
-14
@@ -1,14 +0,0 @@
1
-{
2
- "name": "react-rt-renderer",
3
- "version": "16.0.0",
4
- "private": true,
5
- "repository": "facebook/react",
6
- "dependencies": {
7
- "fbjs": "^0.8.16",
8
- "object-assign": "^4.1.1",
9
- "prop-types": "^15.6.0"
10
- },
11
- "peerDependencies": {
12
- "react": "^16.0.0"
13
- }
14
-}
packages/react-rt-renderer/src/ReactNativeRT.js
deleted
-87
@@ -1,87 +0,0 @@
1
-/**
2
- * Copyright (c) 2013-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow
8
- */
9
-
10
-import type {ReactNativeRTType} from './ReactNativeRTTypes';
11
-import type {ReactNodeList} from 'shared/ReactTypes';
12
-
13
-/**
14
- * Make sure essential globals are available and are patched correctly. Please don't remove this
15
- * line. Bundles created by react-packager `require` it before executing any application code. This
16
- * ensures it exists in the dependency graph and can be `require`d.
17
- * TODO: require this in packager, not in React #10932517
18
- */
19
-import 'InitializeCore';
20
-import './ReactNativeRTEventEmitter';
21
-
22
-import * as ReactPortal from 'shared/ReactPortal';
23
-import * as ReactGenericBatching from 'events/ReactGenericBatching';
24
-import ReactVersion from 'shared/ReactVersion';
25
-
26
-import {getFiberFromTag} from './ReactNativeRTComponentTree';
27
-import ReactNativeRTFiberRenderer from './ReactNativeRTFiberRenderer';
28
-import ReactNativeRTFiberInspector from './ReactNativeRTFiberInspector';
29
-
30
-ReactGenericBatching.injection.injectFiberBatchedUpdates(
31
- ReactNativeRTFiberRenderer.batchedUpdates,
32
-);
33
-
34
-const roots = new Map();
35
-
36
-const ReactNativeRTFiber: ReactNativeRTType = {
37
- render(element: React$Element<any>, containerTag: any, callback: ?Function) {
38
- let root = roots.get(containerTag);
39
-
40
- if (!root) {
41
- // TODO (bvaughn): If we decide to keep the wrapper component,
42
- // We could create a wrapper for containerTag as well to reduce special casing.
43
- root = ReactNativeRTFiberRenderer.createContainer(
44
- containerTag,
45
- false,
46
- false,
47
- );
48
- roots.set(containerTag, root);
49
- }
50
- ReactNativeRTFiberRenderer.updateContainer(element, root, null, callback);
51
-
52
- return ReactNativeRTFiberRenderer.getPublicRootInstance(root);
53
- },
54
-
55
- unmountComponentAtNode(containerTag: number) {
56
- const root = roots.get(containerTag);
57
- if (root) {
58
- // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred?
59
- ReactNativeRTFiberRenderer.updateContainer(null, root, null, () => {
60
- roots.delete(containerTag);
61
- });
62
- }
63
- },
64
-
65
- createPortal(
66
- children: ReactNodeList,
67
- containerTag: number,
68
- key: ?string = null,
69
- ) {
70
- return ReactPortal.createPortal(children, containerTag, null, key);
71
- },
72
-
73
- unstable_batchedUpdates: ReactGenericBatching.batchedUpdates,
74
-
75
- flushSync: ReactNativeRTFiberRenderer.flushSync,
76
-};
77
-
78
-ReactNativeRTFiberRenderer.injectIntoDevTools({
79
- findFiberByHostInstance: getFiberFromTag,
80
- getInspectorDataForViewTag:
81
- ReactNativeRTFiberInspector.getInspectorDataForViewTag,
82
- bundleType: __DEV__ ? 1 : 0,
83
- version: ReactVersion,
84
- rendererPackageName: 'react-rt-renderer',
85
-});
86
-
87
-export default ReactNativeRTFiber;
packages/react-rt-renderer/src/ReactNativeRTComponentTree.js
deleted
-34
@@ -1,34 +0,0 @@
1
-/**
2
- * Copyright (c) 2013-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow
8
- */
9
-
10
-import type {Fiber} from 'react-reconciler/src/ReactFiber';
11
-
12
-const instanceCache: {[key: number]: Fiber} = {};
13
-const instanceProps: {[key: number]: Object} = {};
14
-
15
-export function precacheFiberNode(fiber: Fiber, tag: number): void {
16
- instanceCache[tag] = fiber;
17
-}
18
-
19
-export function getFiberFromTag(tag: number): null | Fiber {
20
- return instanceCache[tag] || null;
21
-}
22
-
23
-export function uncacheFiberNode(tag: number): void {
24
- delete instanceCache[tag];
25
- delete instanceProps[tag];
26
-}
27
-
28
-export function getFiberCurrentPropsFromTag(tag: number): null | Object {
29
- return instanceProps[tag] || null;
30
-}
31
-
32
-export function updateFiberProps(tag: number, props: Object): void {
33
- instanceProps[tag] = props;
34
-}
packages/react-rt-renderer/src/ReactNativeRTEventEmitter.js
deleted
-47
@@ -1,47 +0,0 @@
1
-/**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow
8
- */
9
-
10
-import {batchedUpdates} from 'events/ReactGenericBatching';
11
-// Module provided by RN:
12
-import BatchedBridge from 'BatchedBridge';
13
-
14
-import {getFiberCurrentPropsFromTag} from './ReactNativeRTComponentTree';
15
-
16
-const ReactNativeRTEventEmitter = {
17
- /**
18
- * Publicly exposed method on module for native objc to invoke when a top
19
- * level event is extracted.
20
- * @param {rootNodeID} rootNodeID React root node ID that event occurred on.
21
- * @param {TopLevelType} topLevelType Top level type of event.
22
- * @param {object} nativeEventParam Object passed from native.
23
- */
24
- receiveEvent: function(
25
- tag: number,
26
- topLevelType: string,
27
- nativeEventParam: Object,
28
- ) {
29
- const nativeEvent = nativeEventParam;
30
- const props = getFiberCurrentPropsFromTag(tag);
31
- if (props == null) {
32
- return;
33
- }
34
- const eventHandler = props[topLevelType];
35
- if (typeof eventHandler !== 'function') {
36
- return;
37
- }
38
- batchedUpdates(function() {
39
- eventHandler(nativeEvent);
40
- });
41
- },
42
-};
43
-
44
-BatchedBridge.registerCallableModule(
45
- 'RTEventEmitter',
46
- ReactNativeRTEventEmitter,
47
-);
packages/react-rt-renderer/src/ReactNativeRTFiberInspector.js
deleted
-106
@@ -1,106 +0,0 @@
1
-/**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow
8
- */
9
-
10
-import {
11
- findCurrentFiberUsingSlowPath,
12
- findCurrentHostFiber,
13
-} from 'react-reconciler/reflection';
14
-import getComponentName from 'shared/getComponentName';
15
-import {HostComponent} from 'shared/ReactTypeOfWork';
16
-import emptyObject from 'fbjs/lib/emptyObject';
17
-import invariant from 'fbjs/lib/invariant';
18
-
19
-import {getFiberFromTag} from './ReactNativeRTComponentTree';
20
-
21
-let getInspectorDataForViewTag;
22
-
23
-if (__DEV__) {
24
- const traverseOwnerTreeUp = function(hierarchy, instance: any) {
25
- if (instance) {
26
- hierarchy.unshift(instance);
27
- traverseOwnerTreeUp(hierarchy, instance._debugOwner);
28
- }
29
- };
30
-
31
- const getOwnerHierarchy = function(instance: any) {
32
- const hierarchy = [];
33
- traverseOwnerTreeUp(hierarchy, instance);
34
- return hierarchy;
35
- };
36
-
37
- const lastNonHostInstance = function(hierarchy) {
38
- for (let i = hierarchy.length - 1; i > 1; i--) {
39
- const instance = hierarchy[i];
40
-
41
- if (instance.tag !== HostComponent) {
42
- return instance;
43
- }
44
- }
45
- return hierarchy[0];
46
- };
47
-
48
- const getHostProps = function(fiber) {
49
- const host = findCurrentHostFiber(fiber);
50
- if (host) {
51
- return host.memoizedProps || emptyObject;
52
- }
53
- return emptyObject;
54
- };
55
-
56
- const createHierarchy = function(fiberHierarchy) {
57
- return fiberHierarchy.map(fiber => ({
58
- name: getComponentName(fiber),
59
- getInspectorData: findNodeHandle => ({
60
- measure: callback => invariant(false, 'Measure not implemented yet'),
61
- props: getHostProps(fiber),
62
- source: fiber._debugSource,
63
- }),
64
- }));
65
- };
66
-
67
- getInspectorDataForViewTag = function(viewTag: number): Object {
68
- const closestInstance = getFiberFromTag(viewTag);
69
-
70
- // Handle case where user clicks outside of ReactNative
71
- if (!closestInstance) {
72
- return {
73
- hierarchy: [],
74
- props: emptyObject,
75
- selection: null,
76
- source: null,
77
- };
78
- }
79
-
80
- const fiber = findCurrentFiberUsingSlowPath(closestInstance);
81
- const fiberHierarchy = getOwnerHierarchy(fiber);
82
- const instance = lastNonHostInstance(fiberHierarchy);
83
- const hierarchy = createHierarchy(fiberHierarchy);
84
- const props = getHostProps(instance);
85
- const source = instance._debugSource;
86
- const selection = fiberHierarchy.indexOf(instance);
87
-
88
- return {
89
- hierarchy,
90
- props,
91
- selection,
92
- source,
93
- };
94
- };
95
-} else {
96
- getInspectorDataForViewTag = () => {
97
- invariant(
98
- false,
99
- 'getInspectorDataForViewTag() is not available in production',
100
- );
101
- };
102
-}
103
-
104
-export default {
105
- getInspectorDataForViewTag,
106
-};
packages/react-rt-renderer/src/ReactNativeRTFiberRenderer.js
deleted
-243
@@ -1,243 +0,0 @@
1
-/**
2
- * Copyright (c) 2013-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow
8
- */
9
-
10
-import ReactFiberReconciler from 'react-reconciler';
11
-import emptyObject from 'fbjs/lib/emptyObject';
12
-import invariant from 'fbjs/lib/invariant';
13
-// Module provided by RN:
14
-import RTManager from 'RTManager';
15
-
16
-import {
17
- precacheFiberNode,
18
- updateFiberProps,
19
-} from './ReactNativeRTComponentTree';
20
-import ReactNativeRTTagHandles from './ReactNativeRTTagHandles';
21
-
22
-export type Container = number;
23
-export type Instance = number;
24
-export type Props = Object;
25
-export type TextInstance = number;
26
-
27
-function processProps(instance: number, props: Props): Object {
28
- const propsPayload = {};
29
- for (const key in props) {
30
- if (key === 'children') {
31
- // Skip special case.
32
- continue;
33
- }
34
- let value = props[key];
35
- if (typeof value === 'function') {
36
- value = {
37
- style: 'rt-event',
38
- event: key,
39
- tag: instance,
40
- };
41
- }
42
- propsPayload[key] = value;
43
- }
44
- return propsPayload;
45
-}
46
-
47
-function arePropsEqual(oldProps: Props, newProps: Props): boolean {
48
- let key;
49
- for (key in newProps) {
50
- if (key === 'children') {
51
- // Skip special case.
52
- continue;
53
- }
54
- if (newProps[key] !== oldProps[key]) {
55
- return false;
56
- }
57
- }
58
- for (key in oldProps) {
59
- if (key === 'children') {
60
- // Skip special case.
61
- continue;
62
- }
63
- if (!(key in newProps)) {
64
- return false;
65
- }
66
- }
67
- return true;
68
-}
69
-
70
-const NativeRTRenderer = ReactFiberReconciler({
71
- appendInitialChild(
72
- parentInstance: Instance,
73
- child: Instance | TextInstance,
74
- ): void {
75
- RTManager.appendChild(parentInstance, child);
76
- },
77
-
78
- createInstance(
79
- type: string,
80
- props: Props,
81
- rootContainerInstance: Container,
82
- hostContext: {},
83
- internalInstanceHandle: Object,
84
- ): Instance {
85
- const tag = ReactNativeRTTagHandles.allocateTag();
86
- precacheFiberNode(internalInstanceHandle, tag);
87
- updateFiberProps(tag, props);
88
- RTManager.createNode(tag, type, processProps(tag, props));
89
- return tag;
90
- },
91
-
92
- createTextInstance(
93
- text: string,
94
- rootContainerInstance: Container,
95
- hostContext: {},
96
- internalInstanceHandle: Object,
97
- ): TextInstance {
98
- invariant(false, 'Text components are not supported for now.');
99
- },
100
-
101
- finalizeInitialChildren(
102
- parentInstance: Instance,
103
- type: string,
104
- props: Props,
105
- rootContainerInstance: Container,
106
- ): boolean {
107
- return false;
108
- },
109
-
110
- getRootHostContext(): {} {
111
- return emptyObject;
112
- },
113
-
114
- getChildHostContext(): {} {
115
- return emptyObject;
116
- },
117
-
118
- getPublicInstance(instance) {
119
- return instance;
120
- },
121
-
122
- prepareForCommit(): void {
123
- RTManager.beginUpdates();
124
- },
125
-
126
- prepareUpdate(
127
- instance: Instance,
128
- type: string,
129
- oldProps: Props,
130
- newProps: Props,
131
- rootContainerInstance: Container,
132
- hostContext: {},
133
- ): null | Object {
134
- if (arePropsEqual(oldProps, newProps)) {
135
- return null;
136
- }
137
- return processProps(instance, newProps);
138
- },
139
-
140
- resetAfterCommit(): void {
141
- RTManager.completeUpdates();
142
- },
143
-
144
- shouldDeprioritizeSubtree(type: string, props: Props): boolean {
145
- return false;
146
- },
147
-
148
- scheduleDeferredCallback: global.requestIdleCallback,
149
- cancelDeferredCallback: global.cancelIdleCallback,
150
-
151
- shouldSetTextContent(type: string, props: Props): boolean {
152
- // TODO: Figure out when we should allow text content.
153
- return false;
154
- },
155
-
156
- now(): number {
157
- // TODO: Enable expiration by implementing this method.
158
- return 0;
159
- },
160
-
161
- mutation: {
162
- appendChild(
163
- parentInstance: Instance,
164
- child: Instance | TextInstance,
165
- ): void {
166
- RTManager.appendChild(parentInstance, child);
167
- },
168
-
169
- appendChildToContainer(
170
- parentInstance: Container,
171
- child: Instance | TextInstance,
172
- ): void {
173
- RTManager.appendChildToContext(parentInstance, child);
174
- },
175
-
176
- commitTextUpdate(
177
- textInstance: TextInstance,
178
- oldText: string,
179
- newText: string,
180
- ): void {
181
- invariant(false, 'Text components are not yet supported.');
182
- },
183
-
184
- commitMount(
185
- instance: Instance,
186
- type: string,
187
- newProps: Props,
188
- internalInstanceHandle: Object,
189
- ): void {
190
- // Noop
191
- },
192
-
193
- commitUpdate(
194
- instance: Instance,
195
- updatePayload: Object,
196
- type: string,
197
- oldProps: Props,
198
- newProps: Props,
199
- internalInstanceHandle: Object,
200
- ): void {
201
- updateFiberProps(instance, newProps);
202
- RTManager.updateNode(instance, updatePayload);
203
- },
204
-
205
- insertBefore(
206
- parentInstance: Instance,
207
- child: Instance | TextInstance,
208
- beforeChild: Instance | TextInstance,
209
- ): void {
210
- RTManager.prependChild(child, beforeChild);
211
- },
212
-
213
- insertInContainerBefore(
214
- parentInstance: Container,
215
- child: Instance | TextInstance,
216
- beforeChild: Instance | TextInstance,
217
- ): void {
218
- RTManager.prependChild(child, beforeChild);
219
- },
220
-
221
- removeChild(
222
- parentInstance: Instance,
223
- child: Instance | TextInstance,
224
- ): void {
225
- // TODO: recursively uncache, by traversing fibers, this will currently leak
226
- RTManager.deleteChild(child);
227
- },
228
-
229
- removeChildFromContainer(
230
- parentInstance: Container,
231
- child: Instance | TextInstance,
232
- ): void {
233
- // TODO: recursively uncache, by traversing fibers, this will currently leak
234
- RTManager.deleteChild(child);
235
- },
236
-
237
- resetTextContent(instance: Instance): void {
238
- // Noop
239
- },
240
- },
241
-});
242
-
243
-export default NativeRTRenderer;
packages/react-rt-renderer/src/ReactNativeRTTagHandles.js
deleted
-51
@@ -1,51 +0,0 @@
1
-/**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow
8
- */
9
-
10
-import invariant from 'fbjs/lib/invariant';
11
-
12
-/**
13
- * Keeps track of allocating and associating native "tags" which are numeric,
14
- * unique view IDs. All the native tags are negative numbers, to avoid
15
- * collisions, but in the JS we keep track of them as positive integers to store
16
- * them effectively in Arrays. So we must refer to them as "inverses" of the
17
- * native tags (that are * normally negative).
18
- *
19
- * It *must* be the case that every `rootNodeID` always maps to the exact same
20
- * `tag` forever. The easiest way to accomplish this is to never delete
21
- * anything from this table.
22
- * Why: Because `dangerouslyReplaceNodeWithMarkupByID` relies on being able to
23
- * unmount a component with a `rootNodeID`, then mount a new one in its place,
24
- */
25
-const INITIAL_TAG_COUNT = 1;
26
-const ReactNativeRTTagHandles = {
27
- tagsStartAt: INITIAL_TAG_COUNT,
28
- tagCount: INITIAL_TAG_COUNT,
29
-
30
- allocateTag: function(): number {
31
- // Skip over root IDs as those are reserved for native
32
- const tag = ReactNativeRTTagHandles.tagCount;
33
- ReactNativeRTTagHandles.tagCount++;
34
- return tag;
35
- },
36
-
37
- assertRootTag: function(tag: number): void {
38
- invariant(
39
- ReactNativeRTTagHandles.reactTagIsNativeID(tag),
40
- 'Expect a native root tag, instead got %s',
41
- tag,
42
- );
43
- },
44
-
45
- reactTagIsNativeID: function(reactTag: number): boolean {
46
- // We reserve all tags that are 1 mod 10 for native view creation
47
- return reactTag % 10 === 1;
48
- },
49
-};
50
-
51
-export default ReactNativeRTTagHandles;
packages/react-rt-renderer/src/ReactNativeRTTypes.js
deleted
-23
@@ -1,23 +0,0 @@
1
-/**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow
8
- * @providesModule ReactNativeRTTypes
9
- */
10
-
11
-/**
12
- * Flat RT renderer bundles are too big for Flow to parse efficiently.
13
- * Provide minimal Flow typing for the high-level RN API and call it a day.
14
- */
15
-export type ReactNativeRTType = {
16
- render(
17
- element: React$Element<any>,
18
- containerTag: any,
19
- callback: ?Function,
20
- ): any,
21
- unmountComponentAtNode(containerTag: number): any,
22
- unstable_batchedUpdates: any, // TODO (bvaughn) Add types
23
-};
packages/react-rt-renderer/src/__tests__/ReactNativeRT-test.internal.js
deleted
-62
@@ -1,62 +0,0 @@
1
-/**
2
- * Copyright (c) 2013-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails react-core
8
- * @jest-environment node
9
- */
10
-
11
-'use strict';
12
-
13
-let React;
14
-let ReactNativeRT;
15
-let RTManager;
16
-
17
-describe('ReactNativeRT', () => {
18
- beforeEach(() => {
19
- jest.resetModules();
20
-
21
- React = require('react');
22
- ReactNativeRT = require('react-rt-renderer');
23
- RTManager = require('RTManager');
24
- });
25
-
26
- it('should be able to create and render a native component', () => {
27
- ReactNativeRT.render(<rt-box foo="test" />, 1);
28
- expect(RTManager.createNode).toBeCalled();
29
- expect(RTManager.appendChildToContext).toBeCalled();
30
- expect(RTManager.appendChild).not.toBeCalled();
31
- expect(RTManager.updateNode).not.toBeCalled();
32
- });
33
-
34
- it('should be able to create and update a native component', () => {
35
- ReactNativeRT.render(<rt-box foo="foo" />, 11);
36
-
37
- expect(RTManager.createNode.mock.calls.length).toBe(1);
38
- expect(RTManager.createNode).toBeCalledWith(1, 'rt-box', {foo: 'foo'});
39
- expect(RTManager.appendChildToContext.mock.calls.length).toBe(1);
40
- expect(RTManager.appendChild).not.toBeCalled();
41
- expect(RTManager.updateNode).not.toBeCalled();
42
-
43
- ReactNativeRT.render(<rt-box foo="bar" />, 11);
44
-
45
- expect(RTManager.createNode.mock.calls.length).toBe(1);
46
- expect(RTManager.appendChildToContext.mock.calls.length).toBe(1);
47
- expect(RTManager.appendChild).not.toBeCalled();
48
- expect(RTManager.updateNode).toBeCalledWith(1, {foo: 'bar'});
49
-
50
- ReactNativeRT.render(
51
- <rt-box foo="bar">
52
- <rt-box />
53
- </rt-box>,
54
- 11,
55
- );
56
-
57
- expect(RTManager.createNode.mock.calls.length).toBe(2);
58
- expect(RTManager.appendChildToContext.mock.calls.length).toBe(1);
59
- expect(RTManager.appendChildToContext.mock.calls.length).toBe(1);
60
- expect(RTManager.updateNode.mock.calls.length).toBe(1);
61
- });
62
-});
scripts/circleci/check_modules.sh
+1
-3
@@ -3,9 +3,7 @@
3
set -e
4
5
# Make sure we don't introduce accidental @providesModule annotations.
6
-EXPECTED='packages/react-cs-renderer/src/ReactNativeCSTypes.js
7
-packages/react-native-renderer/src/ReactNativeTypes.js
8
-packages/react-rt-renderer/src/ReactNativeRTTypes.js
6
+EXPECTED='packages/react-native-renderer/src/ReactNativeTypes.js
7
packages/shared/ReactTypes.js
8
scripts/rollup/wrappers.js'
9
ACTUAL=$(git grep -l @providesModule -- './*.js' ':!scripts/rollup/shims/*.js')
scripts/rollup/bundles.js
-26
@@ -131,32 +131,6 @@ const bundles = [
131
],
132
},
133
134
- /******* React Native RT *******/
135
- {
136
- label: 'native-rt',
137
- bundleTypes: [RN_DEV, RN_PROD],
138
- moduleType: RENDERER,
139
- entry: 'react-rt-renderer',
140
- global: 'ReactRTRenderer',
141
- externals: [
142
- 'ExceptionsManager',
143
- 'InitializeCore',
144
- 'Platform',
145
- 'BatchedBridge',
146
- 'RTManager',
147
- ],
148
- },
149
-
150
- /******* React Native CS *******/
151
- {
152
- label: 'native-cs',
153
- bundleTypes: [RN_DEV, RN_PROD],
154
- moduleType: RENDERER,
155
- entry: 'react-cs-renderer',
156
- global: 'ReactCSRenderer',
157
- externals: ['CSStatefulComponent'],
158
- },
159
-
134
/******* React Test Renderer *******/
135
{
136
label: 'test',
scripts/rollup/forks.js
-3
@@ -34,8 +34,6 @@ const forks = Object.freeze({
34
switch (entry) {
35
case 'react-native-renderer':
36
return 'shared/forks/ReactFeatureFlags.native.js';
37
- case 'react-cs-renderer':
38
- return 'shared/forks/ReactFeatureFlags.native-cs.js';
37
default:
38
switch (bundleType) {
39
case FB_DEV:
@@ -91,7 +89,6 @@ const forks = Object.freeze({
89
case RN_PROD:
90
switch (entry) {
91
case 'react-native-renderer':
94
- case 'react-rt-renderer':
92
// Use the RN fork which plays well with redbox.
93
return 'react-reconciler/src/forks/ReactFiberErrorDialog.native.js';
94
default:
scripts/rollup/packaging.js
-14
@@ -44,10 +44,6 @@ function getBundleOutputPaths(bundleType, filename, packageName) {
44
case RN_DEV:
45
case RN_PROD:
46
switch (packageName) {
47
- case 'react-rt-renderer':
48
- return [`build/react-rt/${filename}`];
49
- case 'react-cs-renderer':
50
- return [`build/react-cs/${filename}`];
47
case 'react-native-renderer':
48
return [`build/react-native/${filename}`];
49
default:
@@ -77,16 +73,6 @@ async function copyRNShims() {
73
require.resolve('react-native-renderer/src/ReactNativeTypes.js'),
74
'build/react-native/shims/ReactNativeTypes.js'
75
),
80
- // React Native CS
81
- asyncCopyTo(
82
- require.resolve('react-cs-renderer/src/ReactNativeCSTypes.js'),
83
- 'build/react-cs/shims/ReactNativeCSTypes.js'
84
- ),
85
- // React Native RT
86
- asyncCopyTo(
87
- require.resolve('react-rt-renderer/src/ReactNativeRTTypes.js'),
88
- 'build/react-rt/shims/ReactNativeRTTypes.js'
89
- ),
76
]);
77
}
78
scripts/rollup/results.json
-28
@@ -273,34 +273,6 @@
273
"size": 196483,
274
"gzip": 34394
275
},
276
- {
277
- "filename": "ReactRTRenderer-dev.js",
278
- "bundleType": "RN_DEV",
279
- "packageName": "react-rt-renderer",
280
- "size": 286506,
281
- "gzip": 61843
282
- },
283
- {
284
- "filename": "ReactRTRenderer-prod.js",
285
- "bundleType": "RN_PROD",
286
- "packageName": "react-rt-renderer",
287
- "size": 133702,
288
- "gzip": 23039
289
- },
290
- {
291
- "filename": "ReactCSRenderer-dev.js",
292
- "bundleType": "RN_DEV",
293
- "packageName": "react-cs-renderer",
294
- "size": 277130,
295
- "gzip": 58953
296
- },
297
- {
298
- "filename": "ReactCSRenderer-prod.js",
299
- "bundleType": "RN_PROD",
300
- "packageName": "react-cs-renderer",
301
- "size": 126142,
302
- "gzip": 21682
303
- },
276
{
277
"filename": "react-test-renderer.development.js",
278
"bundleType": "NODE_DEV",
scripts/rollup/sync.js
-12
@@ -7,8 +7,6 @@ const resolvePath = require('./utils').resolvePath;
7
const DEFAULT_FB_SOURCE_PATH = '~/fbsource/';
8
const DEFAULT_WWW_PATH = '~/www/';
9
const RELATIVE_RN_PATH = 'xplat/js/react-native-github/Libraries/Renderer/';
10
-const RELATIVE_RN_CS_PATH = 'xplat/js/RKJSModules/Libraries/CS/downstream/';
11
-const RELATIVE_RN_RT_PATH = 'xplat/js/RKJSModules/Libraries/RT/downstream/';
10
const RELATIVE_WWW_PATH = 'html/shared/react/';
11
12
async function doSync(buildPath, destPath) {
@@ -49,17 +47,7 @@ async function syncReactNative(buildPath, fbSourcePath) {
47
await syncReactNativeHelper(buildPath, fbSourcePath, RELATIVE_RN_PATH);
48
}
49
52
-async function syncReactNativeCS(buildPath, fbSourcePath) {
53
- await syncReactNativeHelper(buildPath, fbSourcePath, RELATIVE_RN_CS_PATH);
54
-}
55
-
56
-async function syncReactNativeRT(buildPath, fbSourcePath) {
57
- await syncReactNativeHelper(buildPath, fbSourcePath, RELATIVE_RN_RT_PATH);
58
-}
59
-
50
module.exports = {
51
syncReactDom,
52
syncReactNative,
63
- syncReactNativeCS,
64
- syncReactNativeRT,
53
};