Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 88 additions & 86 deletions Libraries/StyleSheet/StyleSheetTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @format
*/

import {Animated} from '../Animated/Animated';
import {ImageResizeMode} from '../Image/ImageResizeMode';
import {ColorValue} from './StyleSheet';

Expand All @@ -17,6 +18,14 @@ type FlexAlignType =
| 'stretch'
| 'baseline';

type DimensionValue =
| number
| 'auto'
| `${number}%`
| Animated.AnimatedNode
| null;
type AnimatableNumericValue = number | Animated.AnimatedNode;

/**
* Flex Prop Types
* @see https://reactnative.dev/docs/flexbox
Expand All @@ -35,17 +44,17 @@ export interface FlexStyle {
alignSelf?: 'auto' | FlexAlignType | undefined;
aspectRatio?: number | string | undefined;
borderBottomWidth?: number | undefined;
borderEndWidth?: number | string | undefined;
borderEndWidth?: number | undefined;
borderLeftWidth?: number | undefined;
borderRightWidth?: number | undefined;
borderStartWidth?: number | string | undefined;
borderStartWidth?: number | undefined;
borderTopWidth?: number | undefined;
borderWidth?: number | undefined;
bottom?: number | string | undefined;
bottom?: DimensionValue | undefined;
display?: 'none' | 'flex' | undefined;
end?: number | string | undefined;
end?: DimensionValue | undefined;
flex?: number | undefined;
flexBasis?: number | string | undefined;
flexBasis?: DimensionValue | undefined;
flexDirection?:
| 'row'
| 'column'
Expand All @@ -58,14 +67,14 @@ export interface FlexStyle {
flexGrow?: number | undefined;
flexShrink?: number | undefined;
flexWrap?: 'wrap' | 'nowrap' | 'wrap-reverse' | undefined;
height?: number | string | undefined;
inset?: number | string | undefined;
insetBlock?: number | string | undefined;
insetBlockEnd?: number | string | undefined;
insetBlockStart?: number | string | undefined;
insetInline?: number | string | undefined;
insetInlineEnd?: number | string | undefined;
insetInlineStart?: number | string | undefined;
height?: DimensionValue | undefined;
inset?: DimensionValue | undefined;
insetBlock?: DimensionValue | undefined;
insetBlockEnd?: DimensionValue | undefined;
insetBlockStart?: DimensionValue | undefined;
insetInline?: DimensionValue | undefined;
insetInlineEnd?: DimensionValue | undefined;
insetInlineStart?: DimensionValue | undefined;
justifyContent?:
| 'flex-start'
| 'flex-end'
Expand All @@ -74,47 +83,47 @@ export interface FlexStyle {
| 'space-around'
| 'space-evenly'
| undefined;
left?: number | string | undefined;
margin?: number | string | undefined;
marginBlock?: number | string | undefined;
marginBlockEnd?: number | string | undefined;
marginBlockStart?: number | string | undefined;
marginBottom?: number | string | undefined;
marginEnd?: number | string | undefined;
marginHorizontal?: number | string | undefined;
marginInline?: number | string | undefined;
marginInlineEnd?: number | string | undefined;
marginInlineStart?: number | string | undefined;
marginLeft?: number | string | undefined;
marginRight?: number | string | undefined;
marginStart?: number | string | undefined;
marginTop?: number | string | undefined;
marginVertical?: number | string | undefined;
maxHeight?: number | string | undefined;
maxWidth?: number | string | undefined;
minHeight?: number | string | undefined;
minWidth?: number | string | undefined;
left?: DimensionValue | undefined;
margin?: DimensionValue | undefined;
marginBlock?: DimensionValue | undefined;
marginBlockEnd?: DimensionValue | undefined;
marginBlockStart?: DimensionValue | undefined;
marginBottom?: DimensionValue | undefined;
marginEnd?: DimensionValue | undefined;
marginHorizontal?: DimensionValue | undefined;
marginInline?: DimensionValue | undefined;
marginInlineEnd?: DimensionValue | undefined;
marginInlineStart?: DimensionValue | undefined;
marginLeft?: DimensionValue | undefined;
marginRight?: DimensionValue | undefined;
marginStart?: DimensionValue | undefined;
marginTop?: DimensionValue | undefined;
marginVertical?: DimensionValue | undefined;
maxHeight?: DimensionValue | undefined;
maxWidth?: DimensionValue | undefined;
minHeight?: DimensionValue | undefined;
minWidth?: DimensionValue | undefined;
overflow?: 'visible' | 'hidden' | 'scroll' | undefined;
padding?: number | string | undefined;
paddingBottom?: number | string | undefined;
paddingBlock?: number | string | undefined;
paddingBlockEnd?: number | string | undefined;
paddingBlockStart?: number | string | undefined;
paddingEnd?: number | string | undefined;
paddingHorizontal?: number | string | undefined;
paddingInline?: number | string | undefined;
paddingInlineEnd?: number | string | undefined;
paddingInlineStart?: number | string | undefined;
paddingLeft?: number | string | undefined;
paddingRight?: number | string | undefined;
paddingStart?: number | string | undefined;
paddingTop?: number | string | undefined;
paddingVertical?: number | string | undefined;
padding?: DimensionValue | undefined;
paddingBottom?: DimensionValue | undefined;
paddingBlock?: DimensionValue | undefined;
paddingBlockEnd?: DimensionValue | undefined;
paddingBlockStart?: DimensionValue | undefined;
paddingEnd?: DimensionValue | undefined;
paddingHorizontal?: DimensionValue | undefined;
paddingInline?: DimensionValue | undefined;
paddingInlineEnd?: DimensionValue | undefined;
paddingInlineStart?: DimensionValue | undefined;
paddingLeft?: DimensionValue | undefined;
paddingRight?: DimensionValue | undefined;
paddingStart?: DimensionValue | undefined;
paddingTop?: DimensionValue | undefined;
paddingVertical?: DimensionValue | undefined;
position?: 'absolute' | 'relative' | undefined;
right?: number | string | undefined;
start?: number | string | undefined;
top?: number | string | undefined;
width?: number | string | undefined;
right?: DimensionValue | undefined;
start?: DimensionValue | undefined;
top?: DimensionValue | undefined;
width?: DimensionValue | undefined;
zIndex?: number | undefined;

/**
Expand All @@ -125,8 +134,8 @@ export interface FlexStyle {

export interface ShadowStyleIOS {
shadowColor?: ColorValue | undefined;
shadowOffset?: {width: number; height: number} | undefined;
shadowOpacity?: number | undefined;
shadowOffset?: Readonly<{width: number; height: number}> | undefined;
shadowOpacity?: AnimatableNumericValue | undefined;
shadowRadius?: number | undefined;
}

Expand Down Expand Up @@ -207,23 +216,23 @@ export interface TransformsStyle {
/**
* @deprecated Use rotate in transform prop instead.
*/
rotation?: number | undefined;
rotation?: AnimatableNumericValue | undefined;
/**
* @deprecated Use scaleX in transform prop instead.
*/
scaleX?: number | undefined;
scaleX?: AnimatableNumericValue | undefined;
/**
* @deprecated Use scaleY in transform prop instead.
*/
scaleY?: number | undefined;
scaleY?: AnimatableNumericValue | undefined;
/**
* @deprecated Use translateX in transform prop instead.
*/
translateX?: number | undefined;
translateX?: AnimatableNumericValue | undefined;
/**
* @deprecated Use translateY in transform prop instead.
*/
translateY?: number | undefined;
translateY?: AnimatableNumericValue | undefined;
}

