Skip to content

Commit ff28133

Browse files
author
Brian Vaughn
committed
Added UIManager flowtype annotations and fixed flow/lint issues
1 parent 635d89a commit ff28133

File tree

6 files changed

+66
-45
lines changed

6 files changed

+66
-45
lines changed

flow/react-native-host-hooks.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,35 @@ declare module 'TextInputState' {
2929
declare module 'UIManager' {
3030
declare var customBubblingEventTypes : Object;
3131
declare var customDirectEventTypes : Object;
32-
declare function createView() : void;
33-
declare function manageChildren() : void;
32+
declare function createView(
33+
reactTag : number,
34+
viewName : string,
35+
rootTag : number,
36+
props : Object,
37+
) : void;
38+
declare function manageChildren(
39+
containerTag : number,
40+
moveFromIndices : Array<number>,
41+
moveToIndices : Array<number>,
42+
addChildReactTags : Array<number>,
43+
addAtIndices : Array<number>,
44+
removeAtIndices : Array<number>
45+
) : void;
3446
declare function measure() : void;
3547
declare function measureInWindow() : void;
3648
declare function measureLayout() : void;
3749
declare function removeRootView() : void;
3850
declare function removeSubviewsFromContainerWithID() : void;
3951
declare function replaceExistingNonRootView() : void;
40-
declare function setChildren() : void;
41-
declare function updateView() : void;
52+
declare function setChildren(
53+
containerTag : number,
54+
reactTags : Array<number>,
55+
) : void;
56+
declare function updateView(
57+
reactTag : number,
58+
viewName : string,
59+
props : Object,
60+
) : void;
4261
}
4362
declare module 'View' {
4463
declare var exports : typeof ReactComponent;

src/renderers/native/NativeMethodsMixin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ var NativeMethodsMixin = {
150150
);
151151

152152
UIManager.updateView(
153-
findNodeHandle(this),
153+
(findNodeHandle(this) : any),
154154
this.viewConfig.uiViewClassName,
155-
updatePayload
155+
(updatePayload : any)
156156
);
157157
},
158158

src/renderers/native/ReactNativeBaseComponent.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ ReactNativeBaseComponent.Mixin = {
112112
UIManager.updateView(
113113
this._rootNodeID,
114114
this.viewConfig.uiViewClassName,
115-
updatePayload
115+
(updatePayload : any)
116116
);
117117
}
118118

@@ -160,7 +160,7 @@ ReactNativeBaseComponent.Mixin = {
160160
tag,
161161
this.viewConfig.uiViewClassName,
162162
nativeTopRootTag,
163-
updatePayload
163+
(updatePayload : any)
164164
);
165165

166166
ReactNativeComponentTree.precacheNode(this, tag);

src/renderers/native/ReactNativeFiber.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212

1313
'use strict';
1414

15+
import type { Element } from 'React';
1516
import type { Fiber } from 'ReactFiber';
1617
import type { ReactNodeList } from 'ReactTypes';
1718

1819
const NativeMethodsMixin = require('NativeMethodsMixin');
19-
const ReactControlledComponent = require('ReactControlledComponent');
2020
const ReactFiberReconciler = require('ReactFiberReconciler');
2121
const ReactGenericBatching = require('ReactGenericBatching');
22-
const ReactInstanceMap = require('ReactInstanceMap');
2322
const ReactNativeAttributePayload = require('ReactNativeAttributePayload');
2423
const ReactNativeComponentTree = require('ReactNativeComponentTree');
2524
const ReactNativeInjection = require('ReactNativeInjection');
@@ -30,38 +29,33 @@ const UIManager = require('UIManager');
3029

3130
const deepFreezeAndThrowOnMutationInDev = require('deepFreezeAndThrowOnMutationInDev');
3231
const findNodeHandle = require('findNodeHandle');
33-
const invariant = require('invariant');
3432

3533
const { precacheFiberNode, uncacheFiberNode } = ReactNativeComponentTree;
3634

3735
ReactNativeInjection.inject();
38-
// ReactControlledComponent.injection.injectFiberControlledHostComponent(
39-
// ReactNativeFiberComponent
40-
// );
4136

42-
type Container = mixed;
43-
type Props = mixed;
44-
type Instance = mixed;
45-
type TextInstance = mixed;
37+
type Container = number;
38+
type Props = Object;
39+
type Instance = any;
40+
type TextInstance = number;
4641

4742
function NativeHostComponent(tag) {
4843
this._nativeTag = tag;
4944
this._children = [];
5045
}
5146
Object.assign(NativeHostComponent.prototype, NativeMethodsMixin);
5247

53-
function recursivelyUncacheFiberNode (node) {
48+
function recursivelyUncacheFiberNode(node : Instance | TextInstance) {
5449
if (typeof node === 'number') { // Leaf node (eg text)
5550
uncacheFiberNode(node);
5651
} else {
57-
uncacheFiberNode(node._nativeTag);
52+
uncacheFiberNode((node : any)._nativeTag);
5853

59-
node._children.forEach(recursivelyUncacheFiberNode);
54+
(node : any)._children.forEach(recursivelyUncacheFiberNode);
6055
}
6156
}
6257

6358
const NativeRenderer = ReactFiberReconciler({
64-
6559
appendChild(
6660
parentInstance : Instance | Container,
6761
child : Instance | TextInstance
@@ -70,17 +64,19 @@ const NativeRenderer = ReactFiberReconciler({
7064
// Root container
7165
UIManager.setChildren(
7266
parentInstance, // containerTag
73-
[child._nativeTag] // reactTags
67+
[(child : any)._nativeTag] // reactTags
7468
);
7569
} else {
76-
parentInstance._children.push(child);
70+
const children = parentInstance._children;
71+
72+
children.push(child);
7773

7874
UIManager.manageChildren(
7975
parentInstance._nativeTag, // containerTag
8076
[], // moveFromIndices
8177
[], // moveToIndices
82-
[child._nativeTag], // addChildReactTags
83-
[parentInstance._children.length - 1], // addAtIndices
78+
[(child : any)._nativeTag], // addChildReactTags
79+
[children.length - 1], // addAtIndices
8480
[], // removeAtIndices
8581
);
8682
}
@@ -115,16 +111,18 @@ const NativeRenderer = ReactFiberReconciler({
115111
) : void {
116112
precacheFiberNode(internalInstanceHandle, instance._nativeTag);
117113

114+
const viewConfig = (instance : any).viewConfig;
115+
118116
const updatePayload = ReactNativeAttributePayload.diff(
119117
oldProps,
120118
newProps,
121-
instance.viewConfig.validAttributes
119+
viewConfig.validAttributes
122120
);
123121

124122
UIManager.updateView(
125-
instance._nativeTag, // reactTag
126-
instance.viewConfig.uiViewClassName, // viewName
127-
updatePayload, // props
123+
(instance : any)._nativeTag, // reactTag
124+
viewConfig.uiViewClassName, // viewName
125+
(updatePayload : any), // props
128126
);
129127
},
130128

@@ -155,7 +153,7 @@ const NativeRenderer = ReactFiberReconciler({
155153
tag, // reactTag
156154
viewConfig.uiViewClassName, // viewName
157155
rootContainerInstance, // rootTag
158-
updatePayload // props
156+
(updatePayload : any), // props
159157
);
160158

161159
const component = new NativeHostComponent(tag);
@@ -216,30 +214,31 @@ const NativeRenderer = ReactFiberReconciler({
216214
child : Instance | TextInstance,
217215
beforeChild : Instance | TextInstance
218216
) : void {
219-
const beforeChildIndex = parentInstance._children.indexOf(beforeChild);
220-
const index = parentInstance._children.indexOf(child);
217+
const children = (parentInstance : any)._children;
218+
const beforeChildIndex = children.indexOf(beforeChild);
219+
const index = children.indexOf(child);
221220

222221
// Move existing child or add new child?
223222
if (index >= 0) {
224-
parentInstance._children.splice(index,1);
225-
parentInstance._children.splice(beforeChildIndex,0,child);
223+
children.splice(index, 1);
224+
children.splice(beforeChildIndex, 0, child);
226225

227226
UIManager.manageChildren(
228-
parentInstance._nativeTag, // containerID
227+
(parentInstance : any)._nativeTag, // containerID
229228
[index], // moveFromIndices
230229
[beforeChildIndex], // moveToIndices
231230
[], // addChildReactTags
232231
[], // addAtIndices
233232
[], // removeAtIndices
234233
);
235234
} else {
236-
parentInstance._children.splice(beforeChildIndex,0,child);
235+
children.splice(beforeChildIndex, 0, child);
237236

238237
UIManager.manageChildren(
239-
parentInstance._nativeTag, // containerID
238+
(parentInstance : any)._nativeTag, // containerID
240239
[], // moveFromIndices
241240
[], // moveToIndices
242-
[child._nativeTag], // addChildReactTags
241+
[(child : any)._nativeTag], // addChildReactTags
243242
[beforeChildIndex], // addAtIndices
244243
[], // removeAtIndices
245244
);
@@ -271,9 +270,10 @@ const NativeRenderer = ReactFiberReconciler({
271270
[0], // removeAtIndices
272271
);
273272
} else {
274-
const index = parentInstance._children.indexOf(child);
273+
const children = parentInstance._children
274+
const index = children.indexOf(child);
275275

276-
parentInstance._children.splice(index, 1);
276+
children.splice(index, 1);
277277

278278
UIManager.manageChildren(
279279
parentInstance._nativeTag, // containerID
@@ -324,7 +324,7 @@ findNodeHandle.injection.injectFindRootNodeID(
324324
const ReactNative = {
325325
findNodeHandle,
326326

327-
render(element : React.Element<any>, containerTag : number, callback: ?Function) {
327+
render(element : Element<any>, containerTag : any, callback: ?Function) {
328328
let root = roots.get(containerTag);
329329

330330
if (!root) {

src/renderers/native/ReactNativeViewConfigRegistry.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
'use strict';
1414

15+
const invariant = require('invariant');
16+
1517
type ReactNativeBaseComponentViewConfig = {
1618
validAttributes: Object,
1719
uiViewClassName: string,
@@ -38,7 +40,8 @@ const ReactNativeViewConfigRegistry = {
3840
const config = viewConfigs.get(secretName);
3941
invariant(
4042
config,
41-
'View config not found for name %s'
43+
'View config not found for name %s',
44+
secretName
4245
);
4346
return config;
4447
},

src/renderers/native/createReactNativeComponentClass.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
'use strict';
1414

15-
const React = require('React');
1615
const ReactNativeBaseComponent = require('ReactNativeBaseComponent');
1716
const ReactNativeViewConfigRegistry = require('ReactNativeViewConfigRegistry');
1817
const ReactNativeFeatureFlags = require('ReactNativeFeatureFlags');
@@ -32,7 +31,7 @@ const createReactNativeFiberComponentClass = function(
3231
viewConfig: ReactNativeBaseComponentViewConfig
3332
): string {
3433
return ReactNativeViewConfigRegistry.register(viewConfig);
35-
}
34+
};
3635

3736
/**
3837
* @param {string} config iOS View configuration.

0 commit comments

Comments
 (0)