Skip to content

Commit

Permalink
RN: Simplify ReactNativeStyleAttributes Type
Browse files Browse the repository at this point in the history
Summary:
Simplifies the Flow type for `ReactNativeStyleAttributes`, an internal module.

Changelog:
[Internal]

Reviewed By: TheSavior

Differential Revision: D29019311

fbshipit-source-id: cf95dac4b8c2261812cc1d753255dfb905540759
  • Loading branch information
yungsters authored and facebook-github-bot committed Jun 12, 2021
1 parent 2e8c0bd commit 33b3858
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 46 deletions.
41 changes: 2 additions & 39 deletions Libraries/Components/View/ReactNativeStyleAttributes.js
Expand Up @@ -8,52 +8,15 @@
* @flow
*/

'use strict';
import DeprecatedImageStylePropTypes from '../../DeprecatedPropTypes/DeprecatedImageStylePropTypes';
import DeprecatedTextStylePropTypes from '../../DeprecatedPropTypes/DeprecatedTextStylePropTypes';
import DeprecatedViewStylePropTypes from '../../DeprecatedPropTypes/DeprecatedViewStylePropTypes';
import type {AnyAttributeType} from '../../Renderer/shims/ReactNativeTypes';
import processColor from '../../StyleSheet/processColor';
import processTransform from '../../StyleSheet/processTransform';
import sizesDiffer from '../../Utilities/differ/sizesDiffer';

type ReturnBoolType = <V>(V) => true;
type BoolifiedDeprecatedViewStylePropTypes = $ObjMap<
typeof DeprecatedViewStylePropTypes,
ReturnBoolType,
>;
type BoolifiedDeprecatedTextStylePropTypes = $ObjMapi<
typeof DeprecatedTextStylePropTypes,
ReturnBoolType,
>;
type BoolifiedDeprecatedImageStylePropTypes = $ObjMapi<
typeof DeprecatedImageStylePropTypes,
ReturnBoolType,
>;

type StyleAttributesType = {
...BoolifiedDeprecatedViewStylePropTypes,
...BoolifiedDeprecatedTextStylePropTypes,
...BoolifiedDeprecatedImageStylePropTypes,
transform: $ReadOnly<{|process: typeof processTransform|}> | true,
shadowOffset: $ReadOnly<{|diff: typeof sizesDiffer|}> | true,
backgroundColor: typeof colorAttributes | true,
borderBottomColor: typeof colorAttributes | true,
borderColor: typeof colorAttributes | true,
borderLeftColor: typeof colorAttributes | true,
borderRightColor: typeof colorAttributes | true,
borderTopColor: typeof colorAttributes | true,
borderStartColor: typeof colorAttributes | true,
borderEndColor: typeof colorAttributes | true,
color: typeof colorAttributes | true,
shadowColor: typeof colorAttributes | true,
textDecorationColor: typeof colorAttributes | true,
tintColor: typeof colorAttributes | true,
textShadowColor: typeof colorAttributes | true,
overlayColor: typeof colorAttributes | true,
...
};

const ReactNativeStyleAttributes: StyleAttributesType = {};
const ReactNativeStyleAttributes: {[string]: AnyAttributeType} = {};

for (const attributeName of Object.keys({
...DeprecatedViewStylePropTypes,
Expand Down
8 changes: 4 additions & 4 deletions Libraries/Renderer/shims/ReactNativeTypes.js
Expand Up @@ -6,7 +6,7 @@
*
* @format
* @flow strict
* @generated SignedSource<<51285a8509b134326b535fbea3608c87>>
* @generated SignedSource<<d970268c93059bcc9626426c0c280439>>
*/

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

type AttributeType<T, V> =
export type AttributeType<T, V> =
| true
| $ReadOnly<{|
diff?: (arg1: T, arg2: T) => boolean,
Expand All @@ -43,7 +43,7 @@ type AttributeType<T, V> =

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

export type AttributeConfiguration = $ReadOnly<{
[propName: string]: AnyAttributeType,
Expand All @@ -54,7 +54,7 @@ export type AttributeConfiguration = $ReadOnly<{
...
}>;

type PartialAttributeConfiguration = $ReadOnly<{
export type PartialAttributeConfiguration = $ReadOnly<{
[propName: string]: AnyAttributeType,
style?: $ReadOnly<{
[propName: string]: AnyAttributeType,
Expand Down
6 changes: 3 additions & 3 deletions Libraries/StyleSheet/StyleSheet.js
Expand Up @@ -338,9 +338,9 @@ module.exports = {
let value;

if (ReactNativeStyleAttributes[property] === true) {
value = {};
value = {process};
} else if (typeof ReactNativeStyleAttributes[property] === 'object') {
value = ReactNativeStyleAttributes[property];
value = {...ReactNativeStyleAttributes[property], process};
} else {
console.error(`${property} is not a valid style attribute`);
return;
Expand All @@ -350,7 +350,7 @@ module.exports = {
console.warn(`Overwriting ${property} style attribute preprocessor`);
}

ReactNativeStyleAttributes[property] = {...value, process};
ReactNativeStyleAttributes[property] = value;
},

/**
Expand Down

0 comments on commit 33b3858

Please sign in to comment.