Skip to content

Commit d2123d6

Browse files
authored
Sync React Native Flow Changes (#13513)
1 parent 1c0ba70 commit d2123d6

File tree

10 files changed

+73
-58
lines changed

10 files changed

+73
-58
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export default function(
142142
return;
143143
}
144144

145-
const viewConfig: ReactNativeBaseComponentViewConfig =
145+
const viewConfig: ReactNativeBaseComponentViewConfig<> =
146146
maybeInstance.viewConfig;
147147

148148
if (__DEV__) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ if (registerEventHandler) {
8282
*/
8383
class ReactFabricHostComponent {
8484
_nativeTag: number;
85-
viewConfig: ReactNativeBaseComponentViewConfig;
85+
viewConfig: ReactNativeBaseComponentViewConfig<>;
8686
currentProps: Props;
8787

8888
constructor(
8989
tag: number,
90-
viewConfig: ReactNativeBaseComponentViewConfig,
90+
viewConfig: ReactNativeBaseComponentViewConfig<>,
9191
props: Props,
9292
) {
9393
this._nativeTag = tag;

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

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import deepDiffer from 'deepDiffer';
1212
import flattenStyle from 'flattenStyle';
1313

14+
import type {AttributeConfiguration} from './ReactNativeTypes';
15+
1416
const emptyObject = {};
1517

1618
/**
@@ -22,20 +24,6 @@ const emptyObject = {};
2224
* across modules, I've kept them isolated to this module.
2325
*/
2426

25-
type AttributeDiffer = (prevProp: mixed, nextProp: mixed) => boolean;
26-
type AttributePreprocessor = (nextProp: mixed) => mixed;
27-
28-
type CustomAttributeConfiguration =
29-
| {diff: AttributeDiffer, process: AttributePreprocessor}
30-
| {diff: AttributeDiffer}
31-
| {process: AttributePreprocessor};
32-
33-
type AttributeConfiguration = {
34-
[key: string]:
35-
| CustomAttributeConfiguration
36-
| AttributeConfiguration /*| boolean*/,
37-
};
38-
3927
type NestedNode = Array<NestedNode> | Object;
4028

4129
// Tracks removed keys
@@ -55,7 +43,7 @@ function defaultDiffer(prevProp: mixed, nextProp: mixed): boolean {
5543
function restoreDeletedValuesInNestedArray(
5644
updatePayload: Object,
5745
node: NestedNode,
58-
validAttributes: AttributeConfiguration,
46+
validAttributes: AttributeConfiguration<>,
5947
) {
6048
if (Array.isArray(node)) {
6149
let i = node.length;
@@ -113,7 +101,7 @@ function diffNestedArrayProperty(
113101
updatePayload: null | Object,
114102
prevArray: Array<NestedNode>,
115103
nextArray: Array<NestedNode>,
116-
validAttributes: AttributeConfiguration,
104+
validAttributes: AttributeConfiguration<>,
117105
): null | Object {
118106
const minLength =
119107
prevArray.length < nextArray.length ? prevArray.length : nextArray.length;
@@ -151,7 +139,7 @@ function diffNestedProperty(
151139
updatePayload: null | Object,
152140
prevProp: NestedNode,
153141
nextProp: NestedNode,
154-
validAttributes: AttributeConfiguration,
142+
validAttributes: AttributeConfiguration<>,
155143
): null | Object {
156144
if (!updatePayload && prevProp === nextProp) {
157145
// If no properties have been added, then we can bail out quickly on object
@@ -212,7 +200,7 @@ function diffNestedProperty(
212200
function addNestedProperty(
213201
updatePayload: null | Object,
214202
nextProp: NestedNode,
215-
validAttributes: AttributeConfiguration,
203+
validAttributes: AttributeConfiguration<>,
216204
) {
217205
if (!nextProp) {
218206
return updatePayload;
@@ -242,7 +230,7 @@ function addNestedProperty(
242230
function clearNestedProperty(
243231
updatePayload: null | Object,
244232
prevProp: NestedNode,
245-
validAttributes: AttributeConfiguration,
233+
validAttributes: AttributeConfiguration<>,
246234
): null | Object {
247235
if (!prevProp) {
248236
return updatePayload;
@@ -274,9 +262,9 @@ function diffProperties(
274262
updatePayload: null | Object,
275263
prevProps: Object,
276264
nextProps: Object,
277-
validAttributes: AttributeConfiguration,
265+
validAttributes: AttributeConfiguration<>,
278266
): null | Object {
279-
let attributeConfig: ?(CustomAttributeConfiguration | AttributeConfiguration);
267+
let attributeConfig;
280268
let nextProp;
281269
let prevProp;
282270

@@ -375,13 +363,13 @@ function diffProperties(
375363
updatePayload,
376364
prevProp,
377365
nextProp,
378-
((attributeConfig: any): AttributeConfiguration),
366+
((attributeConfig: any): AttributeConfiguration<>),
379367
);
380368
if (removedKeyCount > 0 && updatePayload) {
381369
restoreDeletedValuesInNestedArray(
382370
updatePayload,
383371
nextProp,
384-
((attributeConfig: any): AttributeConfiguration),
372+
((attributeConfig: any): AttributeConfiguration<>),
385373
);
386374
removedKeys = null;
387375
}
@@ -432,7 +420,7 @@ function diffProperties(
432420
updatePayload = clearNestedProperty(
433421
updatePayload,
434422
prevProp,
435-
((attributeConfig: any): AttributeConfiguration),
423+
((attributeConfig: any): AttributeConfiguration<>),
436424
);
437425
}
438426
}
@@ -445,7 +433,7 @@ function diffProperties(
445433
function addProperties(
446434
updatePayload: null | Object,
447435
props: Object,
448-
validAttributes: AttributeConfiguration,
436+
validAttributes: AttributeConfiguration<>,
449437
): null | Object {
450438
// TODO: Fast path
451439
return diffProperties(updatePayload, emptyObject, props, validAttributes);
@@ -458,15 +446,15 @@ function addProperties(
458446
function clearProperties(
459447
updatePayload: null | Object,
460448
prevProps: Object,
461-
validAttributes: AttributeConfiguration,
449+
validAttributes: AttributeConfiguration<>,
462450
): null | Object {
463451
// TODO: Fast path
464452
return diffProperties(updatePayload, prevProps, emptyObject, validAttributes);
465453
}
466454

467455
export function create(
468456
props: Object,
469-
validAttributes: AttributeConfiguration,
457+
validAttributes: AttributeConfiguration<>,
470458
): null | Object {
471459
return addProperties(
472460
null, // updatePayload
@@ -478,7 +466,7 @@ export function create(
478466
export function diff(
479467
prevProps: Object,
480468
nextProps: Object,
481-
validAttributes: AttributeConfiguration,
469+
validAttributes: AttributeConfiguration<>,
482470
): null | Object {
483471
return diffProperties(
484472
null, // updatePayload

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export default function(
153153
return;
154154
}
155155

156-
const viewConfig: ReactNativeBaseComponentViewConfig =
156+
const viewConfig: ReactNativeBaseComponentViewConfig<> =
157157
maybeInstance.viewConfig || maybeInstance.canonical.viewConfig;
158158

159159
const updatePayload = ReactNativeAttributePayload.create(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ import {mountSafeCallback, warnForStyleProps} from './NativeMethodsMixinUtils';
3333
class ReactNativeFiberHostComponent {
3434
_children: Array<Instance | number>;
3535
_nativeTag: number;
36-
viewConfig: ReactNativeBaseComponentViewConfig;
36+
viewConfig: ReactNativeBaseComponentViewConfig<>;
3737

38-
constructor(tag: number, viewConfig: ReactNativeBaseComponentViewConfig) {
38+
constructor(tag: number, viewConfig: ReactNativeBaseComponentViewConfig<>) {
3939
this._nativeTag = tag;
4040
this._children = [];
4141
this.viewConfig = viewConfig;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type Container = number;
3131
export type Instance = {
3232
_children: Array<Instance | number>,
3333
_nativeTag: number,
34-
viewConfig: ReactNativeBaseComponentViewConfig,
34+
viewConfig: ReactNativeBaseComponentViewConfig<>,
3535
};
3636
export type TextInstance = number;
3737
export type HydratableInstance = Instance | TextInstance;

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

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,52 @@ export type MeasureLayoutOnSuccessCallback = (
3333
height: number,
3434
) => void;
3535

36-
type BubblingEventType = {
37-
phasedRegistrationNames: {
38-
captured: string,
39-
bubbled: string,
40-
},
41-
};
42-
43-
type DirectEventType = {
44-
registrationName: string,
45-
};
46-
47-
export type ReactNativeBaseComponentViewConfig = {
48-
validAttributes: Object,
36+
type AttributeType =
37+
| true
38+
| $ReadOnly<{|
39+
diff: ?<T>(arg1: T, arg2: T) => boolean,
40+
process: ?(arg1: any) => any,
41+
|}>;
42+
43+
export type AttributeConfiguration<
44+
TProps = string,
45+
TStyleProps = string,
46+
> = $ReadOnly<{
47+
[propName: TProps]: AttributeType,
48+
style: $ReadOnly<{
49+
[propName: TStyleProps]: AttributeType,
50+
}>,
51+
}>;
52+
53+
export type ReactNativeBaseComponentViewConfig<
54+
TProps = string,
55+
TStyleProps = string,
56+
> = $ReadOnly<{|
57+
baseModuleName?: string,
58+
bubblingEventTypes?: $ReadOnly<{
59+
[eventName: string]: $ReadOnly<{|
60+
phasedRegistrationNames: $ReadOnly<{|
61+
captured: string,
62+
bubbled: string,
63+
|}>,
64+
|}>,
65+
}>,
66+
Commands?: $ReadOnly<{
67+
[commandName: string]: number,
68+
}>,
69+
directEventTypes?: $ReadOnly<{
70+
[eventName: string]: $ReadOnly<{|
71+
registrationName: string,
72+
|}>,
73+
}>,
74+
NativeProps?: $ReadOnly<{
75+
[propName: string]: string,
76+
}>,
4977
uiViewClassName: string,
50-
bubblingEventTypes?: {[topLevelType: string]: BubblingEventType},
51-
directEventTypes?: {[topLevelType: string]: DirectEventType},
52-
propTypes?: Object,
53-
};
78+
validAttributes: AttributeConfiguration<TProps, TStyleProps>,
79+
|}>;
5480

55-
export type ViewConfigGetter = () => ReactNativeBaseComponentViewConfig;
81+
export type ViewConfigGetter = () => ReactNativeBaseComponentViewConfig<>;
5682

5783
/**
5884
* Class only exists for its Flow type.

packages/react-native-renderer/src/__mocks__/ReactNativeViewConfigRegistry.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow
7+
* @flow strict-local
88
*/
9+
910
'use strict';
1011

1112
import type {
@@ -28,7 +29,7 @@ const viewConfigCallbacks = new Map();
2829
const viewConfigs = new Map();
2930

3031
function processEventTypes(
31-
viewConfig: ReactNativeBaseComponentViewConfig,
32+
viewConfig: ReactNativeBaseComponentViewConfig<>,
3233
): void {
3334
const {bubblingEventTypes, directEventTypes} = viewConfig;
3435

@@ -84,7 +85,7 @@ exports.register = function(name: string, callback: ViewConfigGetter): string {
8485
* If this is the first time the view has been used,
8586
* This configuration will be lazy-loaded from UIManager.
8687
*/
87-
exports.get = function(name: string): ReactNativeBaseComponentViewConfig {
88+
exports.get = function(name: string): ReactNativeBaseComponentViewConfig<> {
8889
let viewConfig;
8990
if (!viewConfigs.has(name)) {
9091
const callback = viewConfigCallbacks.get(name);

packages/shared/ReactFeatureFlags.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow
7+
* @flow strict
88
*/
99

1010
import invariant from 'shared/invariant';

scripts/rollup/shims/react-native/createReactNativeComponentClass.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*
77
* @format
8-
* @flow
8+
* @flow strict-local
99
*/
1010

1111
'use strict';

0 commit comments

Comments
 (0)