Skip to content

Commit 33b3858

Browse files
yungstersfacebook-github-bot
authored andcommitted
RN: Simplify ReactNativeStyleAttributes Type
Summary: Simplifies the Flow type for `ReactNativeStyleAttributes`, an internal module. Changelog: [Internal] Reviewed By: TheSavior Differential Revision: D29019311 fbshipit-source-id: cf95dac4b8c2261812cc1d753255dfb905540759
1 parent 2e8c0bd commit 33b3858

File tree

3 files changed

+9
-46
lines changed

3 files changed

+9
-46
lines changed

Libraries/Components/View/ReactNativeStyleAttributes.js

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,15 @@
88
* @flow
99
*/
1010

11-
'use strict';
1211
import DeprecatedImageStylePropTypes from '../../DeprecatedPropTypes/DeprecatedImageStylePropTypes';
1312
import DeprecatedTextStylePropTypes from '../../DeprecatedPropTypes/DeprecatedTextStylePropTypes';
1413
import DeprecatedViewStylePropTypes from '../../DeprecatedPropTypes/DeprecatedViewStylePropTypes';
14+
import type {AnyAttributeType} from '../../Renderer/shims/ReactNativeTypes';
1515
import processColor from '../../StyleSheet/processColor';
1616
import processTransform from '../../StyleSheet/processTransform';
1717
import sizesDiffer from '../../Utilities/differ/sizesDiffer';
1818

19-
type ReturnBoolType = <V>(V) => true;
20-
type BoolifiedDeprecatedViewStylePropTypes = $ObjMap<
21-
typeof DeprecatedViewStylePropTypes,
22-
ReturnBoolType,
23-
>;
24-
type BoolifiedDeprecatedTextStylePropTypes = $ObjMapi<
25-
typeof DeprecatedTextStylePropTypes,
26-
ReturnBoolType,
27-
>;
28-
type BoolifiedDeprecatedImageStylePropTypes = $ObjMapi<
29-
typeof DeprecatedImageStylePropTypes,
30-
ReturnBoolType,
31-
>;
32-
33-
type StyleAttributesType = {
34-
...BoolifiedDeprecatedViewStylePropTypes,
35-
...BoolifiedDeprecatedTextStylePropTypes,
36-
...BoolifiedDeprecatedImageStylePropTypes,
37-
transform: $ReadOnly<{|process: typeof processTransform|}> | true,
38-
shadowOffset: $ReadOnly<{|diff: typeof sizesDiffer|}> | true,
39-
backgroundColor: typeof colorAttributes | true,
40-
borderBottomColor: typeof colorAttributes | true,
41-
borderColor: typeof colorAttributes | true,
42-
borderLeftColor: typeof colorAttributes | true,
43-
borderRightColor: typeof colorAttributes | true,
44-
borderTopColor: typeof colorAttributes | true,
45-
borderStartColor: typeof colorAttributes | true,
46-
borderEndColor: typeof colorAttributes | true,
47-
color: typeof colorAttributes | true,
48-
shadowColor: typeof colorAttributes | true,
49-
textDecorationColor: typeof colorAttributes | true,
50-
tintColor: typeof colorAttributes | true,
51-
textShadowColor: typeof colorAttributes | true,
52-
overlayColor: typeof colorAttributes | true,
53-
...
54-
};
55-
56-
const ReactNativeStyleAttributes: StyleAttributesType = {};
19+
const ReactNativeStyleAttributes: {[string]: AnyAttributeType} = {};
5720

5821
for (const attributeName of Object.keys({
5922
...DeprecatedViewStylePropTypes,

Libraries/Renderer/shims/ReactNativeTypes.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @format
88
* @flow strict
9-
* @generated SignedSource<<51285a8509b134326b535fbea3608c87>>
9+
* @generated SignedSource<<d970268c93059bcc9626426c0c280439>>
1010
*/
1111

1212
import type {ElementRef, ElementType, Element, AbstractComponent} from 'react';
@@ -34,7 +34,7 @@ export type MeasureLayoutOnSuccessCallback = (
3434
height: number,
3535
) => void;
3636

37-
type AttributeType<T, V> =
37+
export type AttributeType<T, V> =
3838
| true
3939
| $ReadOnly<{|
4040
diff?: (arg1: T, arg2: T) => boolean,
@@ -43,7 +43,7 @@ type AttributeType<T, V> =
4343

4444
// We either force that `diff` and `process` always use mixed,
4545
// or we allow them to define specific types and use this hack
46-
type AnyAttributeType = AttributeType<$FlowFixMe, $FlowFixMe>;
46+
export type AnyAttributeType = AttributeType<$FlowFixMe, $FlowFixMe>;
4747

4848
export type AttributeConfiguration = $ReadOnly<{
4949
[propName: string]: AnyAttributeType,
@@ -54,7 +54,7 @@ export type AttributeConfiguration = $ReadOnly<{
5454
...
5555
}>;
5656

57-
type PartialAttributeConfiguration = $ReadOnly<{
57+
export type PartialAttributeConfiguration = $ReadOnly<{
5858
[propName: string]: AnyAttributeType,
5959
style?: $ReadOnly<{
6060
[propName: string]: AnyAttributeType,

Libraries/StyleSheet/StyleSheet.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,9 @@ module.exports = {
338338
let value;
339339

340340
if (ReactNativeStyleAttributes[property] === true) {
341-
value = {};
341+
value = {process};
342342
} else if (typeof ReactNativeStyleAttributes[property] === 'object') {
343-
value = ReactNativeStyleAttributes[property];
343+
value = {...ReactNativeStyleAttributes[property], process};
344344
} else {
345345
console.error(`${property} is not a valid style attribute`);
346346
return;
@@ -350,7 +350,7 @@ module.exports = {
350350
console.warn(`Overwriting ${property} style attribute preprocessor`);
351351
}
352352

353-
ReactNativeStyleAttributes[property] = {...value, process};
353+
ReactNativeStyleAttributes[property] = value;
354354
},
355355

356356
/**

0 commit comments

Comments
 (0)