Skip to content

Commit 8336f19

Browse files
authored
Update React Native types (#20883)
1 parent 9209c30 commit 8336f19

6 files changed

+114
-85
lines changed

packages/react-native-renderer/src/ReactFabric.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import type {HostComponent} from './ReactNativeTypes';
1111
import type {ReactNodeList} from 'shared/ReactTypes';
12-
import type {ElementRef} from 'react';
12+
import type {ElementRef, Element, ElementType} from 'react';
1313

1414
import './ReactFabricInjection';
1515

@@ -47,8 +47,8 @@ import getComponentName from 'shared/getComponentName';
4747

4848
const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
4949

50-
function findHostInstance_DEPRECATED(
51-
componentOrHandle: any,
50+
function findHostInstance_DEPRECATED<TElementType: ElementType>(
51+
componentOrHandle: ?(ElementRef<TElementType> | number),
5252
): ?ElementRef<HostComponent<mixed>> {
5353
if (__DEV__) {
5454
const owner = ReactCurrentOwner.current;
@@ -70,10 +70,14 @@ function findHostInstance_DEPRECATED(
7070
if (componentOrHandle == null) {
7171
return null;
7272
}
73+
// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
7374
if (componentOrHandle._nativeTag) {
75+
// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
7476
return componentOrHandle;
7577
}
78+
// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
7679
if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) {
80+
// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
7781
return componentOrHandle.canonical;
7882
}
7983
let hostInstance;
@@ -194,10 +198,10 @@ function sendAccessibilityEvent(handle: any, eventType: string) {
194198
}
195199

196200
function render(
197-
element: React$Element<any>,
198-
containerTag: any,
199-
callback: ?Function,
200-
) {
201+
element: Element<ElementType>,
202+
containerTag: number,
203+
callback: ?() => void,
204+
): ?ElementRef<ElementType> {
201205
let root = roots.get(containerTag);
202206

203207
if (!root) {
@@ -208,6 +212,7 @@ function render(
208212
}
209213
updateContainer(element, root, null, callback);
210214

215+
// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
211216
return getPublicRootInstance(root);
212217
}
213218

packages/react-native-renderer/src/ReactFabricHostConfig.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
MeasureLayoutOnSuccessCallback,
1515
MeasureOnSuccessCallback,
1616
NativeMethods,
17-
ReactNativeBaseComponentViewConfig,
17+
ViewConfig,
1818
TouchedViewDataAtPoint,
1919
} from './ReactNativeTypes';
2020

@@ -111,13 +111,13 @@ if (registerEventHandler) {
111111
*/
112112
class ReactFabricHostComponent {
113113
_nativeTag: number;
114-
viewConfig: ReactNativeBaseComponentViewConfig<>;
114+
viewConfig: ViewConfig;
115115
currentProps: Props;
116116
_internalInstanceHandle: Object;
117117

118118
constructor(
119119
tag: number,
120-
viewConfig: ReactNativeBaseComponentViewConfig<>,
120+
viewConfig: ViewConfig,
121121
props: Props,
122122
internalInstanceHandle: Object,
123123
) {

packages/react-native-renderer/src/ReactNativeAttributePayload.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function defaultDiffer(prevProp: mixed, nextProp: mixed): boolean {
4949
function restoreDeletedValuesInNestedArray(
5050
updatePayload: Object,
5151
node: NestedNode,
52-
validAttributes: AttributeConfiguration<>,
52+
validAttributes: AttributeConfiguration,
5353
) {
5454
if (Array.isArray(node)) {
5555
let i = node.length;
@@ -107,7 +107,7 @@ function diffNestedArrayProperty(
107107
updatePayload: null | Object,
108108
prevArray: Array<NestedNode>,
109109
nextArray: Array<NestedNode>,
110-
validAttributes: AttributeConfiguration<>,
110+
validAttributes: AttributeConfiguration,
111111
): null | Object {
112112
const minLength =
113113
prevArray.length < nextArray.length ? prevArray.length : nextArray.length;
@@ -145,7 +145,7 @@ function diffNestedProperty(
145145
updatePayload: null | Object,
146146
prevProp: NestedNode,
147147
nextProp: NestedNode,
148-
validAttributes: AttributeConfiguration<>,
148+
validAttributes: AttributeConfiguration,
149149
): null | Object {
150150
if (!updatePayload && prevProp === nextProp) {
151151
// If no properties have been added, then we can bail out quickly on object
@@ -206,7 +206,7 @@ function diffNestedProperty(
206206
function addNestedProperty(
207207
updatePayload: null | Object,
208208
nextProp: NestedNode,
209-
validAttributes: AttributeConfiguration<>,
209+
validAttributes: AttributeConfiguration,
210210
) {
211211
if (!nextProp) {
212212
return updatePayload;
@@ -236,7 +236,7 @@ function addNestedProperty(
236236
function clearNestedProperty(
237237
updatePayload: null | Object,
238238
prevProp: NestedNode,
239-
validAttributes: AttributeConfiguration<>,
239+
validAttributes: AttributeConfiguration,
240240
): null | Object {
241241
if (!prevProp) {
242242
return updatePayload;
@@ -268,7 +268,7 @@ function diffProperties(
268268
updatePayload: null | Object,
269269
prevProps: Object,
270270
nextProps: Object,
271-
validAttributes: AttributeConfiguration<>,
271+
validAttributes: AttributeConfiguration,
272272
): null | Object {
273273
let attributeConfig;
274274
let nextProp;
@@ -369,13 +369,13 @@ function diffProperties(
369369
updatePayload,
370370
prevProp,
371371
nextProp,
372-
((attributeConfig: any): AttributeConfiguration<>),
372+
((attributeConfig: any): AttributeConfiguration),
373373
);
374374
if (removedKeyCount > 0 && updatePayload) {
375375
restoreDeletedValuesInNestedArray(
376376
updatePayload,
377377
nextProp,
378-
((attributeConfig: any): AttributeConfiguration<>),
378+
((attributeConfig: any): AttributeConfiguration),
379379
);
380380
removedKeys = null;
381381
}
@@ -426,7 +426,7 @@ function diffProperties(
426426
updatePayload = clearNestedProperty(
427427
updatePayload,
428428
prevProp,
429-
((attributeConfig: any): AttributeConfiguration<>),
429+
((attributeConfig: any): AttributeConfiguration),
430430
);
431431
}
432432
}
@@ -439,7 +439,7 @@ function diffProperties(
439439
function addProperties(
440440
updatePayload: null | Object,
441441
props: Object,
442-
validAttributes: AttributeConfiguration<>,
442+
validAttributes: AttributeConfiguration,
443443
): null | Object {
444444
// TODO: Fast path
445445
return diffProperties(updatePayload, emptyObject, props, validAttributes);
@@ -452,15 +452,15 @@ function addProperties(
452452
function clearProperties(
453453
updatePayload: null | Object,
454454
prevProps: Object,
455-
validAttributes: AttributeConfiguration<>,
455+
validAttributes: AttributeConfiguration,
456456
): null | Object {
457457
// TODO: Fast path
458458
return diffProperties(updatePayload, prevProps, emptyObject, validAttributes);
459459
}
460460

461461
export function create(
462462
props: Object,
463-
validAttributes: AttributeConfiguration<>,
463+
validAttributes: AttributeConfiguration,
464464
): null | Object {
465465
return addProperties(
466466
null, // updatePayload
@@ -472,7 +472,7 @@ export function create(
472472
export function diff(
473473
prevProps: Object,
474474
nextProps: Object,
475-
validAttributes: AttributeConfiguration<>,
475+
validAttributes: AttributeConfiguration,
476476
): null | Object {
477477
return diffProperties(
478478
null, // updatePayload

packages/react-native-renderer/src/ReactNativeFiberHostComponent.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
MeasureLayoutOnSuccessCallback,
1515
MeasureOnSuccessCallback,
1616
NativeMethods,
17-
ReactNativeBaseComponentViewConfig,
17+
ViewConfig,
1818
} from './ReactNativeTypes';
1919
import type {Instance} from './ReactNativeHostConfig';
2020

@@ -34,11 +34,11 @@ class ReactNativeFiberHostComponent {
3434
_children: Array<Instance | number>;
3535
_nativeTag: number;
3636
_internalFiberInstanceHandleDEV: Object;
37-
viewConfig: ReactNativeBaseComponentViewConfig<>;
37+
viewConfig: ViewConfig;
3838

3939
constructor(
4040
tag: number,
41-
viewConfig: ReactNativeBaseComponentViewConfig<>,
41+
viewConfig: ViewConfig,
4242
internalInstanceHandleDEV: Object,
4343
) {
4444
this._nativeTag = tag;

packages/react-native-renderer/src/ReactNativeRenderer.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import type {HostComponent} from './ReactNativeTypes';
1111
import type {ReactNodeList} from 'shared/ReactTypes';
12+
import type {ElementRef, Element, ElementType} from 'react';
1213

1314
import './ReactNativeInjection';
1415

@@ -193,10 +194,10 @@ function sendAccessibilityEvent(handle: any, eventType: string) {
193194
}
194195

195196
function render(
196-
element: React$Element<any>,
197-
containerTag: any,
198-
callback: ?Function,
199-
) {
197+
element: Element<ElementType>,
198+
containerTag: number,
199+
callback: ?() => void,
200+
): ?ElementRef<ElementType> {
200201
let root = roots.get(containerTag);
201202

202203
if (!root) {
@@ -207,6 +208,7 @@ function render(
207208
}
208209
updateContainer(element, root, null, callback);
209210

211+
// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
210212
return getPublicRootInstance(root);
211213
}
212214

0 commit comments

Comments
 (0)