From 33b385825c7220e89d02cc2de42e45563b9b5e30 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Fri, 11 Jun 2021 23:51:00 -0700 Subject: [PATCH] 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 --- .../View/ReactNativeStyleAttributes.js | 41 +------------------ Libraries/Renderer/shims/ReactNativeTypes.js | 8 ++-- Libraries/StyleSheet/StyleSheet.js | 6 +-- 3 files changed, 9 insertions(+), 46 deletions(-) diff --git a/Libraries/Components/View/ReactNativeStyleAttributes.js b/Libraries/Components/View/ReactNativeStyleAttributes.js index 7ddf41e8352fd8..11f22f43861cf0 100644 --- a/Libraries/Components/View/ReactNativeStyleAttributes.js +++ b/Libraries/Components/View/ReactNativeStyleAttributes.js @@ -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) => 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, diff --git a/Libraries/Renderer/shims/ReactNativeTypes.js b/Libraries/Renderer/shims/ReactNativeTypes.js index 3e5a2f6f1f79e2..dfb03d6818361a 100644 --- a/Libraries/Renderer/shims/ReactNativeTypes.js +++ b/Libraries/Renderer/shims/ReactNativeTypes.js @@ -6,7 +6,7 @@ * * @format * @flow strict - * @generated SignedSource<<51285a8509b134326b535fbea3608c87>> + * @generated SignedSource<> */ import type {ElementRef, ElementType, Element, AbstractComponent} from 'react'; @@ -34,7 +34,7 @@ export type MeasureLayoutOnSuccessCallback = ( height: number, ) => void; -type AttributeType = +export type AttributeType = | true | $ReadOnly<{| diff?: (arg1: T, arg2: T) => boolean, @@ -43,7 +43,7 @@ type AttributeType = // 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, @@ -54,7 +54,7 @@ export type AttributeConfiguration = $ReadOnly<{ ... }>; -type PartialAttributeConfiguration = $ReadOnly<{ +export type PartialAttributeConfiguration = $ReadOnly<{ [propName: string]: AnyAttributeType, style?: $ReadOnly<{ [propName: string]: AnyAttributeType, diff --git a/Libraries/StyleSheet/StyleSheet.js b/Libraries/StyleSheet/StyleSheet.js index d582efe9179a1f..785fbfe199e340 100644 --- a/Libraries/StyleSheet/StyleSheet.js +++ b/Libraries/StyleSheet/StyleSheet.js @@ -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; @@ -350,7 +350,7 @@ module.exports = { console.warn(`Overwriting ${property} style attribute preprocessor`); } - ReactNativeStyleAttributes[property] = {...value, process}; + ReactNativeStyleAttributes[property] = value; }, /**