/**
Expand All @@ -236,37 +245,32 @@ export interface ViewStyle extends FlexStyle, ShadowStyleIOS, TransformsStyle {
borderBlockEndColor?: ColorValue | undefined;
borderBlockStartColor?: ColorValue | undefined;
borderBottomColor?: ColorValue | undefined;
borderBottomEndRadius?: number | undefined;
borderBottomLeftRadius?: number | undefined;
borderBottomRightRadius?: number | undefined;
borderBottomStartRadius?: number | undefined;
borderBottomWidth?: number | undefined;
borderBottomEndRadius?: AnimatableNumericValue | undefined;
borderBottomLeftRadius?: AnimatableNumericValue | undefined;
borderBottomRightRadius?: AnimatableNumericValue | undefined;
borderBottomStartRadius?: AnimatableNumericValue | undefined;
borderColor?: ColorValue | undefined;
/**
* On iOS 13+, it is possible to change the corner curve of borders.
* @platform ios
*/
borderCurve?: 'circular' | 'continuous' | undefined;
borderEndColor?: ColorValue | undefined;
borderEndEndRadius?: number | undefined;
borderEndStartRadius?: number | undefined;
borderEndEndRadius?: AnimatableNumericValue | undefined;
borderEndStartRadius?: AnimatableNumericValue | undefined;
borderLeftColor?: ColorValue | undefined;
borderLeftWidth?: number | undefined;
borderRadius?: number | undefined;
borderRadius?: AnimatableNumericValue | undefined;
borderRightColor?: ColorValue | undefined;
borderRightWidth?: number | undefined;
borderStartColor?: ColorValue | undefined;
borderStartEndRadius?: number | undefined;
borderStartStartRadius?: number | undefined;
borderStartEndRadius?: AnimatableNumericValue | undefined;
borderStartStartRadius?: AnimatableNumericValue | undefined;
borderStyle?: 'solid' | 'dotted' | 'dashed' | undefined;
borderTopColor?: ColorValue | undefined;
borderTopEndRadius?: number | undefined;
borderTopLeftRadius?: number | undefined;
borderTopRightRadius?: number | undefined;
borderTopStartRadius?: number | undefined;
borderTopWidth?: number | undefined;
borderWidth?: number | undefined;
opacity?: number | undefined;
borderTopEndRadius?: AnimatableNumericValue | undefined;
borderTopLeftRadius?: AnimatableNumericValue | undefined;
borderTopRightRadius?: AnimatableNumericValue | undefined;
borderTopStartRadius?: AnimatableNumericValue | undefined;
opacity?: AnimatableNumericValue | undefined;
/**
* Sets the elevation of a view, using Android's underlying
* [elevation API](https://developer.android.com/training/material/shadows-clipping.html#Elevation).
Expand All @@ -290,7 +294,6 @@ export type FontVariant =
| 'proportional-nums';
export interface TextStyleIOS extends ViewStyle {
fontVariant?: FontVariant[] | undefined;
letterSpacing?: number | undefined;
textDecorationColor?: ColorValue | undefined;
textDecorationStyle?: 'solid' | 'double' | 'dotted' | 'dashed' | undefined;
writingDirection?: 'auto' | 'ltr' | 'rtl' | undefined;
Expand Down Expand Up @@ -351,17 +354,16 @@ export interface TextStyle extends TextStyleIOS, TextStyleAndroid, ViewStyle {
export interface ImageStyle extends FlexStyle, ShadowStyleIOS, TransformsStyle {
resizeMode?: ImageResizeMode | undefined;
backfaceVisibility?: 'visible' | 'hidden' | undefined;
borderBottomLeftRadius?: number | undefined;
borderBottomRightRadius?: number | undefined;
borderBottomLeftRadius?: AnimatableNumericValue | undefined;
borderBottomRightRadius?: AnimatableNumericValue | undefined;
backgroundColor?: ColorValue | undefined;
borderColor?: ColorValue | undefined;
borderWidth?: number | undefined;
borderRadius?: number | undefined;
borderTopLeftRadius?: number | undefined;
borderTopRightRadius?: number | undefined;
borderRadius?: AnimatableNumericValue | undefined;
borderTopLeftRadius?: AnimatableNumericValue | undefined;
borderTopRightRadius?: AnimatableNumericValue | undefined;
overflow?: 'visible' | 'hidden' | undefined;
overlayColor?: ColorValue | undefined;
tintColor?: ColorValue | undefined;
opacity?: number | undefined;
opacity?: AnimatableNumericValue | undefined;
objectFit?: 'cover' | 'contain' | 'fill' | 'scale-down' | undefined;
}
48 changes: 25 additions & 23 deletions Libraries/StyleSheet/StyleSheetTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export type EdgeInsetsValue = {
right: number,
bottom: number,
};
export type DimensionValue = null | number | string | AnimatedNode;

export type DimensionValue = number | string | 'auto' | AnimatedNode | null;
export type AnimatableNumericValue = number | AnimatedNode;

/**
* React Native's layout system is based on Flexbox and is powered both
Expand Down Expand Up @@ -671,7 +673,7 @@ export type ____ShadowStyle_InternalCore = $ReadOnly<{
* Sets the drop shadow opacity (multiplied by the color's alpha component)
* @platform ios
*/
shadowOpacity?: number | AnimatedNode,
shadowOpacity?: AnimatableNumericValue,
/**
* Sets the drop shadow blur radius
* @platform ios
Expand Down Expand Up @@ -701,28 +703,28 @@ export type ____ViewStyle_InternalCore = $ReadOnly<{
borderBlockColor?: ____ColorValue_Internal,
borderBlockEndColor?: ____ColorValue_Internal,
borderBlockStartColor?: ____ColorValue_Internal,
borderRadius?: number | AnimatedNode,
borderBottomEndRadius?: number | AnimatedNode,
borderBottomLeftRadius?: number | AnimatedNode,
borderBottomRightRadius?: number | AnimatedNode,
borderBottomStartRadius?: number | AnimatedNode,
borderEndEndRadius?: number | AnimatedNode,
borderEndStartRadius?: number | AnimatedNode,
borderStartEndRadius?: number | AnimatedNode,
borderStartStartRadius?: number | AnimatedNode,
borderTopEndRadius?: number | AnimatedNode,
borderTopLeftRadius?: number | AnimatedNode,
borderTopRightRadius?: number | AnimatedNode,
borderTopStartRadius?: number | AnimatedNode,
borderRadius?: AnimatableNumericValue,
borderBottomEndRadius?: AnimatableNumericValue,
borderBottomLeftRadius?: AnimatableNumericValue,
borderBottomRightRadius?: AnimatableNumericValue,
borderBottomStartRadius?: AnimatableNumericValue,
borderEndEndRadius?: AnimatableNumericValue,
borderEndStartRadius?: AnimatableNumericValue,
borderStartEndRadius?: AnimatableNumericValue,
borderStartStartRadius?: AnimatableNumericValue,
borderTopEndRadius?: AnimatableNumericValue,
borderTopLeftRadius?: AnimatableNumericValue,
borderTopRightRadius?: AnimatableNumericValue,
borderTopStartRadius?: AnimatableNumericValue,
borderStyle?: 'solid' | 'dotted' | 'dashed',
borderWidth?: number | AnimatedNode,
borderBottomWidth?: number | AnimatedNode,
borderEndWidth?: number | AnimatedNode,
borderLeftWidth?: number | AnimatedNode,
borderRightWidth?: number | AnimatedNode,
borderStartWidth?: number | AnimatedNode,
borderTopWidth?: number | AnimatedNode,
opacity?: number | AnimatedNode,
borderWidth?: AnimatableNumericValue,
borderBottomWidth?: AnimatableNumericValue,
borderEndWidth?: AnimatableNumericValue,
borderLeftWidth?: AnimatableNumericValue,
borderRightWidth?: AnimatableNumericValue,
borderStartWidth?: AnimatableNumericValue,
borderTopWidth?: AnimatableNumericValue,
opacity?: AnimatableNumericValue,
elevation?: number,
pointerEvents?: 'auto' | 'none' | 'box-none' | 'box-only',
}>;
Expand Down
11 changes: 7 additions & 4 deletions React/Base/RCTConvert.m
Original file line number Diff line number Diff line change
Expand Up @@ -992,12 +992,15 @@ + (YGValue)YGValue:(id)json
if ([s isEqualToString:@"auto"]) {
return (YGValue){YGUndefined, YGUnitAuto};
} else if ([s hasSuffix:@"%"]) {
return (YGValue){[[s substringToIndex:s.length] floatValue], YGUnitPercent};
float floatValue;
if ([[NSScanner scannerWithString:s] scanFloat:&floatValue]) {
return (YGValue){floatValue, YGUnitPercent};
}
} else {
RCTLogConvertError(json, @"a YGValue. Did you forget the % or pt suffix?");
RCTLogAdvice(
@"\"%@\" is not a valid dimension. Dimensions must be a number, \"auto\", or a string suffixed with \"%%\".",
s);
}
} else {
RCTLogConvertError(json, @"a YGValue.");
}
return YGValueUndefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ void setFromDynamic(Dynamic dynamic) {
value = Float.parseFloat(s.substring(0, s.length() - 1));
} else {
FLog.w(ReactConstants.TAG, "Unknown value: " + s);
unit = YogaUnit.UNDEFINED;
value = YogaConstants.UNDEFINED;
}
} else if (dynamic.getType() == ReadableType.Number) {
unit = YogaUnit.POINT;
Expand Down
10 changes: 6 additions & 4 deletions ReactCommon/react/renderer/components/view/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,12 @@ inline void fromRawValue(
return;
} else {
if (stringValue.back() == '%') {
result = YGValue{
folly::to<float>(stringValue.substr(0, stringValue.length() - 1)),
YGUnitPercent};
return;
auto tryValue = folly::tryTo<float>(
std::string_view(stringValue).substr(0, stringValue.length() - 1));
if (tryValue.hasValue()) {
result = YGValue{tryValue.value(), YGUnitPercent};
return;
}
} else {
auto tryValue = folly::tryTo<float>(stringValue);
if (tryValue.hasValue()) {
Expand Down
Loading