mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
2e8c0bd7ea
commit
33b385825c
@@ -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,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* @format
|
||||
* @flow strict
|
||||
* @generated SignedSource<<51285a8509b134326b535fbea3608c87>>
|
||||
* @generated SignedSource<<d970268c93059bcc9626426c0c280439>>
|
||||
*/
|
||||
|
||||
import type {ElementRef, ElementType, Element, AbstractComponent} from 'react';
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
@@ -54,7 +54,7 @@ export type AttributeConfiguration = $ReadOnly<{
|
||||
...
|
||||
}>;
|
||||
|
||||
type PartialAttributeConfiguration = $ReadOnly<{
|
||||
export type PartialAttributeConfiguration = $ReadOnly<{
|
||||
[propName: string]: AnyAttributeType,
|
||||
style?: $ReadOnly<{
|
||||
[propName: string]: AnyAttributeType,
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user