Sync React Native Flow Changes (#13513)
Timothy Yung committed
Aug 29, 2018 at 13:54 UTC
d2123d65699d4d8e36537e2eb3a2299e7558eefa
10 files changed
+73
-58
packages/react-native-renderer/src/NativeMethodsMixin.js
+1
-1
@@ -142,7 +142,7 @@ export default function(
142
return;
143
}
144
145
- const viewConfig: ReactNativeBaseComponentViewConfig =
145
+ const viewConfig: ReactNativeBaseComponentViewConfig<> =
146
maybeInstance.viewConfig;
147
148
if (__DEV__) {
packages/react-native-renderer/src/ReactFabricHostConfig.js
+2
-2
@@ -82,12 +82,12 @@ if (registerEventHandler) {
82
*/
83
class ReactFabricHostComponent {
84
_nativeTag: number;
85
- viewConfig: ReactNativeBaseComponentViewConfig;
85
+ viewConfig: ReactNativeBaseComponentViewConfig<>;
86
currentProps: Props;
87
88
constructor(
89
tag: number,
90
- viewConfig: ReactNativeBaseComponentViewConfig,
90
+ viewConfig: ReactNativeBaseComponentViewConfig<>,
91
props: Props,
92
) {
93
this._nativeTag = tag;
packages/react-native-renderer/src/ReactNativeAttributePayload.js
+16
-28
@@ -11,6 +11,8 @@
11
import deepDiffer from 'deepDiffer';
12
import flattenStyle from 'flattenStyle';
13
14
+import type {AttributeConfiguration} from './ReactNativeTypes';
15
+
16
const emptyObject = {};
17
18
/**
@@ -22,20 +24,6 @@ const emptyObject = {};
24
* across modules, I've kept them isolated to this module.
25
*/
26
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
-
27
type NestedNode = Array<NestedNode> | Object;
28
29
// Tracks removed keys
@@ -55,7 +43,7 @@ function defaultDiffer(prevProp: mixed, nextProp: mixed): boolean {
43
function restoreDeletedValuesInNestedArray(
44
updatePayload: Object,
45
node: NestedNode,
58
- validAttributes: AttributeConfiguration,
46
+ validAttributes: AttributeConfiguration<>,
47
) {
48
if (Array.isArray(node)) {
49
let i = node.length;
@@ -113,7 +101,7 @@ function diffNestedArrayProperty(
101
updatePayload: null | Object,
102
prevArray: Array<NestedNode>,
103
nextArray: Array<NestedNode>,
116
- validAttributes: AttributeConfiguration,
104
+ validAttributes: AttributeConfiguration<>,
105
): null | Object {
106
const minLength =
107
prevArray.length < nextArray.length ? prevArray.length : nextArray.length;
@@ -151,7 +139,7 @@ function diffNestedProperty(
139
updatePayload: null | Object,
140
prevProp: NestedNode,
141
nextProp: NestedNode,
154
- validAttributes: AttributeConfiguration,
142
+ validAttributes: AttributeConfiguration<>,
143
): null | Object {
144
if (!updatePayload && prevProp === nextProp) {
145
// If no properties have been added, then we can bail out quickly on object
@@ -212,7 +200,7 @@ function diffNestedProperty(
200
function addNestedProperty(
201
updatePayload: null | Object,
202
nextProp: NestedNode,
215
- validAttributes: AttributeConfiguration,
203
+ validAttributes: AttributeConfiguration<>,
204
) {
205
if (!nextProp) {
206
return updatePayload;
@@ -242,7 +230,7 @@ function addNestedProperty(
230
function clearNestedProperty(
231
updatePayload: null | Object,
232
prevProp: NestedNode,
245
- validAttributes: AttributeConfiguration,
233
+ validAttributes: AttributeConfiguration<>,
234
): null | Object {
235
if (!prevProp) {
236
return updatePayload;
@@ -274,9 +262,9 @@ function diffProperties(
262
updatePayload: null | Object,
263
prevProps: Object,
264
nextProps: Object,
277
- validAttributes: AttributeConfiguration,
265
+ validAttributes: AttributeConfiguration<>,
266
): null | Object {
279
- let attributeConfig: ?(CustomAttributeConfiguration | AttributeConfiguration);
267
+ let attributeConfig;
268
let nextProp;
269
let prevProp;
270
@@ -375,13 +363,13 @@ function diffProperties(
363
updatePayload,
364
prevProp,
365
nextProp,
378
- ((attributeConfig: any): AttributeConfiguration),
366
+ ((attributeConfig: any): AttributeConfiguration<>),
367
);
368
if (removedKeyCount > 0 && updatePayload) {
369
restoreDeletedValuesInNestedArray(
370
updatePayload,
371
nextProp,
384
- ((attributeConfig: any): AttributeConfiguration),
372
+ ((attributeConfig: any): AttributeConfiguration<>),
373
);
374
removedKeys = null;
375
}
@@ -432,7 +420,7 @@ function diffProperties(
420
updatePayload = clearNestedProperty(
421
updatePayload,
422
prevProp,
435
- ((attributeConfig: any): AttributeConfiguration),
423
+ ((attributeConfig: any): AttributeConfiguration<>),
424
);
425
}
426
}
@@ -445,7 +433,7 @@ function diffProperties(
433
function addProperties(
434
updatePayload: null | Object,
435
props: Object,
448
- validAttributes: AttributeConfiguration,
436
+ validAttributes: AttributeConfiguration<>,
437
): null | Object {
438
// TODO: Fast path
439
return diffProperties(updatePayload, emptyObject, props, validAttributes);
@@ -458,7 +446,7 @@ function addProperties(
446
function clearProperties(
447
updatePayload: null | Object,
448
prevProps: Object,
461
- validAttributes: AttributeConfiguration,
449
+ validAttributes: AttributeConfiguration<>,
450
): null | Object {
451
// TODO: Fast path
452
return diffProperties(updatePayload, prevProps, emptyObject, validAttributes);
@@ -466,7 +454,7 @@ function clearProperties(
454
455
export function create(
456
props: Object,
469
- validAttributes: AttributeConfiguration,
457
+ validAttributes: AttributeConfiguration<>,
458
): null | Object {
459
return addProperties(
460
null, // updatePayload
@@ -478,7 +466,7 @@ export function create(
466
export function diff(
467
prevProps: Object,
468
nextProps: Object,
481
- validAttributes: AttributeConfiguration,
469
+ validAttributes: AttributeConfiguration<>,
470
): null | Object {
471
return diffProperties(
472
null, // updatePayload
packages/react-native-renderer/src/ReactNativeComponent.js
+1
-1
@@ -153,7 +153,7 @@ export default function(
153
return;
154
}
155
156
- const viewConfig: ReactNativeBaseComponentViewConfig =
156
+ const viewConfig: ReactNativeBaseComponentViewConfig<> =
157
maybeInstance.viewConfig || maybeInstance.canonical.viewConfig;
158
159
const updatePayload = ReactNativeAttributePayload.create(
packages/react-native-renderer/src/ReactNativeFiberHostComponent.js
+2
-2
@@ -33,9 +33,9 @@ import {mountSafeCallback, warnForStyleProps} from './NativeMethodsMixinUtils';
33
class ReactNativeFiberHostComponent {
34
_children: Array<Instance | number>;
35
_nativeTag: number;
36
- viewConfig: ReactNativeBaseComponentViewConfig;
36
+ viewConfig: ReactNativeBaseComponentViewConfig<>;
37
38
- constructor(tag: number, viewConfig: ReactNativeBaseComponentViewConfig) {
38
+ constructor(tag: number, viewConfig: ReactNativeBaseComponentViewConfig<>) {
39
this._nativeTag = tag;
40
this._children = [];
41
this.viewConfig = viewConfig;
packages/react-native-renderer/src/ReactNativeHostConfig.js
+1
-1
@@ -31,7 +31,7 @@ export type Container = number;
31
export type Instance = {
32
_children: Array<Instance | number>,
33
_nativeTag: number,
34
- viewConfig: ReactNativeBaseComponentViewConfig,
34
+ viewConfig: ReactNativeBaseComponentViewConfig<>,
35
};
36
export type TextInstance = number;
37
export type HydratableInstance = Instance | TextInstance;
packages/react-native-renderer/src/ReactNativeTypes.js
+44
-18
@@ -33,26 +33,52 @@ export type MeasureLayoutOnSuccessCallback = (
33
height: number,
34
) => void;
35
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
+ }>,
77
uiViewClassName: string,
50
- bubblingEventTypes?: {[topLevelType: string]: BubblingEventType},
51
- directEventTypes?: {[topLevelType: string]: DirectEventType},
52
- propTypes?: Object,
53
-};
78
+ validAttributes: AttributeConfiguration<TProps, TStyleProps>,
79
+|}>;
80
55
-export type ViewConfigGetter = () => ReactNativeBaseComponentViewConfig;
81
+export type ViewConfigGetter = () => ReactNativeBaseComponentViewConfig<>;
82
83
/**
84
* Class only exists for its Flow type.
packages/react-native-renderer/src/__mocks__/ReactNativeViewConfigRegistry.js
+4
-3
@@ -4,8 +4,9 @@
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
7
+ * @flow strict-local
8
*/
9
+
10
'use strict';
11
12
import type {
@@ -28,7 +29,7 @@ const viewConfigCallbacks = new Map();
29
const viewConfigs = new Map();
30
31
function processEventTypes(
31
- viewConfig: ReactNativeBaseComponentViewConfig,
32
+ viewConfig: ReactNativeBaseComponentViewConfig<>,
33
): void {
34
const {bubblingEventTypes, directEventTypes} = viewConfig;
35
@@ -84,7 +85,7 @@ exports.register = function(name: string, callback: ViewConfigGetter): string {
85
* If this is the first time the view has been used,
86
* This configuration will be lazy-loaded from UIManager.
87
*/
87
-exports.get = function(name: string): ReactNativeBaseComponentViewConfig {
88
+exports.get = function(name: string): ReactNativeBaseComponentViewConfig<> {
89
let viewConfig;
90
if (!viewConfigs.has(name)) {
91
const callback = viewConfigCallbacks.get(name);
packages/shared/ReactFeatureFlags.js
+1
-1
@@ -4,7 +4,7 @@
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
7
+ * @flow strict
8
*/
9
10
import invariant from 'shared/invariant';
scripts/rollup/shims/react-native/createReactNativeComponentClass.js
+1
-1
@@ -5,7 +5,7 @@
5
* LICENSE file in the root directory of this source tree.
6
*
7
* @format
8
- * @flow
8
+ * @flow strict-local
9
*/
10
11
'use strict';